Search in sources :

Example 16 with ClientClassificationFilter

use of name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter in project portfolio by buchen.

the class SecurityTaxAndFeeAccountTransactionsTestCase method checkTaxonomyWihtSecurityAndAccountAssignment.

@Test
public void checkTaxonomyWihtSecurityAndAccountAssignment() {
    // if account and security are both classified, only the tax
    // transactions are converted to deposits or removals
    Taxonomy case3 = client.getTaxonomies().stream().filter(t -> "case_full_classification_adidas_with_account".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    Classification classification = case3.getAllClassifications().stream().filter(c -> "category_security".equals(c.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    Client filteredClient = new ClientClassificationFilter(classification).filter(client);
    List<AccountTransaction> txa1 = filteredClient.getAccounts().stream().flatMap(a1 -> a1.getTransactions().stream()).collect(Collectors.toList());
    // expect 7 transactions: the original 6 plus the removal of the taxes
    // as
    // part of the buy
    assertThat(txa1.size(), is(7));
    // check for additional transactions
    assertThat(txa1, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2017-01-09T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.FEES)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(10.0)))))));
    assertThat(txa1, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2017-01-10T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.FEES_REFUND)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(5.0)))))));
    assertThat(txa1, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2017-01-11T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(25.0)))))));
    assertThat(txa1, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2017-01-12T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.DEPOSIT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(5.0)))))));
    // if the account is fully classified, but the security only partially,
    // there must be offset transactions to make sure that the balance of
    // the account remains correct
    Taxonomy case4 = client.getTaxonomies().stream().filter(t -> "case_partial_classification_adidas_with_account".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    classification = case4.getAllClassifications().stream().filter(c -> "category_security".equals(c.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    filteredClient = new ClientClassificationFilter(classification).filter(client);
    List<AccountTransaction> txa = filteredClient.getAccounts().stream().flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
    // expect 9 transactions: the original 6 plus the removal of the fees as
    // part of the buy + partial transactions to offset fees
    assertThat(txa.size(), is(9));
    // check for additional transactions
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2017-01-09T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.FEES)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(5)))))));
    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(5)))))));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2017-01-10T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.FEES_REFUND)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2.5)))))));
    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(2.5)))))));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) 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) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) 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) PortfolioClientFilter(name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Collectors(java.util.stream.Collectors) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) List(java.util.List) LocalDate(java.time.LocalDate) ClientSecurityFilter(name.abuchen.portfolio.snapshot.filter.ClientSecurityFilter) IsCloseTo.closeTo(org.hamcrest.number.IsCloseTo.closeTo) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) Taxonomy(name.abuchen.portfolio.model.Taxonomy) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) Classification(name.abuchen.portfolio.model.Classification) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Aggregations

LocalDate (java.time.LocalDate)16 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)16 Client (name.abuchen.portfolio.model.Client)16 Security (name.abuchen.portfolio.model.Security)16 Taxonomy (name.abuchen.portfolio.model.Taxonomy)16 ClientClassificationFilter (name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter)16 Test (org.junit.Test)16 IOException (java.io.IOException)15 LocalDateTime (java.time.LocalDateTime)15 ArrayList (java.util.ArrayList)15 List (java.util.List)15 Collectors (java.util.stream.Collectors)15 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)15 Classification (name.abuchen.portfolio.model.Classification)15 ClientFactory (name.abuchen.portfolio.model.ClientFactory)15 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)15 Money (name.abuchen.portfolio.money.Money)15 Values (name.abuchen.portfolio.money.Values)15 PerformanceIndex (name.abuchen.portfolio.snapshot.PerformanceIndex)15 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)15