Search in sources :

Example 16 with LoanDescriptor

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

the class NaturalLanguageInvestmentStrategyTest method noLoansApplicable.

@Test
void noLoansApplicable() {
    final MarketplaceFilter filter = MarketplaceFilter.of(MarketplaceFilterCondition.alwaysAccepting());
    final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.PROGRESSIVE, Collections.singleton(filter));
    final InvestmentStrategy s = new NaturalLanguageInvestmentStrategy(p);
    final PortfolioOverview portfolio = mock(PortfolioOverview.class);
    when(portfolio.getCzkAvailable()).thenReturn(p.getMinimumBalance());
    when(portfolio.getCzkInvested()).thenReturn(p.getMaximumInvestmentSizeInCzk() - 1);
    final Stream<RecommendedLoan> result = s.recommend(Collections.singletonList(new LoanDescriptor(mockLoan(2))), portfolio, new Restrictions());
    assertThat(result).isEmpty();
}
Also used : RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) MarketplaceFilter(com.github.robozonky.strategy.natural.conditions.MarketplaceFilter) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Test(org.junit.jupiter.api.Test)

Example 17 with LoanDescriptor

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

the class NaturalLanguageInvestmentStrategyTest method nothingRecommendedDueToRatingOverinvested.

@Test
void nothingRecommendedDueToRatingOverinvested() {
    final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.EMPTY, Collections.emptySet());
    final InvestmentStrategy s = new NaturalLanguageInvestmentStrategy(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 Loan l = mockLoan(1000);
    final Stream<RecommendedLoan> result = s.recommend(Collections.singletonList(new LoanDescriptor(l)), portfolio, new Restrictions());
    assertThat(result).isEmpty();
}
Also used : RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Test(org.junit.jupiter.api.Test)

Example 18 with LoanDescriptor

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

the class NaturalLanguageInvestmentStrategyTest method unacceptablePortfolioDueToLowBalance.

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

Example 19 with LoanDescriptor

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

the class ParsedStrategyTest method exitButNoSelloff.

@Test
void exitButNoSelloff() {
    final DefaultPortfolio portfolio = DefaultPortfolio.EMPTY;
    final DefaultValues values = new DefaultValues(portfolio);
    // exit active, no sell-off yet
    values.setExitProperties(new ExitProperties(LocalDate.now().plusMonths(6)));
    final ParsedStrategy strategy = new ParsedStrategy(values, Collections.emptyList(), Collections.emptyMap(), new FilterSupplier(values, Collections.emptySet(), Collections.emptySet(), Collections.emptySet()));
    // no loan or participation should be bought; every investment should be sold
    final Loan loanUnder = mockLoan(1000);
    final Loan loanOver = Loan.custom().setId(2).setAmount(2000).setTermInMonths(84).build();
    final LoanDescriptor ldOver = new LoanDescriptor(loanOver);
    final LoanDescriptor ldUnder = new LoanDescriptor(loanUnder);
    final ParticipationDescriptor pdOver = mockParticipationDescriptor(loanOver);
    final ParticipationDescriptor pdUnder = mockParticipationDescriptor(loanUnder);
    final Investment iUnder = Investment.fresh((MarketplaceLoan) loanUnder, 200);
    final InvestmentDescriptor idUnder = new InvestmentDescriptor(iUnder, loanUnder);
    final Investment iOver = Investment.fresh((MarketplaceLoan) loanOver, 200);
    final InvestmentDescriptor idOver = new InvestmentDescriptor(iOver, loanOver);
    assertSoftly(softly -> {
        softly.assertThat(strategy.getApplicableLoans(Arrays.asList(ldOver, ldUnder))).containsOnly(ldUnder);
        softly.assertThat(strategy.getApplicableParticipations(Arrays.asList(pdOver, pdUnder))).containsOnly(pdUnder);
        softly.assertThat(strategy.getApplicableInvestments(Arrays.asList(idOver, idUnder))).isEmpty();
    });
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) ParticipationDescriptor(com.github.robozonky.api.strategies.ParticipationDescriptor) InvestmentDescriptor(com.github.robozonky.api.strategies.InvestmentDescriptor) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test)

Example 20 with LoanDescriptor

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

the class ParsedStrategyTest method construct.

@Test
void construct() {
    final DefaultPortfolio portfolio = DefaultPortfolio.PROGRESSIVE;
    // test for default values
    final ParsedStrategy strategy = new ParsedStrategy(portfolio);
    assertSoftly(softly -> {
        softly.assertThat(strategy.getMinimumBalance()).isEqualTo(Defaults.MINIMUM_INVESTMENT_IN_CZK);
        softly.assertThat(strategy.getMaximumInvestmentSizeInCzk()).isEqualTo(Integer.MAX_VALUE);
        softly.assertThat(strategy.getMinimumShare(Rating.A)).isEqualTo(portfolio.getDefaultShare(Rating.A));
        softly.assertThat(strategy.getMaximumShare(Rating.B)).isEqualTo(portfolio.getDefaultShare(Rating.B));
        softly.assertThat(strategy.getMinimumInvestmentSizeInCzk(Rating.C)).isEqualTo(0);
        softly.assertThat(strategy.getMaximumInvestmentSizeInCzk(Rating.D)).isEqualTo(Defaults.MAXIMUM_INVESTMENT_IN_CZK);
        softly.assertThat(strategy.needsConfirmation(new LoanDescriptor(mockLoan(2)))).isFalse();
    });
}
Also used : LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)34 Test (org.junit.jupiter.api.Test)29 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)17 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)15 Portfolio (com.github.robozonky.app.portfolio.Portfolio)15 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)13 Zonky (com.github.robozonky.common.remote.Zonky)12 InvestmentStrategy (com.github.robozonky.api.strategies.InvestmentStrategy)11 Authenticated (com.github.robozonky.app.authentication.Authenticated)11 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)10 Event (com.github.robozonky.api.notifications.Event)8 InvestmentDelegatedEvent (com.github.robozonky.api.notifications.InvestmentDelegatedEvent)8 InvestmentMadeEvent (com.github.robozonky.api.notifications.InvestmentMadeEvent)8 InvestmentRejectedEvent (com.github.robozonky.api.notifications.InvestmentRejectedEvent)8 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)8 ExecutionCompletedEvent (com.github.robozonky.api.notifications.ExecutionCompletedEvent)7 MarketplaceLoan (com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan)7 ExecutionStartedEvent (com.github.robozonky.api.notifications.ExecutionStartedEvent)6 InvestmentSkippedEvent (com.github.robozonky.api.notifications.InvestmentSkippedEvent)6 Restrictions (com.github.robozonky.api.remote.entities.Restrictions)6