Search in sources :

Example 6 with PerformanceIndex

use of name.abuchen.portfolio.snapshot.PerformanceIndex 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)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) BeforeClass(org.junit.BeforeClass) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) LocalDateTime(java.time.LocalDateTime) Classification(name.abuchen.portfolio.model.Classification) ArrayList(java.util.ArrayList) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Assert.assertThat(org.junit.Assert.assertThat) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) ClientFactory(name.abuchen.portfolio.model.ClientFactory) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Taxonomy(name.abuchen.portfolio.model.Taxonomy) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) Collectors(java.util.stream.Collectors) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) List(java.util.List) LocalDate(java.time.LocalDate) Taxonomy(name.abuchen.portfolio.model.Taxonomy) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) Classification(name.abuchen.portfolio.model.Classification) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 7 with PerformanceIndex

use of name.abuchen.portfolio.snapshot.PerformanceIndex 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)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) BeforeClass(org.junit.BeforeClass) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) LocalDateTime(java.time.LocalDateTime) Classification(name.abuchen.portfolio.model.Classification) ArrayList(java.util.ArrayList) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Assert.assertThat(org.junit.Assert.assertThat) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) ClientFactory(name.abuchen.portfolio.model.ClientFactory) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Taxonomy(name.abuchen.portfolio.model.Taxonomy) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) Collectors(java.util.stream.Collectors) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) List(java.util.List) LocalDate(java.time.LocalDate) Taxonomy(name.abuchen.portfolio.model.Taxonomy) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) Classification(name.abuchen.portfolio.model.Classification) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 8 with PerformanceIndex

use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.

the class SecurityPerformanceTaxRefundTestCase method testSecurityPerformanceTaxRefundAllSold.

/**
 * Feature: Same as {@link #testSecurityPerformanceTaxRefunds} except that
 * now the security has been sold. Taxes paid when selling the security must
 * be ignored.
 */
@Test
public void testSecurityPerformanceTaxRefundAllSold() throws IOException {
    Client client = ClientFactory.load(SecurityTestCase.class.getResourceAsStream("security_performance_tax_refund_all_sold.xml"));
    Portfolio portfolio = client.getPortfolios().get(0);
    PortfolioTransaction delivery = portfolio.getTransactions().get(0);
    PortfolioTransaction sell = portfolio.getTransactions().get(1);
    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"));
    assertThat(record.getSharesHeld(), is(0L));
    // no changes in holdings, ttwror must (without taxes and tax refunds):
    double startValue = delivery.getAmount() - delivery.getUnitSum(Unit.Type.TAX).getAmount();
    double endValue = sell.getAmount() + sell.getUnitSum(Unit.Type.TAX).getAmount();
    double ttwror = (endValue / startValue) - 1;
    assertThat(record.getTrueTimeWeightedRateOfReturn(), closeTo(ttwror, 0.0001));
    // accrued taxes must be 0 (paid 10 on delivery + 5 tax refund + 10
    // taxes on sell):
    assertThat(record.getTaxes(), is(Money.of(CurrencyUnit.EUR, 15_00L)));
    // accrued fees must be 20 (paid 10 on delivery + 10 on sell)
    assertThat(record.getFees(), is(Money.of(CurrencyUnit.EUR, 20_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
    assertThatTTWROROfPortfolioIsLessThan(client, clientIndex, ttwror);
    // the irr must not include taxes as well (compared with Excel):
    assertThat(record.getIrr(), closeTo(-0.032248297, 0.0001));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Portfolio(name.abuchen.portfolio.model.Portfolio) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Client(name.abuchen.portfolio.model.Client) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) Test(org.junit.Test)

Example 9 with PerformanceIndex

use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.

the class SecurityPerformanceTaxRefundTestCase method assertThatTTWROROfPortfolioIsLessThan.

private void assertThatTTWROROfPortfolioIsLessThan(Client client, PerformanceIndex clientIndex, double ttwror) {
    List<Exception> warnings = new ArrayList<Exception>();
    PerformanceIndex portfolioPerformance = PerformanceIndex.forPortfolio(client, clientIndex.getCurrencyConverter(), client.getPortfolios().get(0), clientIndex.getReportInterval(), warnings);
    assertThat(warnings, empty());
    assertThat(portfolioPerformance.getFinalAccumulatedPercentage(), is(both(lessThan(clientIndex.getFinalAccumulatedPercentage())).and(lessThan(ttwror))));
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex)

Example 10 with PerformanceIndex

use of name.abuchen.portfolio.snapshot.PerformanceIndex 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));
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Classification(name.abuchen.portfolio.model.Classification) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Aggregations

PerformanceIndex (name.abuchen.portfolio.snapshot.PerformanceIndex)33 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)23 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)22 Test (org.junit.Test)22 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)19 Security (name.abuchen.portfolio.model.Security)18 Client (name.abuchen.portfolio.model.Client)17 Classification (name.abuchen.portfolio.model.Classification)15 LocalDate (java.time.LocalDate)14 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)14 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)14 Taxonomy (name.abuchen.portfolio.model.Taxonomy)14 LocalDateTime (java.time.LocalDateTime)13 List (java.util.List)13 Collectors (java.util.stream.Collectors)13 ClientFactory (name.abuchen.portfolio.model.ClientFactory)13 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)13 Money (name.abuchen.portfolio.money.Money)13 Values (name.abuchen.portfolio.money.Values)13