use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.
the class EmailingListenerTest method listeners.
@TestFactory
Stream<DynamicNode> listeners() throws MalformedURLException {
// prepare data
final Loan loan = Loan.custom().setId(66666).setAmount(100_000).setInterestRate(BigDecimal.TEN).setDatePublished(OffsetDateTime.now().minusMonths(2)).setName("Úvěr").setRegion(Region.JIHOCESKY).setPurpose(Purpose.AUTO_MOTO).setMainIncomeType(MainIncomeType.EMPLOYMENT).setRemainingInvestment(2000).setRating(Rating.AAAAA).setTermInMonths(25).setUrl(new URL("http://www.robozonky.cz")).build();
final LoanDescriptor loanDescriptor = new LoanDescriptor(loan);
final RecommendedLoan recommendation = loanDescriptor.recommend(1200, false).get();
final Investment i = Investment.fresh((MarketplaceLoan) loan, 1000).build();
// create events for listeners
return Stream.of(forListener(SupportedListener.INVESTMENT_DELEGATED, new InvestmentDelegatedEvent(recommendation, "random")), forListener(SupportedListener.INVESTMENT_MADE, new InvestmentMadeEvent(i, loan, MAX_PORTFOLIO)), forListener(SupportedListener.INVESTMENT_SOLD, new InvestmentSoldEvent(i, loan, MAX_PORTFOLIO)), forListener(SupportedListener.INVESTMENT_SKIPPED, new InvestmentSkippedEvent(recommendation)), forListener(SupportedListener.INVESTMENT_REJECTED, new InvestmentRejectedEvent(recommendation, "random")), forListener(SupportedListener.LOAN_NO_LONGER_DELINQUENT, new LoanNoLongerDelinquentEvent(i, loan, LocalDate.now(), Collections.singletonList(mockCollectionNoEndDate()))), forListener(SupportedListener.LOAN_DEFAULTED, new LoanDefaultedEvent(i, loan, LocalDate.now(), Collections.singletonList(mockCollectionNoNote()))), forListener(SupportedListener.LOAN_NOW_DELINQUENT, new LoanNowDelinquentEvent(i, loan, LocalDate.now(), Collections.emptyList())), forListener(SupportedListener.LOAN_DELINQUENT_10_PLUS, new LoanDelinquent10DaysOrMoreEvent(i, loan, LocalDate.now().minusDays(11), Collections.emptyList())), forListener(SupportedListener.LOAN_DELINQUENT_30_PLUS, new LoanDelinquent30DaysOrMoreEvent(i, loan, LocalDate.now().minusDays(31), Collections.emptyList())), forListener(SupportedListener.LOAN_DELINQUENT_60_PLUS, new LoanDelinquent60DaysOrMoreEvent(i, loan, LocalDate.now().minusDays(61), Collections.emptyList())), forListener(SupportedListener.LOAN_DELINQUENT_90_PLUS, new LoanDelinquent90DaysOrMoreEvent(i, loan, LocalDate.now().minusDays(91), Collections.emptyList())), forListener(SupportedListener.LOAN_REPAID, new LoanRepaidEvent(i, loan, MAX_PORTFOLIO)), forListener(SupportedListener.BALANCE_ON_TARGET, new ExecutionStartedEvent(Collections.emptyList(), MAX_PORTFOLIO)), forListener(SupportedListener.BALANCE_UNDER_MINIMUM, new ExecutionStartedEvent(Collections.emptyList(), mockPortfolio(0))), forListener(SupportedListener.CRASHED, new RoboZonkyCrashedEvent(ReturnCode.ERROR_UNEXPECTED, new RuntimeException())), forListener(SupportedListener.REMOTE_OPERATION_FAILED, new RemoteOperationFailedEvent(new RuntimeException())), forListener(SupportedListener.DAEMON_FAILED, new RoboZonkyDaemonFailedEvent(new RuntimeException())), forListener(SupportedListener.INITIALIZED, new RoboZonkyInitializedEvent()), forListener(SupportedListener.ENDING, new RoboZonkyEndingEvent()), forListener(SupportedListener.TESTING, new RoboZonkyTestingEvent()), forListener(SupportedListener.UPDATE_DETECTED, new RoboZonkyUpdateDetectedEvent("1.2.3")), forListener(SupportedListener.EXPERIMENTAL_UPDATE_DETECTED, new RoboZonkyExperimentalUpdateDetectedEvent("1.3.0-beta-1")), forListener(SupportedListener.INVESTMENT_PURCHASED, new InvestmentPurchasedEvent(i, loan, MAX_PORTFOLIO)), forListener(SupportedListener.SALE_OFFERED, new SaleOfferedEvent(i, loan)));
}
use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.
the class InvestmentSizeRecommenderTest method minimumOverRemaining.
@Test
void minimumOverRemaining() {
final int minimumInvestment = 1000;
final Loan l = mockLoan(minimumInvestment - 1);
final ParsedStrategy s = mock(ParsedStrategy.class);
when(s.getMinimumInvestmentSizeInCzk(eq(l.getRating()))).thenReturn(minimumInvestment);
when(s.getMaximumInvestmentSizeInCzk(eq(l.getRating()))).thenReturn(minimumInvestment * 2);
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 InvestmentSizeRecommenderTest method byDefault.
@Test
void byDefault() {
final ParsedStrategy s = getStrategy();
final Loan l = mockLoan(100_000);
final InvestmentSizeRecommender r = new InvestmentSizeRecommender(s, Defaults.MAXIMUM_INVESTMENT_IN_CZK);
// with unlimited balance, make maximum possible recommendation
final int actualInvestment = r.apply(l, Integer.MAX_VALUE);
assertThat(actualInvestment).isEqualTo(MAXIMUM_INVESTMENT);
// with balance less that the recommendation, go just under maximum
final int investmentOnLowBalance = r.apply(l, actualInvestment - 1);
assertThat(investmentOnLowBalance).isEqualTo(MAXIMUM_INVESTMENT - Defaults.MINIMUM_INVESTMENT_INCREMENT_IN_CZK);
}
use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.
the class NaturalLanguageInvestmentStrategyTest method nothingRecommendedDueToRatingOverinvested.
@Test
void nothingRecommendedDueToRatingOverinvested() {
final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.EMPTY, 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(1000);
final Stream<RecommendedLoan> result = s.recommend(Collections.singletonList(new LoanDescriptor(l)), portfolio, new Restrictions());
assertThat(result).isEmpty();
}
use of com.github.robozonky.api.remote.entities.sanitized.Loan 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();
});
}
Aggregations