Search in sources :

Example 1 with InvestmentDescriptor

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();
    });
}
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 2 with InvestmentDescriptor

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()));
}
Also used : SaleRecommendedEvent(com.github.robozonky.api.notifications.SaleRecommendedEvent) Logger(org.slf4j.Logger) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Zonky(com.github.robozonky.common.remote.Zonky) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) SaleRequestedEvent(com.github.robozonky.api.notifications.SaleRequestedEvent) InvestmentDescriptor(com.github.robozonky.api.strategies.InvestmentDescriptor) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) RecommendedInvestment(com.github.robozonky.api.strategies.RecommendedInvestment) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) Stream(java.util.stream.Stream) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) LoanCache(com.github.robozonky.app.util.LoanCache) Events(com.github.robozonky.app.Events) Authenticated(com.github.robozonky.app.authentication.Authenticated) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Optional(java.util.Optional) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) SellStrategy(com.github.robozonky.api.strategies.SellStrategy) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) SaleRecommendedEvent(com.github.robozonky.api.notifications.SaleRecommendedEvent) InvestmentDescriptor(com.github.robozonky.api.strategies.InvestmentDescriptor) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) RecommendedInvestment(com.github.robozonky.api.strategies.RecommendedInvestment) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment)

Example 3 with InvestmentDescriptor

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

Aggregations

Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)3 InvestmentDescriptor (com.github.robozonky.api.strategies.InvestmentDescriptor)3 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)2 MarketplaceLoan (com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan)2 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)2 ParticipationDescriptor (com.github.robozonky.api.strategies.ParticipationDescriptor)2 Test (org.junit.jupiter.api.Test)2 SaleOfferedEvent (com.github.robozonky.api.notifications.SaleOfferedEvent)1 SaleRecommendedEvent (com.github.robozonky.api.notifications.SaleRecommendedEvent)1 SaleRequestedEvent (com.github.robozonky.api.notifications.SaleRequestedEvent)1 SellingCompletedEvent (com.github.robozonky.api.notifications.SellingCompletedEvent)1 SellingStartedEvent (com.github.robozonky.api.notifications.SellingStartedEvent)1 RawInvestment (com.github.robozonky.api.remote.entities.RawInvestment)1 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)1 RecommendedInvestment (com.github.robozonky.api.strategies.RecommendedInvestment)1 SellStrategy (com.github.robozonky.api.strategies.SellStrategy)1 Events (com.github.robozonky.app.Events)1 Authenticated (com.github.robozonky.app.authentication.Authenticated)1 LoanCache (com.github.robozonky.app.util.LoanCache)1 Zonky (com.github.robozonky.common.remote.Zonky)1