Search in sources :

Example 6 with PurchaseStrategy

use of com.github.robozonky.api.strategies.PurchaseStrategy in project robozonky by RoboZonky.

the class NaturalLanguagePurchaseStrategyTest method nothingRecommendedDueToRatingOverinvested.

@Test
void nothingRecommendedDueToRatingOverinvested() {
    final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.EMPTY);
    final PurchaseStrategy s = new NaturalLanguagePurchaseStrategy(p);
    final PortfolioOverview portfolio = mock(PortfolioOverview.class);
    when(portfolio.getCzkAvailable()).thenReturn(p.getMinimumBalance());
    when(portfolio.getCzkInvested()).thenReturn(p.getMaximumInvestmentSizeInCzk() - 1);
    when(portfolio.getShareOnInvestment(any())).thenReturn(BigDecimal.ZERO);
    final Participation l = mockParticipation();
    doReturn(Rating.A).when(l).getRating();
    final Stream<RecommendedParticipation> result = s.recommend(Collections.singletonList(mockDescriptor(l)), portfolio, new Restrictions());
    assertThat(result).isEmpty();
}
Also used : RecommendedParticipation(com.github.robozonky.api.strategies.RecommendedParticipation) Participation(com.github.robozonky.api.remote.entities.Participation) PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) RecommendedParticipation(com.github.robozonky.api.strategies.RecommendedParticipation) Test(org.junit.jupiter.api.Test)

Example 7 with PurchaseStrategy

use of com.github.robozonky.api.strategies.PurchaseStrategy in project robozonky by RoboZonky.

the class NaturalLanguagePurchaseStrategyTest method unacceptablePortfolioDueToLowBalance.

@Test
void unacceptablePortfolioDueToLowBalance() {
    final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.EMPTY);
    final PurchaseStrategy s = new NaturalLanguagePurchaseStrategy(p);
    final PortfolioOverview portfolio = mock(PortfolioOverview.class);
    when(portfolio.getCzkAvailable()).thenReturn(p.getMinimumBalance() - 1);
    final Stream<RecommendedParticipation> result = s.recommend(Collections.singletonList(mockDescriptor()), portfolio, new Restrictions());
    assertThat(result).isEmpty();
}
Also used : PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) RecommendedParticipation(com.github.robozonky.api.strategies.RecommendedParticipation) Test(org.junit.jupiter.api.Test)

Example 8 with PurchaseStrategy

use of com.github.robozonky.api.strategies.PurchaseStrategy in project robozonky by RoboZonky.

the class NaturalLanguagePurchaseStrategyTest method recommendationIsMade.

@Test
void recommendationIsMade() {
    final DefaultValues v = new DefaultValues(DefaultPortfolio.PROGRESSIVE);
    final ParsedStrategy ps = new ParsedStrategy(v, Collections.emptyList(), Collections.emptyMap(), new FilterSupplier(v, null, Collections.emptySet()));
    final PurchaseStrategy s = new NaturalLanguagePurchaseStrategy(ps);
    final PortfolioOverview portfolio = mock(PortfolioOverview.class);
    when(portfolio.getCzkAvailable()).thenReturn(ps.getMinimumBalance());
    when(portfolio.getCzkInvested()).thenReturn(ps.getMaximumInvestmentSizeInCzk() - 1);
    when(portfolio.getShareOnInvestment(any())).thenReturn(BigDecimal.ZERO);
    final Participation p = spy(mockParticipation());
    // not recommended due to balance
    doReturn(BigDecimal.valueOf(100000)).when(p).getRemainingPrincipal();
    doReturn(Rating.A).when(p).getRating();
    final Participation p2 = spy(mockParticipation());
    // check amounts under Zonky investment minimum
    final int amount = Defaults.MINIMUM_INVESTMENT_IN_CZK - 1;
    doReturn(BigDecimal.valueOf(amount)).when(p2).getRemainingPrincipal();
    doReturn(Rating.A).when(p2).getRating();
    final ParticipationDescriptor pd = mockDescriptor(p2);
    final List<RecommendedParticipation> result = s.recommend(Arrays.asList(mockDescriptor(p), pd), portfolio, new Restrictions()).collect(Collectors.toList());
    assertThat(result).hasSize(1);
    final RecommendedParticipation r = result.get(0);
    assertSoftly(softly -> {
        softly.assertThat(r.descriptor()).isEqualTo(pd);
        softly.assertThat(r.amount()).isEqualTo(pd.item().getRemainingPrincipal());
    });
}
Also used : RecommendedParticipation(com.github.robozonky.api.strategies.RecommendedParticipation) Participation(com.github.robozonky.api.remote.entities.Participation) PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) ParticipationDescriptor(com.github.robozonky.api.strategies.ParticipationDescriptor) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) RecommendedParticipation(com.github.robozonky.api.strategies.RecommendedParticipation) Test(org.junit.jupiter.api.Test)

Example 9 with PurchaseStrategy

use of com.github.robozonky.api.strategies.PurchaseStrategy in project robozonky by RoboZonky.

the class NaturalLanguagePurchaseStrategyTest method unacceptablePortfolioDueToOverInvestment.

@Test
void unacceptablePortfolioDueToOverInvestment() {
    final DefaultValues v = new DefaultValues(DefaultPortfolio.EMPTY);
    v.setTargetPortfolioSize(1000);
    final ParsedStrategy p = new ParsedStrategy(v);
    final PurchaseStrategy s = new NaturalLanguagePurchaseStrategy(p);
    final PortfolioOverview portfolio = mock(PortfolioOverview.class);
    when(portfolio.getCzkAvailable()).thenReturn(p.getMinimumBalance());
    when(portfolio.getCzkInvested()).thenReturn(p.getMaximumInvestmentSizeInCzk());
    final Stream<RecommendedParticipation> result = s.recommend(Collections.singletonList(mockDescriptor()), portfolio, new Restrictions());
    assertThat(result).isEmpty();
}
Also used : PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) RecommendedParticipation(com.github.robozonky.api.strategies.RecommendedParticipation) Test(org.junit.jupiter.api.Test)

Example 10 with PurchaseStrategy

use of com.github.robozonky.api.strategies.PurchaseStrategy in project robozonky by RoboZonky.

the class StrategyLoaderTest method loading.

@Test
void loading() {
    final InvestmentStrategy is = (availableLoans, portfolio, restrictions) -> Stream.empty();
    final StrategyService iss = new StrategyService() {

        @Override
        public Optional<InvestmentStrategy> toInvest(final String strategy) {
            return Optional.of(is);
        }

        @Override
        public Optional<SellStrategy> toSell(final String strategy) {
            return Optional.empty();
        }

        @Override
        public Optional<PurchaseStrategy> toPurchase(final String strategy) {
            return Optional.empty();
        }
    };
    assertThat(StrategyLoader.load("", Collections.singleton(iss), StrategyService::toInvest)).contains(is);
}
Also used : Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) StrategyService(com.github.robozonky.api.strategies.StrategyService) Stream(java.util.stream.Stream) SoftAssertions(org.assertj.core.api.SoftAssertions) Optional(java.util.Optional) Assertions(org.assertj.core.api.Assertions) UUID(java.util.UUID) PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) Collections(java.util.Collections) SellStrategy(com.github.robozonky.api.strategies.SellStrategy) SellStrategy(com.github.robozonky.api.strategies.SellStrategy) PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) StrategyService(com.github.robozonky.api.strategies.StrategyService) Test(org.junit.jupiter.api.Test)

Aggregations

PurchaseStrategy (com.github.robozonky.api.strategies.PurchaseStrategy)10 Test (org.junit.jupiter.api.Test)9 Restrictions (com.github.robozonky.api.remote.entities.Restrictions)8 Participation (com.github.robozonky.api.remote.entities.Participation)6 ParticipationDescriptor (com.github.robozonky.api.strategies.ParticipationDescriptor)5 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)5 RecommendedParticipation (com.github.robozonky.api.strategies.RecommendedParticipation)5 Stream (java.util.stream.Stream)5 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)4 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)4 Authenticated (com.github.robozonky.app.authentication.Authenticated)4 Portfolio (com.github.robozonky.app.portfolio.Portfolio)4 Collection (java.util.Collection)4 Assertions (org.assertj.core.api.Assertions)4 SoftAssertions (org.assertj.core.api.SoftAssertions)4 Mockito (org.mockito.Mockito)4 Event (com.github.robozonky.api.notifications.Event)3 PurchaseRequestedEvent (com.github.robozonky.api.notifications.PurchaseRequestedEvent)3 Wallet (com.github.robozonky.api.remote.entities.Wallet)3 Rating (com.github.robozonky.api.remote.enums.Rating)3