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);
}
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);
}
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();
});
}
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);
});
}
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();
}
Aggregations