Search in sources :

Example 1 with PortfolioOverview

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);
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) Random(java.util.Random) LoanNowDelinquentEvent(com.github.robozonky.api.notifications.LoanNowDelinquentEvent) Development(com.github.robozonky.api.remote.entities.sanitized.Development) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Instant(java.time.Instant) Function(java.util.function.Function) PaymentStatus(com.github.robozonky.api.remote.enums.PaymentStatus) LoanNoLongerDelinquentEvent(com.github.robozonky.api.notifications.LoanNoLongerDelinquentEvent) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) OffsetDateTime(java.time.OffsetDateTime) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) LoanDefaultedEvent(com.github.robozonky.api.notifications.LoanDefaultedEvent) LocalDate(java.time.LocalDate) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Defaults(com.github.robozonky.internal.api.Defaults) Assertions(org.assertj.core.api.Assertions) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Collections(java.util.Collections) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 2 with PortfolioOverview

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);
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) Random(java.util.Random) LoanNowDelinquentEvent(com.github.robozonky.api.notifications.LoanNowDelinquentEvent) Development(com.github.robozonky.api.remote.entities.sanitized.Development) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Instant(java.time.Instant) Function(java.util.function.Function) PaymentStatus(com.github.robozonky.api.remote.enums.PaymentStatus) LoanNoLongerDelinquentEvent(com.github.robozonky.api.notifications.LoanNoLongerDelinquentEvent) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) OffsetDateTime(java.time.OffsetDateTime) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) LoanDefaultedEvent(com.github.robozonky.api.notifications.LoanDefaultedEvent) LocalDate(java.time.LocalDate) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Defaults(com.github.robozonky.internal.api.Defaults) Assertions(org.assertj.core.api.Assertions) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Collections(java.util.Collections) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 3 with PortfolioOverview

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);
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) Random(java.util.Random) LoanNowDelinquentEvent(com.github.robozonky.api.notifications.LoanNowDelinquentEvent) Development(com.github.robozonky.api.remote.entities.sanitized.Development) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Instant(java.time.Instant) Function(java.util.function.Function) PaymentStatus(com.github.robozonky.api.remote.enums.PaymentStatus) LoanNoLongerDelinquentEvent(com.github.robozonky.api.notifications.LoanNoLongerDelinquentEvent) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) OffsetDateTime(java.time.OffsetDateTime) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) LoanDefaultedEvent(com.github.robozonky.api.notifications.LoanDefaultedEvent) LocalDate(java.time.LocalDate) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Defaults(com.github.robozonky.internal.api.Defaults) Assertions(org.assertj.core.api.Assertions) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Collections(java.util.Collections) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 4 with PortfolioOverview

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);
    });
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) Random(java.util.Random) LoanNowDelinquentEvent(com.github.robozonky.api.notifications.LoanNowDelinquentEvent) Development(com.github.robozonky.api.remote.entities.sanitized.Development) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Instant(java.time.Instant) Function(java.util.function.Function) PaymentStatus(com.github.robozonky.api.remote.enums.PaymentStatus) LoanNoLongerDelinquentEvent(com.github.robozonky.api.notifications.LoanNoLongerDelinquentEvent) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) OffsetDateTime(java.time.OffsetDateTime) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) LoanDefaultedEvent(com.github.robozonky.api.notifications.LoanDefaultedEvent) LocalDate(java.time.LocalDate) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Defaults(com.github.robozonky.internal.api.Defaults) Assertions(org.assertj.core.api.Assertions) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Collections(java.util.Collections) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 5 with PortfolioOverview

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);
}
Also used : IntStream(java.util.stream.IntStream) BigDecimalCalculator.toScale(com.github.robozonky.util.BigDecimalCalculator.toScale) BigDecimalCalculator.divide(com.github.robozonky.util.BigDecimalCalculator.divide) EnumMap(java.util.EnumMap) BigDecimalCalculator.plus(com.github.robozonky.util.BigDecimalCalculator.plus) BigDecimalCalculator.minus(com.github.robozonky.util.BigDecimalCalculator.minus) Instant(java.time.Instant) BigDecimal(java.math.BigDecimal) BigDecimalCalculator.times(com.github.robozonky.util.BigDecimalCalculator.times) OffsetDateTime(java.time.OffsetDateTime) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) TreeMap(java.util.TreeMap) LocalDate(java.time.LocalDate) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Rating(com.github.robozonky.api.remote.enums.Rating) Defaults(com.github.robozonky.internal.api.Defaults) SortedMap(java.util.SortedMap) BigDecimal(java.math.BigDecimal)

Aggregations

PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)26 Test (org.junit.jupiter.api.Test)18 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)11 Restrictions (com.github.robozonky.api.remote.entities.Restrictions)10 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)9 Collection (java.util.Collection)8 Collections (java.util.Collections)8 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)7 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)7 Defaults (com.github.robozonky.internal.api.Defaults)7 Assertions (org.assertj.core.api.Assertions)6 SoftAssertions (org.assertj.core.api.SoftAssertions)6 Mockito (org.mockito.Mockito)6 LoanRepaidEvent (com.github.robozonky.api.notifications.LoanRepaidEvent)5 PaymentStatus (com.github.robozonky.api.remote.enums.PaymentStatus)5 InvestmentStrategy (com.github.robozonky.api.strategies.InvestmentStrategy)5 PurchaseStrategy (com.github.robozonky.api.strategies.PurchaseStrategy)5 RecommendedParticipation (com.github.robozonky.api.strategies.RecommendedParticipation)5 Instant (java.time.Instant)5 LocalDate (java.time.LocalDate)5