Search in sources :

Example 16 with Classification

use of name.abuchen.portfolio.model.Classification in project portfolio by buchen.

the class TaxonomyNode method moveTo.

private void moveTo(int index, TaxonomyNode target) {
    Classification classification = target.getClassification();
    if (classification == null)
        throw new UnsupportedOperationException();
    if (isAssignment()) {
        InvestmentVehicle investmentVehicle = getAssignment().getInvestmentVehicle();
        TaxonomyNode sibling = target.getChildByInvestmentVehicle(investmentVehicle);
        if (sibling != null) {
            sibling.absorb(this);
            return;
        }
    }
    // change parent, update children collections and rank
    this.getParent().removeChild(this);
    this.parent = target;
    if (isClassification()) {
        getClassification().setParent(classification);
        classification.getChildren().add(getClassification());
    } else {
        classification.getAssignments().add(getAssignment());
    }
    List<TaxonomyNode> siblings = target.getChildren();
    if (index == -1)
        index = siblings.size();
    int insertAt = target.isRoot() ? Math.min(index, siblings.size() - 1) : index;
    siblings.add(insertAt, this);
    for (int ii = 0; ii < siblings.size(); ii++) siblings.get(ii).setRank(ii);
}
Also used : Classification(name.abuchen.portfolio.model.Classification) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle)

Example 17 with Classification

use of name.abuchen.portfolio.model.Classification in project portfolio by buchen.

the class DataSeriesSet method buildCommonDataSeries.

private void buildCommonDataSeries(Client client, IPreferenceStore preferences, ColorWheel wheel) {
    int index = client.getSecurities().size();
    for (Security security : client.getSecurities()) {
        // as equity data series (only as benchmark)
        if (security.getCurrencyCode() == null)
            continue;
        availableSeries.add(new // 
        DataSeries(// 
        DataSeries.Type.SECURITY, // 
        security, // 
        security.getName(), wheel.getRGB(index++)));
    }
    for (Portfolio portfolio : client.getPortfolios()) availableSeries.add(new // 
    DataSeries(// 
    DataSeries.Type.PORTFOLIO, // 
    portfolio, // 
    portfolio.getName(), wheel.getRGB(index++)));
    // portfolio + reference account
    for (Portfolio portfolio : client.getPortfolios()) {
        DataSeries series = new DataSeries(DataSeries.Type.PORTFOLIO_PLUS_ACCOUNT, portfolio, // $NON-NLS-1$
        portfolio.getName() + " + " + portfolio.getReferenceAccount().getName(), wheel.getRGB(index++));
        availableSeries.add(series);
    }
    // custom client filters
    ClientFilterMenu menu = new ClientFilterMenu(client, preferences);
    // quick fix: users can create duplicate client filters that end up to
    // have the same UUID. Avoid adding both violates the precondition that
    // every data series must have a unique id
    Set<String> addedSeries = new HashSet<>();
    for (ClientFilterMenu.Item item : menu.getCustomItems()) {
        DataSeries series = new DataSeries(DataSeries.Type.CLIENT_FILTER, item, item.getLabel(), wheel.getRGB(index++));
        if (addedSeries.add(series.getUUID()))
            availableSeries.add(series);
    }
    for (Account account : client.getAccounts()) availableSeries.add(new DataSeries(DataSeries.Type.ACCOUNT, account, account.getName(), wheel.getRGB(index++)));
    for (Taxonomy taxonomy : client.getTaxonomies()) {
        taxonomy.foreach(new Taxonomy.Visitor() {

            @Override
            public void visit(Classification classification) {
                if (classification.getParent() == null)
                    return;
                availableSeries.add(new DataSeries(DataSeries.Type.CLASSIFICATION, classification, classification.getName(), Colors.toRGB(classification.getColor())));
            }
        });
    }
}
Also used : Account(name.abuchen.portfolio.model.Account) Taxonomy(name.abuchen.portfolio.model.Taxonomy) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security) Classification(name.abuchen.portfolio.model.Classification) ClientDataSeries(name.abuchen.portfolio.ui.views.dataseries.DataSeries.ClientDataSeries) ClientFilterMenu(name.abuchen.portfolio.ui.util.ClientFilterMenu) HashSet(java.util.HashSet)

Example 18 with Classification

use of name.abuchen.portfolio.model.Classification in project portfolio by buchen.

the class ClassificationTestCase method testCase7_Account30Account30.

@Test
public void testCase7_Account30Account30() {
    Taxonomy case1 = client.getTaxonomies().stream().filter(t -> "case_7".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().filter(a -> "Konto 1".equals(a.getName())).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 * 0.3)))))));
    // 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 * 0.3)))))));
    txa = categoryClient.getAccounts().stream().filter(a -> "Konto 2".equals(a.getName())).flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
    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 * 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(534.91)));
}
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 19 with Classification

use of name.abuchen.portfolio.model.Classification in project portfolio by buchen.

the class ClassificationTestCase method testCase8_Security100Account30_SecurityTransfer.

@Test
public void testCase8_Security100Account30_SecurityTransfer() {
    Taxonomy case8 = client.getTaxonomies().stream().filter(t -> "case_8".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    // check performance of 'subcategory'
    Classification ccategory = case8.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("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(3813.58 - 20)))))));
    assertThat(txp, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-02T00:00"))), // 
    hasProperty("type", is(PortfolioTransaction.Type.DELIVERY_INBOUND)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(6640.30)))))));
    List<AccountTransaction> txa = categoryClient.getAccounts().stream().flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
    // 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(10563.68)));
}
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 20 with Classification

use of name.abuchen.portfolio.model.Classification in project portfolio by buchen.

the class ClassificationTestCase method testCase5_Account70Account30.

@Test
public void testCase5_Account70Account30() {
    Taxonomy case1 = client.getTaxonomies().stream().filter(t -> "case_5".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 * 0.7)))))));
    // 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 * 0.3)))))));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-25T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.DEPOSIT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100 * 0.4)))))));
    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 * 0.3)))))));
    // 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 * 0.3)))))));
    // 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)))))));
    // 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 * 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(1034.17)));
}
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

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