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();
}
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();
}
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();
}
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();
}
}
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));
}
Aggregations