use of com.github.robozonky.api.strategies.PortfolioOverview in project robozonky by RoboZonky.
the class Repayments method accept.
@Override
public void accept(final Portfolio portfolio, final Authenticated authenticated) {
final PortfolioOverview portfolioOverview = portfolio.calculateOverview();
final Collection<Integer> active = getActiveLastTime();
// detect and process loans that have been fully repaid, comparing to the last time active loans were checked
final Stream<Investment> repaid = portfolio.getActiveWithPaymentStatus(PaymentStatuses.of(PaymentStatus.PAID));
repaid.filter(i -> active.contains(i.getLoanId())).peek(i -> {
final Loan l = authenticated.call(zonky -> LoanCache.INSTANCE.getLoan(i, zonky));
final Event e = new LoanRepaidEvent(i, l, portfolioOverview);
Events.fire(e);
}).forEach(i -> active.remove(i.getLoanId()));
// add all active loans to date
portfolio.getActiveWithPaymentStatus(PaymentStatus.getActive()).forEach(i -> active.add(i.getLoanId()));
// store for future reference
setActive(active);
}
use of com.github.robozonky.api.strategies.PortfolioOverview in project robozonky by RoboZonky.
the class Session method invest.
public static Collection<Investment> invest(final Portfolio portfolio, final Investor investor, final Authenticated auth, final Collection<LoanDescriptor> loans, final RestrictedInvestmentStrategy strategy) {
final Session session = new Session(portfolio, loans, investor, auth);
final PortfolioOverview portfolioOverview = session.portfolioOverview;
final int balance = portfolioOverview.getCzkAvailable();
Events.fire(new ExecutionStartedEvent(loans, portfolioOverview));
if (balance >= Defaults.MINIMUM_INVESTMENT_IN_CZK && !session.getAvailable().isEmpty()) {
session.invest(strategy);
}
final Collection<Investment> result = session.getResult();
// make sure we get fresh portfolio reference here
Events.fire(new ExecutionCompletedEvent(result, session.portfolioOverview));
return Collections.unmodifiableCollection(result);
}
use of com.github.robozonky.api.strategies.PortfolioOverview 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.PortfolioOverview 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.PortfolioOverview 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();
}
Aggregations