use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.
the class ClassificationTestCase method testCase12_ForexAccountOut100_AccountIn50.
@Test
public void testCase12_ForexAccountOut100_AccountIn50() {
Taxonomy case12 = client.getTaxonomies().stream().filter(t -> "case_12".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
// check performance of 'subcategory'
Classification ccategory = case12.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 -> "Account Forex".equals(a.getName())).flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
// check cash transfers
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-17T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.TRANSFER_OUT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(50)))))));
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-17T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(50)))))));
txa = categoryClient.getAccounts().stream().filter(a -> "Konto 3".equals(a.getName())).flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-17T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.TRANSFER_IN)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(78.19 * 0.5d)))))));
// create index
List<Exception> warnings = new ArrayList<>();
PerformanceIndex index_subcategory = PerformanceIndex.forClassification(client, converter, ccategory, interval, warnings);
assertThat(warnings.isEmpty(), is(true));
// 343.42 EUR (Konto 3 EUR)
// 423.52 USD / 1.2141 (exchange rate in TestCurrencyConverter)
assertThat(index_subcategory.getTotals()[index_subcategory.getTotals().length - 1], is(//
Values.Amount.factorize(343.42) + Values.Amount.factorize(423.52 / 1.2141)));
}
use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.
the class VolatilityTestCase method testVolatilityOfSharesHeldIsIdenticalToExcel.
@Test
public void testVolatilityOfSharesHeldIsIdenticalToExcel() throws IOException {
ReportingPeriod report = new ReportingPeriod.FromXtoY(LocalDate.parse("2014-01-31"), LocalDate.parse("2014-07-31"));
List<Exception> warnings = new ArrayList<>();
PerformanceIndex index = PerformanceIndex.forClient(client, converter, report, warnings);
assertThat(warnings, empty());
// excel
assertThat(index.getVolatility().getStandardDeviation(), closeTo(0.141568791460, 0.1e-10));
}
use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.
the class VolatilityTestCase method testVolatilityIfSecurityIsSoldDuringReportingPeriod.
@Test
public void testVolatilityIfSecurityIsSoldDuringReportingPeriod() throws IOException {
ReportingPeriod report = new ReportingPeriod.FromXtoY(LocalDate.parse("2014-01-31"), LocalDate.parse("2015-01-31"));
List<Exception> warnings = new ArrayList<>();
Security basf = client.getSecurities().stream().filter(s -> "Basf SE".equals(s.getName())).findAny().get();
PerformanceIndex index = PerformanceIndex.forInvestment(client, converter, basf, report, warnings);
PerformanceIndex clientIndex = PerformanceIndex.forClient(client, converter, report, warnings);
assertThat(warnings, empty());
// excel
assertThat(index.getVolatility().getStandardDeviation(), closeTo(0.200573810778, 0.1e-10));
// excel
assertThat(clientIndex.getVolatility().getStandardDeviation(), closeTo(0.200599730118, 0.1e-10));
assertThat(index.getDates()[index.getDates().length - 1], is(LocalDate.parse("2015-01-31")));
}
use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.
the class SecurityPerformanceRecord method calculateTTWROR.
private void calculateTTWROR(Client client, CurrencyConverter converter, ReportingPeriod period) {
PerformanceIndex index = PerformanceIndex.forInvestment(client, converter, security, period, new ArrayList<Exception>());
this.twror = index.getFinalAccumulatedPercentage();
this.drawdown = index.getDrawdown();
this.volatility = index.getVolatility();
}
use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.
the class PerformanceCalculationWidget method update.
@Override
public void update() {
title.setText(getWidget().getLabel());
PerformanceIndex index = getDashboardData().calculate(get(DataSeriesConfig.class).getDataSeries(), get(ReportingPeriodConfig.class).getReportingPeriod());
ClientPerformanceSnapshot snapshot = index.getClientPerformanceSnapshot();
int ii = 0;
for (ClientPerformanceSnapshot.Category category : snapshot.getCategories()) {
signs[ii].setText(category.getSign());
labels[ii].setText(category.getLabel());
values[ii].setText(Values.Money.format(category.getValuation(), getClient().getBaseCurrency()));
if (++ii >= labels.length)
break;
}
container.layout();
}
Aggregations