use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class SecurityPerformanceTaxRefundTestCase method assertThatTTWROROfClassificationWithSecurityIsIdentical.
private void assertThatTTWROROfClassificationWithSecurityIsIdentical(Client client, ReportingPeriod period, double ttwror) {
// performance of the category of the taxonomy must be identical
Classification classification = client.getTaxonomy("32ac1de9-b9a7-480a-b464-36abf7984e0a").getClassificationById("a41d1836-9f8e-493c-9304-7434d9bbaa05");
List<Exception> warnings = new ArrayList<Exception>();
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex classificationPerformance = PerformanceIndex.forClassification(client, converter, classification, period, warnings);
assertThat(warnings, empty());
assertThat(classificationPerformance.getFinalAccumulatedPercentage(), is(ttwror));
}
use of name.abuchen.portfolio.TestCurrencyConverter 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.TestCurrencyConverter 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.TestCurrencyConverter in project portfolio by buchen.
the class SecurityTestCase method testSecurityPerformanceWithMissingHistoricalQuotes.
/**
* Issue: If historical quotes start only after the purchase (or delivery)
* of a security, the security is valued at 0 (no quote available) and the
* performance would go crazy to -100% (as reported in the forum). This
* scenario makes sure that earliest available historical quote is used.
*/
@Test
public void testSecurityPerformanceWithMissingHistoricalQuotes() throws IOException {
Client client = ClientFactory.load(SecurityTestCase.class.getResourceAsStream("security_performance_with_missing_historical_quotes.xml"));
Security security = client.getSecurities().get(0);
PortfolioTransaction delivery = client.getPortfolios().get(0).getTransactions().get(0);
assertThat("delivery transaction must be before earliest historical quote", delivery.getDateTime().toLocalDate(), lessThan(security.getPrices().get(0).getDate()));
ReportingPeriod period = new ReportingPeriod.FromXtoY(LocalDate.parse("2013-12-04"), LocalDate.parse("2014-12-04"));
TestCurrencyConverter converter = new TestCurrencyConverter();
SecurityPerformanceSnapshot snapshot = SecurityPerformanceSnapshot.create(client, converter, period);
SecurityPerformanceRecord record = snapshot.getRecords().get(0);
assertThat(record.getSecurity().getName(), is("Basf SE"));
assertThat(record.getTrueTimeWeightedRateOfReturn(), closeTo(-0.0594, 0.0001));
assertThat(record.getIrr(), closeTo(-0.0643, 0.0001));
// actually, in this simple scenario (no cash transfers involved), the
// ttwror is easy to calculate:
double endvalue = delivery.getShares() * security.getSecurityPrice(LocalDate.parse("2014-12-04")).getValue() / Values.Share.divider() / Values.Quote.dividerToMoney();
assertThat(record.getTrueTimeWeightedRateOfReturn(), closeTo((endvalue / delivery.getAmount()) - 1, 0.0001));
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class ClassificationIndexTest method testThatPartialAssignmentIsNOTIdenticalToClientPerformance.
@Test
public void testThatPartialAssignmentIsNOTIdenticalToClientPerformance() {
Client client = createClient(Classification.ONE_HUNDRED_PERCENT);
Classification classification = client.getTaxonomies().get(0).getClassificationById("one");
// remove account assignment
classification.getAssignments().remove(1);
List<Exception> warnings = new ArrayList<Exception>();
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex iClient = PerformanceIndex.forClient(client, converter, period, warnings);
PerformanceIndex iClassification = PerformanceIndex.forClassification(client, converter, classification, period, warnings);
assertThat(warnings.isEmpty(), is(true));
assertThat(iClient.getAccumulatedPercentage(), is(not(iClassification.getAccumulatedPercentage())));
assertThat(iClient.getDeltaPercentage(), is(not(iClassification.getDeltaPercentage())));
assertThat(iClient.getTotals(), is(not(iClassification.getTotals())));
assertThat(iClient.getTransferals(), is(not(iClassification.getTransferals())));
}
Aggregations