use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.
the class SecurityPerformanceTaxRefundTestCase method assertPerformanceOfClient.
private PerformanceIndex assertPerformanceOfClient(Client client, ReportingPeriod period, double ttwror) {
// the performance of the client must include taxes though -> worse
List<Exception> warnings = new ArrayList<Exception>();
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex clientIndex = PerformanceIndex.forClient(client, converter, period, warnings);
assertThat(warnings, empty());
assertThat(clientIndex.getFinalAccumulatedPercentage(), lessThan(ttwror));
// the performance of portfolio + account must be identical to the
// performance of the client
PerformanceIndex portfolioPlusPerformance = PerformanceIndex.forPortfolioPlusAccount(client, converter, client.getPortfolios().get(0), period, warnings);
assertThat(warnings, empty());
assertThat(portfolioPlusPerformance.getFinalAccumulatedPercentage(), is(clientIndex.getFinalAccumulatedPercentage()));
return clientIndex;
}
use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.
the class SecurityPerformanceTaxRefundTestCase method testSecurityPerformanceTaxRefund.
/**
* Feature: when calculating the performance of a security, do not include
* taxes and tax refunds. Include taxes and tax refunds only when
* calculating a performance of a porfolio and/or client.
*/
@Test
public void testSecurityPerformanceTaxRefund() throws IOException {
Client client = ClientFactory.load(SecurityTestCase.class.getResourceAsStream("security_performance_tax_refund.xml"));
Security security = client.getSecurities().get(0);
Portfolio portfolio = client.getPortfolios().get(0);
PortfolioTransaction delivery = portfolio.getTransactions().get(0);
ReportingPeriod period = new ReportingPeriod.FromXtoY(LocalDate.parse("2013-12-06"), LocalDate.parse("2014-12-06"));
TestCurrencyConverter converter = new TestCurrencyConverter();
SecurityPerformanceSnapshot snapshot = SecurityPerformanceSnapshot.create(client, converter, period);
SecurityPerformanceRecord record = snapshot.getRecords().get(0);
assertThat(record.getSecurity().getName(), is("Basf SE"));
// no changes in holdings, ttwror must (without taxes and tax refunds):
double startValue = delivery.getAmount() - delivery.getUnitSum(Unit.Type.TAX).getAmount();
double endValue = delivery.getShares() * security.getSecurityPrice(LocalDate.parse("2014-12-06")).getValue() / Values.Share.divider() / Values.Quote.dividerToMoney();
double ttwror = (endValue / startValue) - 1;
assertThat(record.getTrueTimeWeightedRateOfReturn(), closeTo(ttwror, 0.0001));
// accrued taxes must be 5 (paid 10 on delivery + 5 tax refund):
assertThat(record.getTaxes(), is(Money.of(CurrencyUnit.EUR, 5_00L)));
// accrued fees must be 10 (paid 10 on delivery)
assertThat(record.getFees(), is(Money.of(CurrencyUnit.EUR, 10_00L)));
// make sure that tax refund is included in transactions
assertThat(record.getTransactions(), hasItem(isA(AccountTransaction.class)));
// ttwror of classification must be identical to ttwror of security
assertThatTTWROROfClassificationWithSecurityIsIdentical(client, period, ttwror);
// check client performance + performance of portfolio + account
PerformanceIndex clientIndex = assertPerformanceOfClient(client, period, ttwror);
// the performance of the portfolio (w/o account) includes taxes
// in this sample file, the valuation of the security drops by 971
// euros. However, the client has total valuation of 8406 while the
// portfolio has valuation of only 8401 as it does not include the tax
// refund. Therefore the performances of the porfolio is worse than that
// of the client.
assertThatTTWROROfPortfolioIsLessThan(client, clientIndex, ttwror);
// the irr must not include taxes as well (compared with Excel):
assertThat(record.getIrr(), closeTo(-0.030745789, 0.0001));
// ensure the performance of the account is zero
List<Exception> warnings = new ArrayList<Exception>();
PerformanceIndex accountIndex = PerformanceIndex.forAccount(client, converter, client.getAccounts().get(0), period, warnings);
assertThat(warnings, empty());
assertThat(accountIndex.getFinalAccumulatedPercentage(), is(0d));
}
use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.
the class SecurityTaxAndFeeAccountTransactionsTestCase method testAdidas.
@Test
public void testAdidas() {
SecurityPerformanceSnapshot snapshot = SecurityPerformanceSnapshot.create(client, converter, interval);
SecurityPerformanceRecord record = snapshot.getRecords().stream().filter(r -> r.getSecurity().equals(adidas)).findAny().orElseThrow(IllegalArgumentException::new);
assertThat(record.getTransactions().size(), is(6));
// fees and taxes from the buy transaction + separate transactions
assertThat(record.getFees(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(10d + 10d - 5d))));
assertThat(record.getTaxes(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(10d + 25d - 5d))));
// delta is end value - starting value including all fees and taxes
assertThat(record.getDelta(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1456.5 - 1533 - 10 + 5 - 25 + 5))));
// IRR as calculated in Excel
// @formatter:off
// date w/ tax w/o tax
// 02.01.17 -1533 -1523
// 09.01.17 -10 -10
// 10.01.17 5 5
// 11.01.17 -25 0
// 12.01.17 5 0
// 31.01.17 1456,5 1456,5
// XIRR -0,573350433 -0,453151944
// @formatter:on
assertThat(record.getIrr(), closeTo(-0.453151944d, 1.0e-8));
// check filtering - ClientSecurityFilter
Client filteredClient = new ClientSecurityFilter(adidas).filter(client);
checkFilteredClientAdidas(filteredClient, 1.0);
// check filtering - ClientClassificationFilter
Taxonomy case1 = client.getTaxonomies().stream().filter(t -> "case_full_classification_adidas".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
Classification classification = case1.getAllClassifications().stream().filter(c -> "category_security".equals(c.getName())).findAny().orElseThrow(IllegalArgumentException::new);
filteredClient = new ClientClassificationFilter(classification).filter(client);
checkFilteredClientAdidas(filteredClient, 1.0);
// TTWROR must be identical to one calculated via ClientSecurityFilter
// (implicitly used by the SecurityPeformanceSnapshot)
PerformanceIndex index = PerformanceIndex.forClassification(client, converter, classification, interval, new ArrayList<>());
assertThat(index.getFinalAccumulatedPercentage(), is(record.getTrueTimeWeightedRateOfReturn()));
// a partial assignment of the security should be identical to the full
// assignment - only the weight differs
Taxonomy case2 = client.getTaxonomies().stream().filter(t -> "case_partial_classification_adidas".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
classification = case2.getAllClassifications().stream().filter(c -> "category_security".equals(c.getName())).findAny().orElseThrow(IllegalArgumentException::new);
filteredClient = new ClientClassificationFilter(classification).filter(client);
checkFilteredClientAdidas(filteredClient, 0.5);
}
use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.
the class VolatilityTestCase method testVolatilityIfSecurityIsSoldAndLaterBoughtDuringReportingPeriod.
@Test
public void testVolatilityIfSecurityIsSoldAndLaterBoughtDuringReportingPeriod() throws IOException {
ReportingPeriod report = new ReportingPeriod.FromXtoY(LocalDate.parse("2014-01-31"), LocalDate.parse("2015-02-20"));
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);
assertThat(warnings, empty());
// excel
assertThat(index.getVolatility().getStandardDeviation(), closeTo(0.202942041440, 0.1e-10));
assertThat(index.getDates()[index.getDates().length - 1], is(LocalDate.parse("2015-02-20")));
}
use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.
the class VolatilityTestCase method testVolatilityIfBenchmarkHasNoQuotes.
@Test
public void testVolatilityIfBenchmarkHasNoQuotes() throws IOException {
ReportingPeriod report = new ReportingPeriod.FromXtoY(LocalDate.parse("2014-01-31"), LocalDate.parse("2015-01-31"));
List<Exception> warnings = new ArrayList<>();
PerformanceIndex index = PerformanceIndex.forClient(client, converter, report, warnings);
Security sap = client.getSecurities().stream().filter(s -> "Sap AG".equals(s.getName())).findAny().get();
PerformanceIndex sapIndex = PerformanceIndex.forSecurity(index, sap);
assertThat(warnings, empty());
// quotes only until December 31st
assertThat(sapIndex.getDates()[sapIndex.getDates().length - 1], is(LocalDate.parse("2014-12-31")));
// excel
assertThat(sapIndex.getVolatility().getStandardDeviation(), closeTo(0.193062749491, 0.1e-10));
}
Aggregations