use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class StaticInvestorTest method investmentFromAmountlessConfirmation.
@Test
void investmentFromAmountlessConfirmation() {
final LoanDescriptor ld = mockLoanDescriptor();
final int recommended = 200;
final Investment i = Investor.convertToInvestment(ld.recommend(recommended).get());
assertThat(i.getOriginalPrincipal().intValue()).isEqualTo(recommended);
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class RepaymentsTest method registerNewRepayments.
@Test
void registerNewRepayments() {
final Loan l = Loan.custom().setId(1).setAmount(200).setRating(Rating.D).setMyInvestment(mockMyInvestment()).setRemainingInvestment(0).build();
final Investment i = Investment.fresh(l, 200).setPaymentStatus(PaymentStatus.OK).build();
// first, portfolio contains one active investment; no repaid
final Zonky z = harmlessZonky(10_000);
when(z.getLoan(eq(l.getId()))).thenReturn(l);
final Portfolio p = new Portfolio(Collections.singletonList(i), mockBalance(z));
final Authenticated a = mockAuthentication(z);
final Repayments r = new Repayments();
r.accept(p, a);
assertThat(getNewEvents()).isEmpty();
// now, portfolio has the same investment marked as paid; event will be triggered
Investment.markAsPaid(i);
r.accept(p, a);
assertThat(getNewEvents()).first().isInstanceOf(LoanRepaidEvent.class);
// make sure the loan was retrieved from Zonky
verify(z).getLoan(eq(l.getId()));
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class SessionTest method empty.
@Test
void empty() {
final Zonky z = mockZonky();
final Authenticated auth = mockAuthentication(z);
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final Collection<Investment> i = Session.purchase(portfolio, auth, Stream.empty(), null, true);
assertThat(i).isEmpty();
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class SessionTest method properReal.
@Test
void properReal() {
final Loan l = Loan.custom().setId(1).setAmount(200).setRating(Rating.D).setRemainingInvestment(200).setMyInvestment(mockMyInvestment()).build();
final Participation p = mock(Participation.class);
when(p.getLoanId()).thenReturn(l.getId());
when(p.getRemainingPrincipal()).thenReturn(BigDecimal.valueOf(200));
final PurchaseStrategy s = mock(PurchaseStrategy.class);
when(s.recommend(any(), any(), any())).thenAnswer(i -> {
final Collection<ParticipationDescriptor> participations = i.getArgument(0);
return participations.stream().map(ParticipationDescriptor::recommend).flatMap(o -> o.map(Stream::of).orElse(Stream.empty()));
});
final Zonky z = mockZonky(BigDecimal.valueOf(100_000));
when(z.getLoan(eq(l.getId()))).thenReturn(l);
final Authenticated auth = mockAuthentication(z);
final Portfolio portfolio = spy(Portfolio.create(z, mockBalance(z)));
final ParticipationDescriptor pd = new ParticipationDescriptor(p, l);
final Collection<Investment> i = Session.purchase(portfolio, auth, Stream.of(pd), new RestrictedPurchaseStrategy(s, new Restrictions()), false);
assertThat(i).hasSize(1);
assertThat(this.getNewEvents()).hasSize(5);
verify(z).purchase(eq(p));
verify(portfolio).newBlockedAmount(eq(auth), argThat((a) -> a.getLoanId() == l.getId()));
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment 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