Search in sources :

Example 16 with PortfolioOverview

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);
        });
    });
}
Also used : ExecutionStartedEvent(com.github.robozonky.api.notifications.ExecutionStartedEvent) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Test(org.junit.jupiter.api.Test)

Example 17 with PortfolioOverview

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);
}
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 18 with PortfolioOverview

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();
    });
}
Also used : RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Test(org.junit.jupiter.api.Test)

Example 19 with PortfolioOverview

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();
}
Also used : RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Test(org.junit.jupiter.api.Test)

Example 20 with PortfolioOverview

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();
}
Also used : RecommendedParticipation(com.github.robozonky.api.strategies.RecommendedParticipation) Participation(com.github.robozonky.api.remote.entities.Participation) PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) RecommendedParticipation(com.github.robozonky.api.strategies.RecommendedParticipation) Test(org.junit.jupiter.api.Test)

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