Search in sources :

Example 6 with InvestmentStrategy

use of com.github.robozonky.api.strategies.InvestmentStrategy in project robozonky by RoboZonky.

the class InvestmentDaemonTest method standard.

@Test
void standard() {
    final int loanId = 1;
    final MarketplaceLoan ml = MarketplaceLoan.custom().setId(loanId).setRating(Rating.A).build();
    final Loan l = Loan.custom().setId(loanId).setRating(Rating.A).build();
    final Zonky z = harmlessZonky(Defaults.MINIMUM_INVESTMENT_IN_CZK);
    when(z.getAvailableLoans((Select) notNull())).thenReturn(Stream.of(ml));
    when(z.getLoan(eq(loanId))).thenReturn(l);
    final Authenticated a = mockAuthentication(z);
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final InvestmentStrategy is = mock(InvestmentStrategy.class);
    final Supplier<Optional<InvestmentStrategy>> s = () -> Optional.of(is);
    final InvestingDaemon d = new InvestingDaemon(t -> {
    }, a, new Investor.Builder(), s, () -> Optional.of(portfolio), Duration.ofSeconds(1));
    d.run();
    verify(z).getAvailableLoans((Select) notNull());
    verify(z).getLoan(ml.getId());
    verify(is).recommend(any(), any(), any());
    assertThat(d.getRefreshInterval()).isEqualByComparingTo(Duration.ofSeconds(1));
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) Optional(java.util.Optional) Portfolio(com.github.robozonky.app.portfolio.Portfolio) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) Investor(com.github.robozonky.app.investing.Investor) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 7 with InvestmentStrategy

use of com.github.robozonky.api.strategies.InvestmentStrategy in project robozonky by RoboZonky.

the class StrategyExecutorTest method rechecksMarketplaceIfFirstCheckFailed.

@Test
void rechecksMarketplaceIfFirstCheckFailed() {
    final Zonky zonky = harmlessZonky(10_000);
    final Portfolio p = Portfolio.create(zonky, mockBalance(zonky));
    final Loan loan = Loan.custom().build();
    final LoanDescriptor ld = new LoanDescriptor(loan);
    final Collection<LoanDescriptor> marketplace = Collections.singleton(ld);
    // prepare the executor, have it fail when executing the investment operation
    final StrategyExecutor<LoanDescriptor, InvestmentStrategy> e = new AlwaysFreshNeverInvesting();
    final StrategyExecutor<LoanDescriptor, InvestmentStrategy> mocked = spy(e);
    doThrow(new IllegalStateException()).when(mocked).execute(any(), any(), any());
    Assertions.assertThatThrownBy(() -> mocked.apply(p, marketplace)).isInstanceOf(IllegalStateException.class);
    // now the method won't throw, but must be executed again
    reset(mocked);
    mocked.apply(p, marketplace);
    verify(mocked).execute(eq(p), eq(ALL_ACCEPTING_STRATEGY), eq(marketplace));
    // marketplace stays the same + balance stays the same+  previous update passed = no update should be triggered
    reset(mocked);
    when(mocked.hasMarketplaceUpdates(eq(marketplace))).thenReturn(false);
    mocked.apply(p, marketplace);
    verify(mocked, never()).execute(any(), any(), any());
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 8 with InvestmentStrategy

use of com.github.robozonky.api.strategies.InvestmentStrategy in project robozonky by RoboZonky.

the class StrategyExecutorTest method doesNotInvestOnEmptyMarketplace.

@Test
void doesNotInvestOnEmptyMarketplace() {
    final Zonky zonky = harmlessZonky(10_000);
    final Portfolio p = Portfolio.create(zonky, mockBalance(zonky));
    final StrategyExecutor<LoanDescriptor, InvestmentStrategy> e = spy(new AlwaysFreshNeverInvesting());
    e.apply(p, Collections.emptyList());
    verify(e, never()).execute(any(), any(), any());
}
Also used : Portfolio(com.github.robozonky.app.portfolio.Portfolio) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 9 with InvestmentStrategy

use of com.github.robozonky.api.strategies.InvestmentStrategy 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 10 with InvestmentStrategy

use of com.github.robozonky.api.strategies.InvestmentStrategy 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)

Aggregations

InvestmentStrategy (com.github.robozonky.api.strategies.InvestmentStrategy)12 Test (org.junit.jupiter.api.Test)10 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)9 Restrictions (com.github.robozonky.api.remote.entities.Restrictions)6 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)6 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)6 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)5 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)4 Portfolio (com.github.robozonky.app.portfolio.Portfolio)4 Zonky (com.github.robozonky.common.remote.Zonky)4 Optional (java.util.Optional)3 PurchaseStrategy (com.github.robozonky.api.strategies.PurchaseStrategy)2 SellStrategy (com.github.robozonky.api.strategies.SellStrategy)2 StrategyService (com.github.robozonky.api.strategies.StrategyService)2 NaturalLanguageInvestmentStrategy (com.github.robozonky.strategy.natural.NaturalLanguageInvestmentStrategy)2 MarketplaceFilter (com.github.robozonky.strategy.natural.conditions.MarketplaceFilter)2 Collections (java.util.Collections)2 Stream (java.util.stream.Stream)2 Wallet (com.github.robozonky.api.remote.entities.Wallet)1 MarketplaceLoan (com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan)1