use of name.abuchen.portfolio.money.CurrencyConverter in project portfolio by buchen.
the class AccountPerformanceTaxRefundTestCase method testAccountPerformanceTaxRefund.
/**
* Feature: when calculating the performance of an account, do include taxes
* and tax refunds but only those that are not paid for a security.
*/
@Test
public void testAccountPerformanceTaxRefund() throws IOException {
Client client = ClientFactory.load(SecurityTestCase.class.getResourceAsStream("account_performance_tax_refund.xml"));
Account account = client.getAccounts().get(0);
ReportingPeriod period = new ReportingPeriod.FromXtoY(LocalDate.parse("2013-12-06"), LocalDate.parse("2014-12-06"));
AccountTransaction deposit = account.getTransactions().get(0);
// no changes in holdings, ttwror must be:
double startValue = deposit.getAmount();
double endValue = account.getCurrentAmount(LocalDateTime.of(2016, 1, 1, 10, 00));
double ttwror = (endValue / startValue) - 1;
List<Exception> warnings = new ArrayList<>();
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex accountPerformance = PerformanceIndex.forAccount(client, converter, account, period, warnings);
assertThat(warnings, empty());
double calculatedTtwror = accountPerformance.getFinalAccumulatedPercentage();
assertThat(calculatedTtwror, closeTo(ttwror, 0.0001));
// if the tax_refund is for a security, it must not be included in the
// performance of the account
AccountTransaction taxRefund = account.getTransactions().get(1);
assertThat(taxRefund.getType(), is(AccountTransaction.Type.TAX_REFUND));
taxRefund.setSecurity(new Security());
accountPerformance = PerformanceIndex.forAccount(client, converter, account, period, warnings);
assertThat(warnings, empty());
assertThat(accountPerformance.getFinalAccumulatedPercentage(), lessThan(calculatedTtwror));
}
use of name.abuchen.portfolio.money.CurrencyConverter 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.money.CurrencyConverter 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.money.CurrencyConverter 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())));
}
use of name.abuchen.portfolio.money.CurrencyConverter in project portfolio by buchen.
the class ClientIndexTest method testThatPerformanceOfInvestmentAndIndexIsIdendicalWhenInForeignCurrency.
@Test
public void testThatPerformanceOfInvestmentAndIndexIsIdendicalWhenInForeignCurrency() {
LocalDate startDate = LocalDate.of(2015, 1, 1);
LocalDate endDate = LocalDate.of(2015, 8, 1);
long startPrice = Values.Quote.factorize(100);
Client client = new Client();
Security security = //
new SecurityBuilder("USD").generatePrices(startPrice, startDate, //
endDate).addTo(client);
Account account = new AccountBuilder().addTo(client);
//
new PortfolioBuilder(account).inbound_delivery(security, LocalDateTime.of(2014, 01, 01, 0, 0), Values.Share.factorize(100), //
100).addTo(client);
ReportingPeriod.FromXtoY period = new ReportingPeriod.FromXtoY(startDate, endDate);
List<Exception> warnings = new ArrayList<Exception>();
CurrencyConverter converter = new TestCurrencyConverter().with(CurrencyUnit.EUR);
PerformanceIndex index = PerformanceIndex.forClient(client, converter, period, warnings);
assertTrue(warnings.isEmpty());
PerformanceIndex benchmark = PerformanceIndex.forSecurity(index, security);
assertTrue(warnings.isEmpty());
assertThat(benchmark.getFinalAccumulatedPercentage(), IsCloseTo.closeTo(index.getFinalAccumulatedPercentage(), PRECISION));
PerformanceIndex investment = PerformanceIndex.forInvestment(client, converter, security, period, warnings);
assertTrue(warnings.isEmpty());
assertThat(investment.getFinalAccumulatedPercentage(), is(index.getFinalAccumulatedPercentage()));
}
Aggregations