use of com.github.robozonky.api.strategies.RecommendedParticipation in project robozonky by RoboZonky.
the class Session method purchase.
public boolean purchase(final RecommendedParticipation recommendation) {
Events.fire(new PurchaseRequestedEvent(recommendation));
final Participation participation = recommendation.descriptor().item();
final Loan loan = recommendation.descriptor().related();
final boolean purchased = isDryRun || actualPurchase(participation);
if (purchased) {
final Investment i = Investment.fresh(participation, loan, recommendation.amount());
markSuccessfulPurchase(i);
Events.fire(new InvestmentPurchasedEvent(i, loan, portfolioOverview));
}
return purchased;
}
use of com.github.robozonky.api.strategies.RecommendedParticipation in project robozonky by RoboZonky.
the class NaturalLanguagePurchaseStrategyTest method noLoansApplicable.
@Test
void noLoansApplicable() {
final MarketplaceFilter filter = MarketplaceFilter.of(MarketplaceFilterCondition.alwaysAccepting());
final DefaultValues v = new DefaultValues(DefaultPortfolio.PROGRESSIVE);
final FilterSupplier w = new FilterSupplier(v, Collections.emptySet(), Collections.singleton(filter));
final ParsedStrategy p = new ParsedStrategy(v, Collections.emptySet(), Collections.emptyMap(), w);
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);
final Stream<RecommendedParticipation> result = s.recommend(Collections.singletonList(mockDescriptor()), portfolio, new Restrictions());
assertThat(result).isEmpty();
}
use of com.github.robozonky.api.strategies.RecommendedParticipation 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();
}
use of com.github.robozonky.api.strategies.RecommendedParticipation 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();
}
use of com.github.robozonky.api.strategies.RecommendedParticipation 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());
});
}
Aggregations