use of com.github.robozonky.api.strategies.PortfolioOverview in project robozonky by RoboZonky.
the class DelinquentsTest method noLongerDelinquent.
@Test
void noLongerDelinquent() {
final PortfolioOverview po = mock(PortfolioOverview.class);
final Loan l = Loan.custom().setId(RANDOM.nextInt(10000)).setMyInvestment(mockMyInvestment()).build();
final Investment i = Investment.fresh(l, 200).setNextPaymentDate(OffsetDateTime.ofInstant(Instant.EPOCH, Defaults.ZONE_ID)).build();
final Function<Investment, Loan> f = (id) -> l;
// register delinquence
Delinquents.update(Collections.singleton(i), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
// ignore events just emitted
this.readPreexistingEvents();
// the investment is no longer delinquent
Delinquents.update(Collections.emptyList(), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
assertThat(this.getNewEvents()).hasSize(1).first().isInstanceOf(LoanNoLongerDelinquentEvent.class);
}
use of com.github.robozonky.api.strategies.PortfolioOverview in project robozonky by RoboZonky.
the class DelinquentsTest method paid.
@Test
void paid() {
final PortfolioOverview po = mock(PortfolioOverview.class);
final Loan l = Loan.custom().setId(RANDOM.nextInt(10000)).setMyInvestment(mockMyInvestment()).build();
final Investment i = Investment.fresh(l, 200).setPaymentStatus(PaymentStatus.PAID).setNextPaymentDate(OffsetDateTime.ofInstant(Instant.EPOCH, Defaults.ZONE_ID)).build();
final Function<Investment, Loan> f = (id) -> l;
// register delinquence
Delinquents.update(Collections.singleton(i), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
// ignore events just emitted
this.readPreexistingEvents();
// the investment is paid
Delinquents.update(Collections.emptyList(), Collections.singletonList(i), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
assertThat(this.getNewEvents()).hasSize(1).first().isInstanceOf(LoanRepaidEvent.class);
}
use of com.github.robozonky.api.strategies.PortfolioOverview in project robozonky by RoboZonky.
the class DelinquentsTest method defaulted.
@Test
void defaulted() {
final PortfolioOverview po = mock(PortfolioOverview.class);
final Loan l = Loan.custom().setId(RANDOM.nextInt(10000)).setMyInvestment(mockMyInvestment()).build();
final Investment i = Investment.fresh(l, 200).setPaymentStatus(PaymentStatus.PAID_OFF).setNextPaymentDate(OffsetDateTime.ofInstant(Instant.EPOCH, Defaults.ZONE_ID)).build();
final Function<Investment, Loan> f = (id) -> l;
// register delinquency
Delinquents.update(Collections.singleton(i), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
// ignore events just emitted
this.readPreexistingEvents();
// the investment is defaulted
Delinquents.update(Collections.emptyList(), Collections.singletonList(i), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
assertThat(this.getNewEvents()).hasSize(1).first().isInstanceOf(LoanDefaultedEvent.class);
}
use of com.github.robozonky.api.strategies.PortfolioOverview in project robozonky by RoboZonky.
the class DelinquentsTest method oldDelinquency.
@Test
void oldDelinquency() {
final PortfolioOverview po = mock(PortfolioOverview.class);
final Loan l = Loan.custom().setId(RANDOM.nextInt(10000)).setMyInvestment(mockMyInvestment()).build();
final Investment i = Investment.fresh(l, 200).setNextPaymentDate(OffsetDateTime.ofInstant(Instant.EPOCH, Defaults.ZONE_ID)).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);
// all 5 delinquency events
softly.assertThat(this.getNewEvents()).hasSize(5);
});
}
use of com.github.robozonky.api.strategies.PortfolioOverview in project robozonky by RoboZonky.
the class FinancialCalculator method feePaid.
private static BigDecimal feePaid(final Investment investment, final PortfolioOverview portfolioOverview, final int totalMonths) {
if (totalMonths == 0) {
return BigDecimal.ZERO;
}
final BigDecimal originalValue = investment.getOriginalPrincipal();
final BigDecimal monthlyRate = divide(investment.getInterestRate(), 12);
final BigDecimal monthlyFee = divide(estimateFeeRate(investment, portfolioOverview), 12);
final BigDecimal pmt = FinancialUtil.pmt(monthlyRate, investment.getOriginalTerm(), originalValue);
final BigDecimal result = IntStream.range(0, totalMonths).mapToObj(term -> FinancialUtil.fv(monthlyRate, term + 1, pmt, originalValue).negate()).map(fv -> times(fv, monthlyFee)).reduce(BigDecimal.ZERO, BigDecimalCalculator::plus);
return toScale(result);
}
Aggregations