Search in sources :

Example 46 with Loan

use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.

the class InvestmentSizeRecommenderTest method withSpecificRating.

@Test
void withSpecificRating() {
    final ParsedStrategy s = getStrategy();
    final InvestmentSizeRecommender r = new InvestmentSizeRecommender(s, Defaults.MAXIMUM_INVESTMENT_IN_CZK);
    // with unlimited balance, make maximum possible recommendation
    final Loan loan = mockLoan(50_000);
    final int actualInvestment = r.apply(loan, Integer.MAX_VALUE);
    // at most 1 percent of 50000, rounded down to nearest increment of 200
    assertThat(actualInvestment).isEqualTo(400);
    // with balance less that the recommendation, recommend less than 400 but more than 0; 200 only possible
    final int investmentOnLowBalance = r.apply(loan, actualInvestment - 1);
    assertThat(investmentOnLowBalance).isEqualTo(actualInvestment - Defaults.MINIMUM_INVESTMENT_INCREMENT_IN_CZK);
    // with no balance, don't make a recommendation
    final int investmentOnNoBalance = r.apply(loan, investmentOnLowBalance - 1);
    assertThat(investmentOnNoBalance).isEqualTo(0);
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Test(org.junit.jupiter.api.Test)

Example 47 with Loan

use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.

the class InvestmentSizeRecommenderTest method recommendationRoundedUnderMinimum.

@Test
void recommendationRoundedUnderMinimum() {
    final int minimumInvestment = 1000;
    final Loan l = mockLoan(minimumInvestment - 1);
    final ParsedStrategy s = mock(ParsedStrategy.class);
    // next line will cause the recommendation to be rounded to 800, which will be below the minimum investment
    when(s.getMinimumInvestmentSizeInCzk(eq(l.getRating()))).thenReturn(minimumInvestment - 1);
    when(s.getMaximumInvestmentSizeInCzk(eq(l.getRating()))).thenReturn(minimumInvestment);
    when(s.getMaximumInvestmentShareInPercent()).thenReturn(100);
    final BiFunction<Loan, Integer, Integer> r = new InvestmentSizeRecommender(s, minimumInvestment * 10);
    assertThat(r.apply(l, minimumInvestment * 2)).isEqualTo(0);
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Test(org.junit.jupiter.api.Test)

Example 48 with Loan

use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.

the class NaturalLanguageInvestmentStrategyTest method recommendationIsMade.

@Test
void recommendationIsMade() {
    final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.PROGRESSIVE, 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(100_000);
    final Loan l2 = mockLoan(100);
    final LoanDescriptor ld = new LoanDescriptor(l);
    final List<RecommendedLoan> result = s.recommend(Arrays.asList(new LoanDescriptor(l2), ld), portfolio, new Restrictions()).collect(Collectors.toList());
    assertThat(result).hasSize(1);
    final RecommendedLoan r = result.get(0);
    assertSoftly(softly -> {
        softly.assertThat(r.descriptor()).isEqualTo(ld);
        softly.assertThat(r.amount()).isEqualTo(BigDecimal.valueOf(Defaults.MINIMUM_INVESTMENT_IN_CZK));
        softly.assertThat(r.isConfirmationRequired()).isFalse();
    });
}
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 49 with Loan

use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.

the class ParsedStrategyTest method sellOffStarted.

@Test
void sellOffStarted() {
    final DefaultPortfolio portfolio = DefaultPortfolio.EMPTY;
    final DefaultValues values = new DefaultValues(portfolio);
    // activate default sell-off 3 months before the given date, which is already in the past
    values.setExitProperties(new ExitProperties(LocalDate.now().plusMonths(2)));
    final ParsedStrategy strategy = new ParsedStrategy(values, Collections.emptyList());
    // no loan or participation should be bought; every investment should be sold
    final Loan l = mockLoan(1000);
    final LoanDescriptor ld = new LoanDescriptor(l);
    final ParticipationDescriptor pd = mockParticipationDescriptor(l);
    final Investment i = Investment.fresh((MarketplaceLoan) l, 200);
    final InvestmentDescriptor id = new InvestmentDescriptor(i, l);
    assertSoftly(softly -> {
        softly.assertThat(strategy.getApplicableLoans(Collections.singleton(ld))).isEmpty();
        softly.assertThat(strategy.getApplicableParticipations(Collections.singleton(pd))).isEmpty();
        softly.assertThat(strategy.getApplicableInvestments(Collections.singleton(id))).containsOnly(id);
    });
}
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 50 with Loan

use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.

the class ParsedStrategyTest method matchesAlsoSellFilter.

@Test
void matchesAlsoSellFilter() {
    final MarketplaceFilter accepting = MarketplaceFilter.of(MarketplaceFilterCondition.alwaysAccepting());
    final Collection<MarketplaceFilter> filters = Collections.singleton(accepting);
    final DefaultValues v = new DefaultValues(DefaultPortfolio.PROGRESSIVE);
    final FilterSupplier s = new FilterSupplier(v, Collections.emptySet(), Collections.emptySet(), filters);
    final ParsedStrategy ps = new ParsedStrategy(v, Collections.emptyList(), Collections.emptyMap(), s);
    final Loan l = mockLoan(200_000);
    final LoanDescriptor ld = new LoanDescriptor(l);
    assertThat(ps.getApplicableLoans(Collections.singleton(ld))).isEmpty();
    final Participation p = mock(Participation.class);
    final ParticipationDescriptor pd = new ParticipationDescriptor(p, l);
    assertThat(ps.getApplicableParticipations(Collections.singleton(pd))).isEmpty();
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) MarketplaceFilter(com.github.robozonky.strategy.natural.conditions.MarketplaceFilter) ParticipationDescriptor(com.github.robozonky.api.strategies.ParticipationDescriptor) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)53 Test (org.junit.jupiter.api.Test)46 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)25 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)20 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)19 MarketplaceLoan (com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan)14 Zonky (com.github.robozonky.common.remote.Zonky)14 SoftAssertions (org.assertj.core.api.SoftAssertions)14 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)13 Assertions (org.assertj.core.api.Assertions)13 Mockito (org.mockito.Mockito)13 Event (com.github.robozonky.api.notifications.Event)12 Portfolio (com.github.robozonky.app.portfolio.Portfolio)12 Authenticated (com.github.robozonky.app.authentication.Authenticated)11 Collection (java.util.Collection)11 Collections (java.util.Collections)11 Stream (java.util.stream.Stream)10 Optional (java.util.Optional)9 InvestmentPurchasedEvent (com.github.robozonky.api.notifications.InvestmentPurchasedEvent)8 Participation (com.github.robozonky.api.remote.entities.Participation)8