use of com.github.robozonky.api.strategies.PortfolioOverview in project robozonky by RoboZonky.
the class PortfolioTest method run.
@Test
void run() {
final PortfolioOverview portfolio = mock(PortfolioOverview.class);
when(portfolio.getCzkAvailable()).thenReturn(1000);
when(portfolio.getCzkInvested()).thenReturn(10000);
when(portfolio.getCzkAtRisk()).thenReturn(0);
when(portfolio.getShareOnInvestment(any())).thenReturn(BigDecimal.ONE);
when(portfolio.getCzkAtRisk(any())).thenReturn(0);
when(portfolio.getAtRiskShareOnInvestment(any())).thenReturn(BigDecimal.ZERO);
when(portfolio.getCzkInvested(any())).thenReturn(1000);
final Portfolio mbean = new Portfolio();
final ExecutionStartedEvent evt = new ExecutionStartedEvent(Collections.emptyList(), portfolio);
mbean.handle(evt);
assertSoftly(softly -> {
softly.assertThat(mbean.getAmountAtRisk()).isEqualTo(0);
softly.assertThat(mbean.getAvailableBalance()).isEqualTo(portfolio.getCzkAvailable());
softly.assertThat(mbean.getInvestedAmount()).isEqualTo(portfolio.getCzkInvested());
softly.assertThat(mbean.getLatestUpdatedDateTime()).isBeforeOrEqualTo(OffsetDateTime.now());
// checks for proper ordering of ratings
final String[] ratings = Stream.of(Rating.values()).map(Rating::getCode).toArray(String[]::new);
softly.assertThat(mbean.getInvestedAmountPerRating().keySet()).containsExactly(ratings);
softly.assertThat(mbean.getRatingShare().keySet()).containsExactly(ratings);
// checks correct values per rating
Stream.of(ratings).forEach(r -> {
softly.assertThat(mbean.getInvestedAmountPerRating()).containsEntry(r, 1000);
softly.assertThat(mbean.getShareAtRiskPerRating()).containsEntry(r, BigDecimal.ZERO);
softly.assertThat(mbean.getAmountAtRiskPerRating()).containsEntry(r, 0);
softly.assertThat(mbean.getRatingShare()).containsEntry(r, BigDecimal.ONE);
});
});
}
use of com.github.robozonky.api.strategies.PortfolioOverview in project robozonky by RoboZonky.
the class DelinquentsTest method newDelinquence.
@Test
void newDelinquence() {
final PortfolioOverview po = mock(PortfolioOverview.class);
final Loan l = Loan.custom().setId(RANDOM.nextInt(10000)).setAmount(200).setMyInvestment(mockMyInvestment()).build();
final Investment i = Investment.fresh(l, 200).setNextPaymentDate(OffsetDateTime.now().minusDays(1)).build();
final Function<Investment, Loan> f = (id) -> l;
// make sure new delinquencies are reported and stored
Delinquents.update(Collections.singleton(i), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
assertSoftly(softly -> {
softly.assertThat(Delinquents.getDelinquents()).hasSize(1);
softly.assertThat(this.getNewEvents()).hasSize(1);
});
assertThat(this.getNewEvents().get(0)).isInstanceOf(LoanNowDelinquentEvent.class);
// make sure delinquencies are persisted even when there are none present
Delinquents.update(Collections.emptyList(), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
assertSoftly(softly -> {
softly.assertThat(Delinquents.getDelinquents()).hasSize(1);
softly.assertThat(this.getNewEvents()).hasSize(2);
});
assertThat(this.getNewEvents().get(1)).isInstanceOf(LoanNoLongerDelinquentEvent.class);
// and when they are no longer active, they're gone for good
Delinquents.update(Collections.emptyList(), Collections.singleton(i), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
assertThat(Delinquents.getDelinquents()).hasSize(0);
}
use of com.github.robozonky.api.strategies.PortfolioOverview in project robozonky by RoboZonky.
the class NaturalLanguageInvestmentStrategyTest method recommendationIsMade.
@Test
void recommendationIsMade() {
final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.PROGRESSIVE, 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(100_000);
final Loan l2 = mockLoan(100);
final LoanDescriptor ld = new LoanDescriptor(l);
final List<RecommendedLoan> result = s.recommend(Arrays.asList(new LoanDescriptor(l2), ld), portfolio, new Restrictions()).collect(Collectors.toList());
assertThat(result).hasSize(1);
final RecommendedLoan r = result.get(0);
assertSoftly(softly -> {
softly.assertThat(r.descriptor()).isEqualTo(ld);
softly.assertThat(r.amount()).isEqualTo(BigDecimal.valueOf(Defaults.MINIMUM_INVESTMENT_IN_CZK));
softly.assertThat(r.isConfirmationRequired()).isFalse();
});
}
use of com.github.robozonky.api.strategies.PortfolioOverview in project robozonky by RoboZonky.
the class NaturalLanguageInvestmentStrategyTest method unacceptablePortfolioDueToOverInvestment.
@Test
void unacceptablePortfolioDueToOverInvestment() {
final DefaultValues v = new DefaultValues(DefaultPortfolio.EMPTY);
v.setTargetPortfolioSize(1000);
final ParsedStrategy p = new ParsedStrategy(v, Collections.emptyList(), Collections.emptyMap());
final InvestmentStrategy s = new NaturalLanguageInvestmentStrategy(p);
final PortfolioOverview portfolio = mock(PortfolioOverview.class);
when(portfolio.getCzkAvailable()).thenReturn(p.getMinimumBalance());
when(portfolio.getCzkInvested()).thenReturn(p.getMaximumInvestmentSizeInCzk());
final Stream<RecommendedLoan> result = s.recommend(Collections.singletonList(new LoanDescriptor(mockLoan(2))), portfolio, new Restrictions());
assertThat(result).isEmpty();
}
use of com.github.robozonky.api.strategies.PortfolioOverview 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();
}
Aggregations