use of com.github.robozonky.api.strategies.InvestmentDescriptor 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();
});
}
use of com.github.robozonky.api.strategies.InvestmentDescriptor in project robozonky by RoboZonky.
the class Selling method sell.
private void sell(final Portfolio portfolio, final SellStrategy strategy, final Authenticated auth) {
final PortfolioOverview overview = portfolio.calculateOverview();
final Set<InvestmentDescriptor> eligible = portfolio.getActiveForSecondaryMarketplace().parallel().map(i -> getDescriptor(i, auth)).collect(Collectors.toSet());
Events.fire(new SellingStartedEvent(eligible, overview));
final Collection<Investment> investmentsSold = strategy.recommend(eligible, overview).peek(r -> Events.fire(new SaleRecommendedEvent(r))).map(r -> auth.call(zonky -> processInvestment(zonky, r))).flatMap(o -> o.map(Stream::of).orElse(Stream.empty())).collect(Collectors.toSet());
Events.fire(new SellingCompletedEvent(investmentsSold, portfolio.calculateOverview()));
}
use of com.github.robozonky.api.strategies.InvestmentDescriptor 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);
});
}
Aggregations