use of com.github.robozonky.api.remote.enums.Rating in project robozonky by RoboZonky.
the class InvestmentSizeRecommender method getInvestmentBounds.
private int[] getInvestmentBounds(final ParsedStrategy strategy, final Loan loan) {
final Rating rating = loan.getRating();
final int absoluteMinimum = Math.max(strategy.getMinimumInvestmentSizeInCzk(rating), Defaults.MINIMUM_INVESTMENT_IN_CZK);
final int minimumRecommendation = roundToNearestIncrement(absoluteMinimum);
final int maximumUserRecommendation = roundToNearestIncrement(strategy.getMaximumInvestmentSizeInCzk(rating));
if (maximumUserRecommendation > maximumInvestmentAmount) {
LOGGER.info("Maximum investment amount reduced to {} by Zonky.", maximumInvestmentAmount);
}
final int maximumRecommendation = Math.min(maximumUserRecommendation, maximumInvestmentAmount);
final int loanId = loan.getId();
LOGGER.trace("Strategy gives investment range for loan #{} of <{}; {}> CZK.", loanId, minimumRecommendation, maximumRecommendation);
final int minimumInvestmentByShare = getPercentage(loan.getAmount(), strategy.getMinimumInvestmentShareInPercent());
final int minimumInvestment = Math.max(minimumInvestmentByShare, strategy.getMinimumInvestmentSizeInCzk(loan.getRating()));
final int maximumInvestmentByShare = getPercentage(loan.getAmount(), strategy.getMaximumInvestmentShareInPercent());
final int maximumInvestment = Math.min(maximumInvestmentByShare, strategy.getMaximumInvestmentSizeInCzk(loan.getRating()));
// minimums are guaranteed to be <= maximums due to the contract of strategy implementation
return new int[] { minimumInvestment, maximumInvestment };
}
use of com.github.robozonky.api.remote.enums.Rating in project robozonky by RoboZonky.
the class NaturalLanguagePurchaseStrategy method getRecommendationBoundaries.
private int[] getRecommendationBoundaries(final Participation participation) {
final Rating rating = participation.getRating();
final int minimumInvestment = strategy.getMinimumInvestmentSizeInCzk(rating);
final int maximumInvestment = strategy.getMaximumInvestmentSizeInCzk(rating);
return new int[] { minimumInvestment, maximumInvestment };
}
use of com.github.robozonky.api.remote.enums.Rating in project robozonky by RoboZonky.
the class PortfolioOverviewTest method emptyPortfolio.
@Test
void emptyPortfolio() {
final int balance = 5000;
final PortfolioOverview o = PortfolioOverview.calculate(BigDecimal.valueOf(balance), Stream::empty);
assertSoftly(softly -> {
for (final Rating r : Rating.values()) {
softly.assertThat(o.getShareOnInvestment(r)).isEqualTo(BigDecimal.ZERO);
softly.assertThat(o.getAtRiskShareOnInvestment(r)).isEqualTo(BigDecimal.ZERO);
}
softly.assertThat(o.getCzkAvailable()).isEqualTo(balance);
softly.assertThat(o.getCzkInvested()).isEqualTo(0);
});
}
use of com.github.robozonky.api.remote.enums.Rating in project robozonky by RoboZonky.
the class SimpleStrategyService method parseOrThrow.
private static InvestmentStrategy parseOrThrow(final String strategy) {
final ImmutableConfiguration config = ImmutableConfiguration.from(strategy);
// set default values
final DefaultValues d = new DefaultValues(DefaultPortfolio.EMPTY);
d.setMinimumBalance(SimpleStrategyService.getMinimumBalance(config));
d.setTargetPortfolioSize(SimpleStrategyService.getTargetPortfolioSize(config));
d.setInvestmentShare(new DefaultInvestmentShare(SimpleStrategyService.getInvestmentShare(config)));
final LoanRatingEnumeratedCondition c = new LoanRatingEnumeratedCondition();
Stream.of(Rating.values()).filter(r -> StrategyFileProperty.REQUIRE_CONFIRMATION.getValue(r, config::getBoolean)).forEach(c::add);
d.setConfirmationCondition(c);
// assemble strategy
final Map<Rating, InvestmentSize> investmentSizes = Stream.of(Rating.values()).collect(Collectors.toMap(Function.identity(), r -> {
final int min = StrategyFileProperty.MINIMUM_LOAN_AMOUNT.getValue(r, config::getInt);
final int max = StrategyFileProperty.MAXIMUM_LOAN_AMOUNT.getValue(r, config::getInt);
return new InvestmentSize(min, max);
}));
final Collection<PortfolioShare> portfolio = Stream.of(Rating.values()).map(r -> {
final int min = SimpleStrategyService.getShare(config, StrategyFileProperty.TARGET_SHARE, r);
final int max = SimpleStrategyService.getShare(config, StrategyFileProperty.MAXIMUM_SHARE, r);
return new PortfolioShare(r, min, max);
}).collect(Collectors.toList());
// filter loans with less than minimum term
final Stream<Optional<MarketplaceFilter>> s1 = Stream.of(Rating.values()).map(r -> {
final int min = StrategyFileProperty.MINIMUM_TERM.getValue(r, config::getInt);
if (min < 2) {
// there will be no loan with term smaller than 1
return Optional.empty();
}
final MarketplaceFilterCondition f = new LoanTermCondition(0, min - 1);
return Optional.of(getRatingFilter(r, f));
});
// filter loans with more than maximum term
final Stream<Optional<MarketplaceFilter>> s2 = Stream.of(Rating.values()).map(r -> {
final int max = StrategyFileProperty.MAXIMUM_TERM.getValue(r, config::getInt);
if (max < 1) {
return Optional.empty();
}
final MarketplaceFilterCondition f = new LoanTermCondition(max + 1);
return Optional.of(getRatingFilter(r, f));
});
// filter loans with ask for less than minimum
final Stream<Optional<MarketplaceFilter>> s3 = Stream.of(Rating.values()).map(r -> {
final int min = StrategyFileProperty.MINIMUM_ASK.getValue(r, config::getInt);
if (min < 2) {
// amount smaller than 1 is 0, no need to have that filter
return Optional.empty();
}
final MarketplaceFilterCondition f = new LoanAmountCondition(0, min - 1);
return Optional.of(getRatingFilter(r, f));
});
// filter loans with ask more than maximum
final Stream<Optional<MarketplaceFilter>> s4 = Stream.of(Rating.values()).map(r -> {
final int max = StrategyFileProperty.MAXIMUM_ASK.getValue(r, config::getInt);
if (max < 1) {
return Optional.empty();
}
final MarketplaceFilterCondition f = new LoanAmountCondition(max + 1);
return Optional.of(getRatingFilter(r, f));
});
// put all filters together
final Collection<MarketplaceFilter> filters = Stream.of(s1, s2, s3, s4).flatMap(Function.identity()).flatMap(s -> s.map(Stream::of).orElse(Stream.empty())).collect(Collectors.toList());
// and create the strategy
final ParsedStrategy p = new ParsedStrategy(d, portfolio, investmentSizes, new FilterSupplier(d, filters));
LOGGER.debug("Converted strategy: {}.", p);
final InvestmentStrategy result = new NaturalLanguageInvestmentStrategy(p);
return new SimpleStrategyService.ExclusivelyPrimaryMarketplaceInvestmentStrategy(result);
}
use of com.github.robozonky.api.remote.enums.Rating in project robozonky by RoboZonky.
the class UtilTest method assertOrder.
private static void assertOrder(final List<Rating> result, final Rating... ratingsOrderedDown) {
final Rating first = result.get(0);
final Rating last = result.get(ratingsOrderedDown.length - 1);
assertSoftly(softly -> {
softly.assertThat(first).isGreaterThan(last);
softly.assertThat(first).isEqualTo(ratingsOrderedDown[0]);
softly.assertThat(last).isEqualTo(ratingsOrderedDown[ratingsOrderedDown.length - 1]);
});
}
Aggregations