use of name.abuchen.portfolio.model.Classification in project portfolio by buchen.
the class ClassificationTestCase method testCase9_Security100Account30_SecuritySold.
@Test
public void testCase9_Security100Account30_SecuritySold() {
Taxonomy case9 = client.getTaxonomies().stream().filter(t -> "case_9".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
// check performance of 'subcategory'
Classification ccategory = case9.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());
// check that inbound delivery is w/o taxes
assertThat(txp, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-01T00:00"))), //
hasProperty("type", is(PortfolioTransaction.Type.DELIVERY_INBOUND)), //
hasProperty("shares", is(Values.Share.factorize(33))), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(3813.58 - 20)))))));
assertThat(txp, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-10T00:00"))), //
hasProperty("type", is(PortfolioTransaction.Type.SELL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(688.36 * 0.3d)))))));
assertThat(txp, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-10T00:00"))), //
hasProperty("type", is(PortfolioTransaction.Type.DELIVERY_OUTBOUND)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize((688.36 + 10) - (688.36 * 0.3d))))))));
// check that shares of the split transaction add up to the expected
// value, e.g. the total value of the original transaction
assertThat(txp.stream().filter(t -> t.getDateTime().equals(LocalDateTime.parse("2012-01-10T00:00"))).mapToLong(PortfolioTransaction::getShares).sum(), is(Values.Share.factorize(74.8)));
List<AccountTransaction> txa = categoryClient.getAccounts().stream().flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-10T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.SELL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(688.36 * 0.3)))))));
// check that dividends are included + removal to reflect the 30%
// assignment of the account
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-10T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.DIVIDENDS)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(16.5)))))));
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-10T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(16.5 * 0.7)))))));
// tax refund w/ security
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-27T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.DEPOSIT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(10 * 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(4105.28)));
}
use of name.abuchen.portfolio.model.Classification in project portfolio by buchen.
the class ClassificationTestCase method testCase4_TwoAccountsEach100Percent.
@Test
public void testCase4_TwoAccountsEach100Percent() {
Taxonomy case1 = client.getTaxonomies().stream().filter(t -> "case_4".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().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)))))));
// 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)))))));
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)))))));
// check that taxes are not included:
// tax refund w/o security
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-26T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.DEPOSIT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(10)))))));
// tax refund w/ security
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-27T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.DEPOSIT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(10)))))));
// tax transaction
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-28T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(10)))))));
// 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(1783.02)));
}
use of name.abuchen.portfolio.model.Classification 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.model.Classification in project portfolio by buchen.
the class SecurityTaxAndFeeAccountTransactionsTestCase method checkTaxonomyWihtAccountOnlyAssignment.
@Test
public void checkTaxonomyWihtAccountOnlyAssignment() {
// if only the account is classified, the fees and taxes related to the
// security must be plain deposit and removal transactions
Taxonomy case5 = client.getTaxonomies().stream().filter(t -> "case_account_classification".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
Classification classification = case5.getAllClassifications().stream().filter(c -> "category_account".equals(c.getName())).findAny().orElseThrow(IllegalArgumentException::new);
Client filteredClient = new ClientClassificationFilter(classification).filter(client);
List<AccountTransaction> txa = filteredClient.getAccounts().stream().flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
// expect the 6 original transactions
assertThat(txa.size(), is(6));
// check for additional transactions
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2017-01-09T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(10)))))));
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2017-01-10T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.DEPOSIT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(5)))))));
}
use of name.abuchen.portfolio.model.Classification 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);
}
Aggregations