Search in sources :

Example 1 with PerformanceIndex

use of name.abuchen.portfolio.snapshot.PerformanceIndex 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));
}
Also used : Account(name.abuchen.portfolio.model.Account) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 2 with PerformanceIndex

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

the class ClassificationTestCase method testCase11_ForexSecurity100_ForexAccountTransfers.

@Test
public void testCase11_ForexSecurity100_ForexAccountTransfers() {
    Taxonomy case11 = client.getTaxonomies().stream().filter(t -> "case_11".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    // check performance of 'subcategory'
    Classification ccategory = case11.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, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-16T00:00"))), // 
    hasProperty("type", is(PortfolioTransaction.Type.BUY)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(476.48 * 0.7d)))))));
    assertThat(txp, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-16T00:00"))), // 
    hasProperty("type", is(PortfolioTransaction.Type.DELIVERY_INBOUND)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.USD, Values.Amount.factorize((476.48 - 10) - (476.48 * 0.7d))))))));
    // 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-16T00:00"))).mapToLong(PortfolioTransaction::getShares).sum(), is(Values.Share.factorize(1)));
    List<AccountTransaction> txa = categoryClient.getAccounts().stream().filter(a -> "Account Forex".equals(a.getName())).flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-16T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.BUY)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(476.48 * 0.7d)))))));
    // check cash transfers
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-17T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.TRANSFER_OUT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(100 * 0.7d)))))));
    txa = categoryClient.getAccounts().stream().filter(a -> "Konto 3".equals(a.getName())).flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-17T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.TRANSFER_IN)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(78.19 * 0.7d)))))));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-17T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.DEPOSIT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(78.19 * 0.3d)))))));
    // create index
    List<Exception> warnings = new ArrayList<>();
    PerformanceIndex index_subcategory = PerformanceIndex.forClassification(client, converter, ccategory, interval, warnings);
    assertThat(warnings.isEmpty(), is(true));
    // 686.84 EUR (Konto 3 EUR)
    // 296.46 USD * 1.2141 (exchange rate in TestCurrencyConverter)
    // 2 * Apple 456.4799 / 1.2141 (quote for Apple)
    assertThat(index_subcategory.getTotals()[index_subcategory.getTotals().length - 1], is(// 
    Values.Amount.factorize(686.84) + Values.Amount.factorize(296.46 / 1.2141) + Values.Amount.factorize(2 * 456.4799 / 1.2141)));
}
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 3 with PerformanceIndex

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

the class ClassificationTestCase method testCase2_AccountWith50PercentAssignment.

@Test
public void testCase2_AccountWith50PercentAssignment() {
    Taxonomy case1 = client.getTaxonomies().stream().filter(t -> "case_2".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    // check performance of 'subcategory'
    Classification subcategory = case1.getAllClassifications().stream().filter(c -> "subcategory".equals(c.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    Client subcategoryClient = new ClientClassificationFilter(subcategory).filter(client);
    List<PortfolioTransaction> txp = subcategoryClient.getPortfolios().stream().flatMap(p -> p.getTransactions().stream()).collect(Collectors.toList());
    // b/c the account is added only with 50% (but the security with 100%),
    // the purchase transaction is split into two
    assertThat(txp, hasSize(2));
    assertThat(txp, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-02T00:00"))), // 
    hasProperty("type", is(PortfolioTransaction.Type.BUY)), // 
    hasProperty("shares", is(Values.Share.factorize(23.5))), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2397.60 / 2d)))))));
    assertThat(txp, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-02T00:00"))), // 
    hasProperty("type", is(PortfolioTransaction.Type.DELIVERY_INBOUND)), // 
    hasProperty("shares", is(Values.Share.factorize(23.5))), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2397.60 / 2d)))))));
    List<AccountTransaction> txa = subcategoryClient.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.BUY)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2397.60 / 2d)))))));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-01T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1019.80 / 2d)))))));
    // check that dividend is included without taxes
    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(24.44)))))));
    // check correction for dividend payment (w/o taxes and only 50%)
    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(24.44 - 19.44 / 2)))))));
    // create index
    List<Exception> warnings = new ArrayList<>();
    PerformanceIndex index_subcategory = PerformanceIndex.forClassification(client, converter, subcategory, interval, warnings);
    assertThat(warnings.isEmpty(), is(true));
    assertThat(index_subcategory.getTotals()[index_subcategory.getTotals().length - 1], is(Values.Amount.factorize(3181.82)));
}
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 4 with PerformanceIndex

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

the class ClassificationTestCase method testCase1.

@Test
public void testCase1() {
    Taxonomy case1 = client.getTaxonomies().stream().filter(t -> "case_1".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    List<Exception> warnings = new ArrayList<>();
    // check performance of sub-category (containing only one security) is
    // identical with performance of security
    Classification category_security = case1.getAllClassifications().stream().filter(c -> "category_security".equals(c.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    PerformanceIndex index_cat_security = PerformanceIndex.forClassification(client, converter, category_security, interval, warnings);
    assertThat(warnings.isEmpty(), is(true));
    PerformanceIndex index_adidas = PerformanceIndex.forInvestment(client, converter, adidas, interval, warnings);
    assertThat(warnings.isEmpty(), is(true));
    assertThat(index_cat_security.getDates(), is(index_adidas.getDates()));
    assertThat(index_cat_security.getAccumulatedPercentage(), is(index_adidas.getAccumulatedPercentage()));
    assertThat(index_cat_security.getDeltaPercentage(), is(index_adidas.getDeltaPercentage()));
    assertThat(index_cat_security.getTotals(), is(index_adidas.getTotals()));
    assertThat(index_cat_security.getTransferals(), is(index_adidas.getTransferals()));
}
Also used : Taxonomy(name.abuchen.portfolio.model.Taxonomy) Classification(name.abuchen.portfolio.model.Classification) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) Test(org.junit.Test)

Example 5 with PerformanceIndex

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

the class ClassificationTestCase method testCase1_subcategory.

@Test
public void testCase1_subcategory() {
    Taxonomy case1 = client.getTaxonomies().stream().filter(t -> "case_1".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    // check performance of 'subcategory'
    Classification subcategory = case1.getAllClassifications().stream().filter(c -> "subcategory".equals(c.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    Client subcategoryClient = new ClientClassificationFilter(subcategory).filter(client);
    List<PortfolioTransaction> txp = subcategoryClient.getPortfolios().stream().flatMap(p -> p.getTransactions().stream()).collect(Collectors.toList());
    assertThat(txp, hasSize(1));
    assertThat(txp, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-02T00:00"))), // 
    hasProperty("type", is(PortfolioTransaction.Type.BUY)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2397.60)))))));
    List<AccountTransaction> txa = subcategoryClient.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.BUY)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2397.60)))))));
    // check that other purchase transactions are converted into removals
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-01T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1019.80)))))));
    // check that dividend is included without taxes
    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(24.44)))))));
    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(5)))))));
    // create index
    List<Exception> warnings = new ArrayList<>();
    PerformanceIndex index_subcategory = PerformanceIndex.forClassification(client, converter, subcategory, interval, warnings);
    assertThat(warnings.isEmpty(), is(true));
    // total must match value shown in taxonomy view (calculated by
    // distributing the total portfolio among the categories)
    assertThat(index_subcategory.getTotals()[index_subcategory.getTotals().length - 1], is(Values.Amount.factorize(3805.90)));
}
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)

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