Search in sources :

Example 31 with LoanDescriptor

use of com.github.robozonky.api.strategies.LoanDescriptor 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 32 with LoanDescriptor

use of com.github.robozonky.api.strategies.LoanDescriptor 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)

Example 33 with LoanDescriptor

use of com.github.robozonky.api.strategies.LoanDescriptor in project robozonky by RoboZonky.

the class PrimaryMarketplaceComparatorTest method sortByRecency.

@Test
void sortByRecency() {
    final OffsetDateTime first = OffsetDateTime.ofInstant(Instant.EPOCH, Defaults.ZONE_ID);
    final OffsetDateTime second = first.plus(Duration.ofMillis(1));
    final Loan l1 = mockLoan(1, 100000, first);
    final Loan l2 = mockLoan(l1.getId() + 1, l1.getAmount(), second);
    final LoanDescriptor ld1 = new LoanDescriptor(l1), ld2 = new LoanDescriptor(l2);
    assertSoftly(softly -> {
        softly.assertThat(c.compare(ld1, ld2)).isEqualTo(1);
        softly.assertThat(c.compare(ld2, ld1)).isEqualTo(-1);
        softly.assertThat(c.compare(ld1, ld1)).isEqualTo(0);
    });
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) OffsetDateTime(java.time.OffsetDateTime) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Test(org.junit.jupiter.api.Test)

Example 34 with LoanDescriptor

use of com.github.robozonky.api.strategies.LoanDescriptor in project robozonky by RoboZonky.

the class PrimaryMarketplaceComparatorTest method sortByRemainingIfAsRecent.

@Test
void sortByRemainingIfAsRecent() {
    final OffsetDateTime first = OffsetDateTime.ofInstant(Instant.EPOCH, Defaults.ZONE_ID);
    final Loan l1 = mockLoan(1, 100000, first);
    final Loan l2 = mockLoan(l1.getId() + 1, l1.getAmount() + 1, l1.getDatePublished());
    final LoanDescriptor ld1 = new LoanDescriptor(l1), ld2 = new LoanDescriptor(l2);
    assertSoftly(softly -> {
        softly.assertThat(c.compare(ld1, ld2)).isEqualTo(1);
        softly.assertThat(c.compare(ld2, ld1)).isEqualTo(-1);
    });
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) OffsetDateTime(java.time.OffsetDateTime) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)34 Test (org.junit.jupiter.api.Test)29 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)17 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)15 Portfolio (com.github.robozonky.app.portfolio.Portfolio)15 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)13 Zonky (com.github.robozonky.common.remote.Zonky)12 InvestmentStrategy (com.github.robozonky.api.strategies.InvestmentStrategy)11 Authenticated (com.github.robozonky.app.authentication.Authenticated)11 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)10 Event (com.github.robozonky.api.notifications.Event)8 InvestmentDelegatedEvent (com.github.robozonky.api.notifications.InvestmentDelegatedEvent)8 InvestmentMadeEvent (com.github.robozonky.api.notifications.InvestmentMadeEvent)8 InvestmentRejectedEvent (com.github.robozonky.api.notifications.InvestmentRejectedEvent)8 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)8 ExecutionCompletedEvent (com.github.robozonky.api.notifications.ExecutionCompletedEvent)7 MarketplaceLoan (com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan)7 ExecutionStartedEvent (com.github.robozonky.api.notifications.ExecutionStartedEvent)6 InvestmentSkippedEvent (com.github.robozonky.api.notifications.InvestmentSkippedEvent)6 Restrictions (com.github.robozonky.api.remote.entities.Restrictions)6