Search in sources :

Example 1 with MarketplaceFilter

use of com.github.robozonky.strategy.natural.conditions.MarketplaceFilter 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 MarketplaceFilter

use of com.github.robozonky.strategy.natural.conditions.MarketplaceFilter in project robozonky by RoboZonky.

the class NaturalLanguagePurchaseStrategyTest method noLoansApplicable.

@Test
void noLoansApplicable() {
    final MarketplaceFilter filter = MarketplaceFilter.of(MarketplaceFilterCondition.alwaysAccepting());
    final DefaultValues v = new DefaultValues(DefaultPortfolio.PROGRESSIVE);
    final FilterSupplier w = new FilterSupplier(v, Collections.emptySet(), Collections.singleton(filter));
    final ParsedStrategy p = new ParsedStrategy(v, Collections.emptySet(), Collections.emptyMap(), w);
    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);
    final Stream<RecommendedParticipation> result = s.recommend(Collections.singletonList(mockDescriptor()), portfolio, new Restrictions());
    assertThat(result).isEmpty();
}
Also used : PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) MarketplaceFilter(com.github.robozonky.strategy.natural.conditions.MarketplaceFilter) 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)

Example 3 with MarketplaceFilter

use of com.github.robozonky.strategy.natural.conditions.MarketplaceFilter in project robozonky by RoboZonky.

the class NaturalLanguageSellStrategyTest method noLoansApplicable.

@Test
void noLoansApplicable() {
    final MarketplaceFilter filter = MarketplaceFilter.of(MarketplaceFilterCondition.alwaysAccepting());
    final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.PROGRESSIVE, Collections.singleton(filter));
    final SellStrategy s = new NaturalLanguageSellStrategy(p);
    final PortfolioOverview portfolio = mock(PortfolioOverview.class);
    when(portfolio.getCzkAvailable()).thenReturn(p.getMinimumBalance());
    when(portfolio.getCzkInvested()).thenReturn(p.getMaximumInvestmentSizeInCzk() - 1);
    final Stream<RecommendedInvestment> result = s.recommend(Collections.singletonList(mockDescriptor()), portfolio);
    assertThat(result).isEmpty();
}
Also used : SellStrategy(com.github.robozonky.api.strategies.SellStrategy) MarketplaceFilter(com.github.robozonky.strategy.natural.conditions.MarketplaceFilter) RecommendedInvestment(com.github.robozonky.api.strategies.RecommendedInvestment) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Test(org.junit.jupiter.api.Test)

Example 4 with MarketplaceFilter

use of com.github.robozonky.strategy.natural.conditions.MarketplaceFilter in project robozonky by RoboZonky.

the class ParsedStrategyTest method conditions.

@Test
void conditions() {
    final DefaultPortfolio portfolio = DefaultPortfolio.PROGRESSIVE;
    // test for default values
    final ParsedStrategy strategy = new ParsedStrategy(portfolio);
    assertThat(strategy.getApplicableLoans(Collections.emptyList())).isEmpty();
    // add loan; without filters, should be applicable
    final Loan loan = mockLoan(2);
    final LoanDescriptor ld = new LoanDescriptor(loan);
    assertThat(strategy.getApplicableLoans(Collections.singletonList(ld))).contains(ld);
    // now add a filter and see no loans applicable
    final MarketplaceFilter f = mock(MarketplaceFilter.class);
    when(f.test(eq(new Wrapper(loan)))).thenReturn(true);
    final ParsedStrategy strategy2 = new ParsedStrategy(portfolio, Collections.singleton(f));
    assertThat(strategy2.getApplicableLoans(Collections.singletonList(ld))).isEmpty();
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) MarketplaceFilter(com.github.robozonky.strategy.natural.conditions.MarketplaceFilter) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Test(org.junit.jupiter.api.Test)

Example 5 with MarketplaceFilter

use of com.github.robozonky.strategy.natural.conditions.MarketplaceFilter in project robozonky by RoboZonky.

the class FilterSupplier method supplyFilters.

private static Collection<MarketplaceFilter> supplyFilters(final Collection<MarketplaceFilter> filters, final long monthsBeforeExit) {
    if (monthsBeforeExit > -1) {
        // ignore marketplace items that go over the exit date
        // fix extreme exit dates
        final long filteredTerms = Math.min(monthsBeforeExit + 1, 84);
        final MarketplaceFilterCondition c = new LoanTermCondition(filteredTerms);
        final MarketplaceFilter f = MarketplaceFilter.of(c);
        final Collection<MarketplaceFilter> result = new ArrayList<>(filters.size());
        result.add(f);
        result.addAll(filters);
        return Collections.unmodifiableCollection(result);
    } else {
        return Collections.unmodifiableCollection(filters);
    }
}
Also used : LoanTermCondition(com.github.robozonky.strategy.natural.conditions.LoanTermCondition) MarketplaceFilter(com.github.robozonky.strategy.natural.conditions.MarketplaceFilter) ArrayList(java.util.ArrayList) MarketplaceFilterCondition(com.github.robozonky.strategy.natural.conditions.MarketplaceFilterCondition)

Aggregations

MarketplaceFilter (com.github.robozonky.strategy.natural.conditions.MarketplaceFilter)8 Test (org.junit.jupiter.api.Test)5 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)4 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)4 Restrictions (com.github.robozonky.api.remote.entities.Restrictions)3 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)2 MarketplaceLoan (com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan)2 InvestmentStrategy (com.github.robozonky.api.strategies.InvestmentStrategy)2 PurchaseStrategy (com.github.robozonky.api.strategies.PurchaseStrategy)2 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)2 SellStrategy (com.github.robozonky.api.strategies.SellStrategy)2 LoanRatingEnumeratedCondition (com.github.robozonky.strategy.natural.conditions.LoanRatingEnumeratedCondition)2 LoanTermCondition (com.github.robozonky.strategy.natural.conditions.LoanTermCondition)2 MarketplaceFilterCondition (com.github.robozonky.strategy.natural.conditions.MarketplaceFilterCondition)2 Participation (com.github.robozonky.api.remote.entities.Participation)1 Rating (com.github.robozonky.api.remote.enums.Rating)1 ParticipationDescriptor (com.github.robozonky.api.strategies.ParticipationDescriptor)1 RecommendedInvestment (com.github.robozonky.api.strategies.RecommendedInvestment)1 RecommendedParticipation (com.github.robozonky.api.strategies.RecommendedParticipation)1 StrategyService (com.github.robozonky.api.strategies.StrategyService)1