Search in sources :

Example 1 with TaxonomyBuilder

use of name.abuchen.portfolio.TaxonomyBuilder in project portfolio by buchen.

the class ClassificationIndexTest method createClient.

private Client createClient(int weight) {
    Client client = new Client();
    Taxonomy taxonomy = // 
    new TaxonomyBuilder().addClassification(// 
    "one").addTo(client);
    Security security = // 
    new SecurityBuilder().addPrice("2011-12-31", // 
    100 * Values.Quote.factor()).addPrice("2012-01-03", // 
    106 * Values.Quote.factor()).addPrice("2012-01-08", // 
    112 * Values.Quote.factor()).assign(taxonomy, "one", // 
    weight).addTo(client);
    Account account = // 
    new AccountBuilder().deposit_("2011-12-31", // 
    10000 * Values.Amount.factor()).interest("2012-01-01", // 
    230 * Values.Amount.factor()).deposit_("2012-01-02", // 
    200 * Values.Amount.factor()).interest("2012-01-02", // 
    200 * Values.Amount.factor()).withdraw("2012-01-03", // 
    400 * Values.Amount.factor()).fees____("2012-01-03", // 
    234 * Values.Amount.factor()).interest("2012-01-04", // 
    293 * Values.Amount.factor()).interest("2012-01-05", // 
    293 * Values.Amount.factor()).deposit_("2012-01-06", // 
    5400 * Values.Amount.factor()).interest("2012-01-06", // 
    195 * Values.Amount.factor()).withdraw("2012-01-07", // 
    3697 * Values.Amount.factor()).fees____("2012-01-07", // 
    882 * Values.Amount.factor()).fees____("2012-01-08", // 
    1003 * Values.Amount.factor()).dividend("2012-01-08", 100 * Values.Amount.factor(), // 
    security).assign(taxonomy, "one", // 
    weight).addTo(client);
    // 
    new PortfolioBuilder(account).buy(security, "2012-01-01", 50 * Values.Share.factor(), // 
    50 * 101 * Values.Amount.factor()).inbound_delivery(security, "2012-01-01", 100 * Values.Share.factor(), // 
    100 * 100 * Values.Amount.factor()).sell(security, "2012-01-05", 50 * Values.Share.factor(), // 
    50 * 105 * Values.Amount.factor()).addTo(client);
    return client;
}
Also used : Account(name.abuchen.portfolio.model.Account) Taxonomy(name.abuchen.portfolio.model.Taxonomy) AccountBuilder(name.abuchen.portfolio.AccountBuilder) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) TaxonomyBuilder(name.abuchen.portfolio.TaxonomyBuilder) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder)

Example 2 with TaxonomyBuilder

use of name.abuchen.portfolio.TaxonomyBuilder in project portfolio by buchen.

the class GroupByTaxonomyTest method testThatAccountsAreClassifiedCorrectlyWhenFiltered.

@Test
public void testThatAccountsAreClassifiedCorrectlyWhenFiltered() {
    // bug report:
    // https://forum.portfolio-performance.info/t/vermoegensaufstellung-klassifizierung-mit-filter/1129
    Client client = new Client();
    Taxonomy taxonomy = // 
    new TaxonomyBuilder().addClassification(// 
    "debt").addTo(client);
    Security a = // 
    new SecurityBuilder().addPrice("2010-01-01", // 
    Values.Quote.factorize(10)).assign(taxonomy, "debt", // 
    Classification.ONE_HUNDRED_PERCENT).addTo(client);
    Account account = // 
    new AccountBuilder().deposit_("2010-01-01", Values.Amount.factorize(100)).assign(taxonomy, "debt", // 
    Classification.ONE_HUNDRED_PERCENT).addTo(client);
    // 
    new PortfolioBuilder(account).inbound_delivery(a, "2010-01-01", Values.Share.factorize(10), // 
    10000).addTo(client);
    ClientFilter filter = new ClientClassificationFilter(taxonomy.getClassificationById("debt"));
    LocalDate date = LocalDate.parse("2010-01-01");
    ClientSnapshot snapshot = ClientSnapshot.create(filter.filter(client), new TestCurrencyConverter(), date);
    assertNotNull(snapshot);
    GroupByTaxonomy grouping = snapshot.groupByTaxonomy(taxonomy);
    // everything is classified
    assertThat(grouping.asList().size(), is(1));
    // two positions in 'debt' category
    AssetCategory debt = grouping.byClassification(taxonomy.getClassificationById("debt"));
    assertThat(debt.getValuation(), is(Money.of(CurrencyUnit.EUR, Values.Money.factorize(200))));
    assertThat(debt.getPositions().size(), is(2));
    // nothing in unassigned
    AssetCategory unassigned = null;
    for (AssetCategory category : grouping.asList()) if (category.getClassification().getId().equals(Classification.UNASSIGNED_ID))
        unassigned = category;
    assertThat(unassigned, nullValue());
}
Also used : Account(name.abuchen.portfolio.model.Account) Taxonomy(name.abuchen.portfolio.model.Taxonomy) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Security(name.abuchen.portfolio.model.Security) LocalDate(java.time.LocalDate) TaxonomyBuilder(name.abuchen.portfolio.TaxonomyBuilder) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) ClientFilter(name.abuchen.portfolio.snapshot.filter.ClientFilter) AccountBuilder(name.abuchen.portfolio.AccountBuilder) Client(name.abuchen.portfolio.model.Client) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Test(org.junit.Test)

Example 3 with TaxonomyBuilder

use of name.abuchen.portfolio.TaxonomyBuilder in project portfolio by buchen.

the class GroupByTaxonomyTest method testThatSecuritiesAreGroupedIntoClassifications.

@Test
public void testThatSecuritiesAreGroupedIntoClassifications() {
    Client client = new Client();
    Taxonomy taxonomy = // 
    new TaxonomyBuilder().addClassification(// 
    "debt").addClassification(// 
    "equity").addClassification(// 
    "realestate").addTo(client);
    Security a = // 
    new SecurityBuilder().addPrice("2010-01-01", // 
    Values.Quote.factorize(10)).assign(taxonomy, // 
    "debt").addTo(client);
    Security c = // 
    new SecurityBuilder().addPrice("2010-01-01", // 
    Values.Quote.factorize(12)).assign(taxonomy, // 
    "equity").addTo(client);
    Security d = // 
    new SecurityBuilder().addPrice("2010-01-01", // 
    Values.Quote.factorize(12)).assign(taxonomy, // 
    "equity").addTo(client);
    Portfolio portfolio = // 
    new PortfolioBuilder().inbound_delivery(a, "2010-01-01", Values.Share.factorize(10), // 
    10000).inbound_delivery(c, "2010-01-01", Values.Share.factorize(10), // 
    12000).inbound_delivery(d, "2010-01-01", Values.Share.factorize(10), // 
    12000).addTo(client);
    LocalDate date = LocalDate.parse("2010-01-01");
    PortfolioSnapshot snapshot = PortfolioSnapshot.create(portfolio, new TestCurrencyConverter(), date);
    assertNotNull(snapshot);
    GroupByTaxonomy grouping = snapshot.groupByTaxonomy(taxonomy);
    AssetCategory debt = grouping.byClassification(taxonomy.getClassificationById("debt"));
    assertThat(debt.getValuation(), is(Money.of(CurrencyUnit.EUR, 100_00)));
    assertThat(debt.getPositions().size(), is(1));
    AssetCategory stocks = grouping.byClassification(taxonomy.getClassificationById("equity"));
    assertThat(stocks.getValuation(), is(Money.of(CurrencyUnit.EUR, 240_00)));
    assertThat(stocks.getPositions().size(), is(2));
    AssetCategory realEstate = grouping.byClassification(taxonomy.getClassificationById("realestate"));
    assertThat(realEstate, nullValue());
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Taxonomy(name.abuchen.portfolio.model.Taxonomy) Portfolio(name.abuchen.portfolio.model.Portfolio) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) LocalDate(java.time.LocalDate) TaxonomyBuilder(name.abuchen.portfolio.TaxonomyBuilder) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Test(org.junit.Test)

Example 4 with TaxonomyBuilder

use of name.abuchen.portfolio.TaxonomyBuilder in project portfolio by buchen.

the class GroupByTaxonomyTest method testSecuritiesWithoutAssignment.

@Test
public void testSecuritiesWithoutAssignment() {
    Client client = new Client();
    Taxonomy taxonomy = // 
    new TaxonomyBuilder().addClassification(// 
    "debt").addTo(client);
    Security a = // 
    new SecurityBuilder().addPrice("2010-01-01", // 
    Values.Quote.factorize(10)).addTo(client);
    Portfolio portfolio = // 
    new PortfolioBuilder().inbound_delivery(a, "2010-01-01", Values.Share.factorize(10), // 
    10000).addTo(client);
    LocalDate date = LocalDate.parse("2010-01-01");
    PortfolioSnapshot snapshot = PortfolioSnapshot.create(portfolio, new TestCurrencyConverter(), date);
    assertNotNull(snapshot);
    GroupByTaxonomy grouping = snapshot.groupByTaxonomy(taxonomy);
    AssetCategory debt = grouping.byClassification(taxonomy.getClassificationById("debt"));
    assertThat(debt, nullValue());
    List<AssetCategory> categories = grouping.asList();
    assertThat(categories.size(), is(1));
    AssetCategory unassigned = categories.get(0);
    assertThat(unassigned.getValuation(), is(Money.of(CurrencyUnit.EUR, 100_00)));
    assertThat(unassigned.getPositions().size(), is(1));
}
Also used : Taxonomy(name.abuchen.portfolio.model.Taxonomy) Portfolio(name.abuchen.portfolio.model.Portfolio) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Security(name.abuchen.portfolio.model.Security) LocalDate(java.time.LocalDate) TaxonomyBuilder(name.abuchen.portfolio.TaxonomyBuilder) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Client(name.abuchen.portfolio.model.Client) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Test(org.junit.Test)

Example 5 with TaxonomyBuilder

use of name.abuchen.portfolio.TaxonomyBuilder in project portfolio by buchen.

the class GroupByTaxonomyTest method testThatPartialAssignmentsInSubClassificationsAreMerged.

@Test
public void testThatPartialAssignmentsInSubClassificationsAreMerged() {
    Client client = new Client();
    Taxonomy taxonomy = // 
    new TaxonomyBuilder().addClassification(// 
    "debt").addClassification("debt", // 
    "cat1").addClassification("debt", // 
    "cat2").addTo(client);
    Security a = // 
    new SecurityBuilder().addPrice("2010-01-01", // 
    Values.Quote.factorize(10)).assign(taxonomy, "cat1", // 
    Classification.ONE_HUNDRED_PERCENT / 2).assign(taxonomy, "cat2", // 
    Classification.ONE_HUNDRED_PERCENT / 2).addTo(client);
    Portfolio portfolio = // 
    new PortfolioBuilder().inbound_delivery(a, "2010-01-01", Values.Share.factorize(10), // 
    10000).addTo(client);
    LocalDate date = LocalDate.parse("2010-01-01");
    PortfolioSnapshot snapshot = PortfolioSnapshot.create(portfolio, new TestCurrencyConverter(), date);
    assertNotNull(snapshot);
    GroupByTaxonomy grouping = snapshot.groupByTaxonomy(taxonomy);
    assertThat(grouping.asList().size(), is(1));
    AssetCategory debt = grouping.byClassification(taxonomy.getClassificationById("debt"));
    assertThat(debt.getPositions().size(), is(1));
    assertThat(debt.getValuation(), is(Money.of(CurrencyUnit.EUR, 100_00)));
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Taxonomy(name.abuchen.portfolio.model.Taxonomy) Portfolio(name.abuchen.portfolio.model.Portfolio) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) LocalDate(java.time.LocalDate) TaxonomyBuilder(name.abuchen.portfolio.TaxonomyBuilder) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Test(org.junit.Test)

Aggregations

PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)7 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)7 TaxonomyBuilder (name.abuchen.portfolio.TaxonomyBuilder)7 Client (name.abuchen.portfolio.model.Client)7 Security (name.abuchen.portfolio.model.Security)7 Taxonomy (name.abuchen.portfolio.model.Taxonomy)7 LocalDate (java.time.LocalDate)6 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)6 Test (org.junit.Test)6 Portfolio (name.abuchen.portfolio.model.Portfolio)5 AccountBuilder (name.abuchen.portfolio.AccountBuilder)2 Account (name.abuchen.portfolio.model.Account)2 ClientClassificationFilter (name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter)1 ClientFilter (name.abuchen.portfolio.snapshot.filter.ClientFilter)1