Search in sources :

Example 6 with PortfolioOverview

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);
}
Also used : Collection(java.util.Collection) Set(java.util.Set) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Collectors(java.util.stream.Collectors) PaymentStatus(com.github.robozonky.api.remote.enums.PaymentStatus) Event(com.github.robozonky.api.notifications.Event) Stream(java.util.stream.Stream) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) LoanCache(com.github.robozonky.app.util.LoanCache) Events(com.github.robozonky.app.Events) Authenticated(com.github.robozonky.app.authentication.Authenticated) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) State(com.github.robozonky.internal.api.State) PaymentStatuses(com.github.robozonky.api.remote.enums.PaymentStatuses) Collections(java.util.Collections) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) Event(com.github.robozonky.api.notifications.Event) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment)

Example 7 with PortfolioOverview

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);
}
Also used : ExecutionCompletedEvent(com.github.robozonky.api.notifications.ExecutionCompletedEvent) ExecutionStartedEvent(com.github.robozonky.api.notifications.ExecutionStartedEvent) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment)

Example 8 with PortfolioOverview

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();
}
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 9 with PortfolioOverview

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

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

PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)26 Test (org.junit.jupiter.api.Test)18 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)11 Restrictions (com.github.robozonky.api.remote.entities.Restrictions)10 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)9 Collection (java.util.Collection)8 Collections (java.util.Collections)8 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)7 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)7 Defaults (com.github.robozonky.internal.api.Defaults)7 Assertions (org.assertj.core.api.Assertions)6 SoftAssertions (org.assertj.core.api.SoftAssertions)6 Mockito (org.mockito.Mockito)6 LoanRepaidEvent (com.github.robozonky.api.notifications.LoanRepaidEvent)5 PaymentStatus (com.github.robozonky.api.remote.enums.PaymentStatus)5 InvestmentStrategy (com.github.robozonky.api.strategies.InvestmentStrategy)5 PurchaseStrategy (com.github.robozonky.api.strategies.PurchaseStrategy)5 RecommendedParticipation (com.github.robozonky.api.strategies.RecommendedParticipation)5 Instant (java.time.Instant)5 LocalDate (java.time.LocalDate)5