Search in sources :

Example 46 with Investment

use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.

the class ParsedStrategyTest method sellOffStarted.

@Test
void sellOffStarted() {
    final DefaultPortfolio portfolio = DefaultPortfolio.EMPTY;
    final DefaultValues values = new DefaultValues(portfolio);
    // activate default sell-off 3 months before the given date, which is already in the past
    values.setExitProperties(new ExitProperties(LocalDate.now().plusMonths(2)));
    final ParsedStrategy strategy = new ParsedStrategy(values, Collections.emptyList());
    // no loan or participation should be bought; every investment should be sold
    final Loan l = mockLoan(1000);
    final LoanDescriptor ld = new LoanDescriptor(l);
    final ParticipationDescriptor pd = mockParticipationDescriptor(l);
    final Investment i = Investment.fresh((MarketplaceLoan) l, 200);
    final InvestmentDescriptor id = new InvestmentDescriptor(i, l);
    assertSoftly(softly -> {
        softly.assertThat(strategy.getApplicableLoans(Collections.singleton(ld))).isEmpty();
        softly.assertThat(strategy.getApplicableParticipations(Collections.singleton(pd))).isEmpty();
        softly.assertThat(strategy.getApplicableInvestments(Collections.singleton(id))).containsOnly(id);
    });
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) ParticipationDescriptor(com.github.robozonky.api.strategies.ParticipationDescriptor) InvestmentDescriptor(com.github.robozonky.api.strategies.InvestmentDescriptor) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test)

Example 47 with Investment

use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.

the class WrapperTest method fromInvestment.

@Test
void fromInvestment() {
    final Loan loan = Loan.custom().setId(1).setAmount(100_000).build();
    final int invested = 200;
    final Investment investment = Investment.fresh((MarketplaceLoan) loan, invested).build();
    final Wrapper w = new Wrapper(investment, loan);
    assertSoftly(softly -> {
        softly.assertThat(w.getLoanId()).isEqualTo(loan.getId());
        softly.assertThat(w.getStory()).isEqualTo(loan.getStory());
        softly.assertThat(w.getRegion()).isEqualTo(loan.getRegion());
        softly.assertThat(w.getRating()).isEqualTo(loan.getRating());
        softly.assertThat(w.getOriginalAmount()).isEqualTo(loan.getAmount());
        softly.assertThat(w.getInterestRate()).isEqualTo(loan.getInterestRate());
        softly.assertThat(w.getRemainingTermInMonths()).isEqualTo(investment.getRemainingMonths());
        softly.assertThat(w.getRemainingAmount()).isEqualTo(BigDecimal.valueOf(invested));
        softly.assertThat(w.getIdentifier()).isNotNull();
    });
}
Also used : MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test)

Example 48 with Investment

use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.

the class ZonkyTest method cancel.

@Test
void cancel() {
    final ControlApi control = mock(ControlApi.class);
    final Api<ControlApi> ca = mockApi(control);
    final PaginatedApi<RawLoan, LoanApi> la = mockApi();
    final PaginatedApi<BlockedAmount, WalletApi> wa = mockApi();
    final PaginatedApi<RawInvestment, PortfolioApi> pa = mockApi();
    final PaginatedApi<Participation, ParticipationApi> sa = mockApi();
    final PaginatedApi<RawDevelopment, CollectionsApi> caa = mockApi();
    final Zonky z = new Zonky(ca, la, sa, pa, wa, caa);
    final Investment i = mock(Investment.class);
    when(i.getId()).thenReturn(1);
    z.cancel(i);
    verify(control).cancel(eq(i.getId()));
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) ParticipationApi(com.github.robozonky.api.remote.ParticipationApi) WalletApi(com.github.robozonky.api.remote.WalletApi) LoanApi(com.github.robozonky.api.remote.LoanApi) PortfolioApi(com.github.robozonky.api.remote.PortfolioApi) BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount) RawLoan(com.github.robozonky.api.remote.entities.RawLoan) ControlApi(com.github.robozonky.api.remote.ControlApi) RawDevelopment(com.github.robozonky.api.remote.entities.RawDevelopment) CollectionsApi(com.github.robozonky.api.remote.CollectionsApi) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) Test(org.junit.jupiter.api.Test)

Example 49 with Investment

use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.

the class FinancialCalculatorTest method expectedInterest.

private static void expectedInterest(final Rating rating, final int threshold) {
    final Investment i = Investment.fresh(mockLoan(rating), 1000).setInterestRate(BigDecimal.TEN).setRemainingMonths(50).build();
    final BigDecimal before = FinancialCalculator.expectedInterestAfterFees(i, getPortfolioOverview(threshold - 1));
    final BigDecimal after = FinancialCalculator.expectedInterestAfterFees(i, getPortfolioOverview(threshold));
    assertThat(after).isGreaterThan(before);
}
Also used : BigDecimal(java.math.BigDecimal) MyInvestment(com.github.robozonky.api.remote.entities.MyInvestment) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment)

Example 50 with Investment

use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.

the class InvestmentMadeEventListener method getData.

@Override
protected Map<String, Object> getData(final InvestmentMadeEvent event) {
    final Investment i = event.getInvestment();
    final Map<String, Object> result = super.getData(event);
    result.put("yield", FinancialCalculator.expectedInterestAfterFees(i, event.getPortfolioOverview()));
    final BigDecimal interestRate = FinancialCalculator.expectedInterestRateAfterFees(i, event.getPortfolioOverview());
    result.put("relativeYield", interestRate);
    return result;
}
Also used : BigDecimal(java.math.BigDecimal) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment)

Aggregations

Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)52 Test (org.junit.jupiter.api.Test)34 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)24 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)20 BigDecimal (java.math.BigDecimal)20 Event (com.github.robozonky.api.notifications.Event)13 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)13 Authenticated (com.github.robozonky.app.authentication.Authenticated)13 Zonky (com.github.robozonky.common.remote.Zonky)13 Collection (java.util.Collection)13 Assertions (org.assertj.core.api.Assertions)13 SoftAssertions (org.assertj.core.api.SoftAssertions)13 Mockito (org.mockito.Mockito)13 Collections (java.util.Collections)12 Stream (java.util.stream.Stream)11 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)10 Portfolio (com.github.robozonky.app.portfolio.Portfolio)9 Participation (com.github.robozonky.api.remote.entities.Participation)8 MarketplaceLoan (com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan)8 ExecutionCompletedEvent (com.github.robozonky.api.notifications.ExecutionCompletedEvent)7