Search in sources :

Example 1 with InvestmentStrategy

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

the class NaturalLanguageInvestmentStrategyTest method noLoansApplicable.

@Test
void noLoansApplicable() {
    final MarketplaceFilter filter = MarketplaceFilter.of(MarketplaceFilterCondition.alwaysAccepting());
    final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.PROGRESSIVE, Collections.singleton(filter));
    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);
    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) MarketplaceFilter(com.github.robozonky.strategy.natural.conditions.MarketplaceFilter) 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 2 with InvestmentStrategy

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

the class NaturalLanguageInvestmentStrategyTest method nothingRecommendedDueToRatingOverinvested.

@Test
void nothingRecommendedDueToRatingOverinvested() {
    final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.EMPTY, 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(1000);
    final Stream<RecommendedLoan> result = s.recommend(Collections.singletonList(new LoanDescriptor(l)), portfolio, new Restrictions());
    assertThat(result).isEmpty();
}
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 3 with InvestmentStrategy

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

the class NaturalLanguageInvestmentStrategyTest method unacceptablePortfolioDueToLowBalance.

@Test
void unacceptablePortfolioDueToLowBalance() {
    final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.EMPTY);
    final InvestmentStrategy s = new NaturalLanguageInvestmentStrategy(p);
    final PortfolioOverview portfolio = mock(PortfolioOverview.class);
    when(portfolio.getCzkAvailable()).thenReturn(p.getMinimumBalance() - 1);
    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 4 with InvestmentStrategy

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

the class SimpleStrategyService method toInvest.

@Override
public Optional<InvestmentStrategy> toInvest(final String strategy) {
    try {
        final InvestmentStrategy s = SimpleStrategyService.parseOrThrow(strategy);
        SimpleStrategyService.LOGGER.warn("Using legacy strategy format. Secondary marketplace support disabled.");
        return Optional.of(s);
    } catch (final Exception ex) {
        SimpleStrategyService.LOGGER.debug("Failed parsing strategy, OK if using natural directly: {}.", ex.getMessage());
        return Optional.empty();
    }
}
Also used : InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) NaturalLanguageInvestmentStrategy(com.github.robozonky.strategy.natural.NaturalLanguageInvestmentStrategy)

Example 5 with InvestmentStrategy

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

the class StrategyExecutorTest method rechecksMarketplaceIfBalanceIncreased.

@Test
void rechecksMarketplaceIfBalanceIncreased() {
    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);
    // marketplace never has any updates
    when(mocked.hasMarketplaceUpdates(any())).thenReturn(false);
    // fresh balance, check marketplace
    mocked.apply(p, marketplace);
    verify(mocked).execute(eq(p), eq(ALL_ACCEPTING_STRATEGY), eq(marketplace));
    // nothing changed, still only ran once
    mocked.apply(p, marketplace);
    verify(mocked, times(1)).execute(eq(p), eq(ALL_ACCEPTING_STRATEGY), eq(marketplace));
    // increase remote balance
    when(zonky.getWallet()).thenReturn(new Wallet(BigDecimal.valueOf(100_000)));
    // should have checked marketplace
    mocked.apply(p, marketplace);
    verify(mocked, times(2)).execute(eq(p), eq(ALL_ACCEPTING_STRATEGY), eq(marketplace));
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Wallet(com.github.robozonky.api.remote.entities.Wallet) 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)

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