use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.
the class ReturnsVolatilityChartView method setChartSeries.
private void setChartSeries() {
configurator.getSelectedDataSeries().forEach(series -> {
PerformanceIndex index = cache.lookup(series, getReportingPeriod());
Volatility volatility = index.getVolatility();
ILineSeries lineSeries = chart.addScatterSeries(new double[] { volatility.getStandardDeviation() }, new double[] { index.getFinalAccumulatedPercentage() }, series.getLabel());
Color color = resources.createColor(series.getColor());
lineSeries.setLineColor(color);
lineSeries.setSymbolColor(color);
lineSeries.enableArea(series.isShowArea());
lineSeries.setLineStyle(series.getLineStyle());
});
}
use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.
the class MaxDrawdownDurationWidget method update.
@Override
public void update() {
super.update();
PerformanceIndex index = getDashboardData().getDataSeriesCache().lookup(get(DataSeriesConfig.class).getDataSeries(), get(ReportingPeriodConfig.class).getReportingPeriod());
Drawdown drawdown = index.getDrawdown();
Interval maxDDDuration = drawdown.getMaxDrawdownDuration();
indicator.setText(MessageFormat.format(Messages.LabelXDays, maxDDDuration.getDays()));
boolean isUntilEndOfPeriod = maxDDDuration.getEnd().equals(index.getReportInterval().getEndDate());
String maxDDSupplement = isUntilEndOfPeriod ? Messages.TooltipMaxDrawdownDurationEndOfPeriod : Messages.TooltipMaxDrawdownDurationFromXtoY;
// recovery time
Interval recoveryTime = drawdown.getLongestRecoveryTime();
isUntilEndOfPeriod = recoveryTime.getEnd().equals(index.getReportInterval().getEndDate());
String recoveryTimeSupplement = isUntilEndOfPeriod ? Messages.TooltipMaxDrawdownDurationEndOfPeriod : Messages.TooltipMaxDrawdownDurationFromXtoY;
InfoToolTip.attach(indicator, // $NON-NLS-1$
Messages.TooltipMaxDrawdownDuration + "\n\n" + MessageFormat.format(maxDDSupplement, formatter.format(maxDDDuration.getStart()), formatter.format(maxDDDuration.getEnd())) + // $NON-NLS-1$
"\n\n" + MessageFormat.format(Messages.TooltipMaxDurationLowToHigh, recoveryTime.getDays()) + MessageFormat.format(recoveryTimeSupplement, formatter.format(recoveryTime.getStart()), formatter.format(recoveryTime.getEnd())));
}
use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.
the class DataSeriesCache method lookup.
public PerformanceIndex lookup(DataSeries series, ReportingPeriod reportingPeriod) {
// Every data series is cached separately except the for the client. The
// client data series are created out of the same PerformanceIndex
// instance, e.g. accumulated and delta performance.
// $NON-NLS-1$
String uuid = series.getType() == DataSeries.Type.CLIENT ? "$client$" : series.getUUID();
CacheKey key = new CacheKey(uuid, reportingPeriod);
// #computeIfAbsent leads to a ConcurrentMapModificdation b/c #calculate
// might call #lookup to calculcate other cache entries
PerformanceIndex result = cache.get(key);
if (result != null)
return result;
result = calculate(series, reportingPeriod);
cache.put(key, result);
return result;
}
use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.
the class ClientSecurityFilterTest method testThatAllSecuritiesHaveIdendicalPerformanceToClient.
@Test
public void testThatAllSecuritiesHaveIdendicalPerformanceToClient() {
Client filtered = new ClientSecurityFilter(securityEUR, securityUSD).filter(client);
assertThat(filtered.getAccounts(), hasSize(2));
assertThat(filtered.getPortfolios(), hasSize(1));
List<Exception> warnings = new ArrayList<>();
TestCurrencyConverter converter = new TestCurrencyConverter();
ReportingPeriod interval = new ReportingPeriod.FromXtoY(LocalDate.parse("2015-12-31"), LocalDate.parse("2017-01-31"));
PerformanceIndex all = PerformanceIndex.forClient(client, converter, interval, warnings);
assertThat(warnings, empty());
PerformanceIndex filteredAll = PerformanceIndex.forClient(filtered, converter, interval, warnings);
assertThat(warnings, empty());
assertThat(all.getFinalAccumulatedPercentage(), is(filteredAll.getFinalAccumulatedPercentage()));
assertThat(all.getDeltaPercentage(), is(filteredAll.getDeltaPercentage()));
}
use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.
the class ClassificationTestCase method testCase7_Account30Account30.
@Test
public void testCase7_Account30Account30() {
Taxonomy case1 = client.getTaxonomies().stream().filter(t -> "case_7".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
// check performance of 'subcategory'
Classification ccategory = case1.getAllClassifications().stream().filter(c -> "category".equals(c.getName())).findAny().orElseThrow(IllegalArgumentException::new);
Client categoryClient = new ClientClassificationFilter(ccategory).filter(client);
List<PortfolioTransaction> txp = categoryClient.getPortfolios().stream().flatMap(p -> p.getTransactions().stream()).collect(Collectors.toList());
assertThat(txp, hasSize(0));
List<AccountTransaction> txa = categoryClient.getAccounts().stream().filter(a -> "Konto 1".equals(a.getName())).flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-02T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2397.60 * 0.3)))))));
// check that transfer between two accounts is created
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-25T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.TRANSFER_IN)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100 * 0.3)))))));
txa = categoryClient.getAccounts().stream().filter(a -> "Konto 2".equals(a.getName())).flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-25T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.TRANSFER_OUT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100 * 0.3)))))));
// create index
List<Exception> warnings = new ArrayList<>();
PerformanceIndex index_subcategory = PerformanceIndex.forClassification(client, converter, ccategory, interval, warnings);
assertThat(warnings.isEmpty(), is(true));
assertThat(index_subcategory.getTotals()[index_subcategory.getTotals().length - 1], is(Values.Amount.factorize(534.91)));
}
Aggregations