Search in sources :

Example 6 with TaxonomyBuilder

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

the class GroupByTaxonomyTest method testSecuritiesWithPartialAssignment.

@SuppressWarnings("null")
@Test
public void testSecuritiesWithPartialAssignment() {
    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 / 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(2));
    AssetCategory debt = grouping.byClassification(taxonomy.getClassificationById("debt"));
    assertThat(debt.getValuation(), is(Money.of(CurrencyUnit.EUR, 50_00)));
    assertThat(debt.getPositions().size(), is(1));
    AssetCategory unassigned = null;
    for (AssetCategory category : grouping.asList()) if (category.getClassification().getId().equals(Classification.UNASSIGNED_ID))
        unassigned = category;
    assertThat(unassigned, notNullValue());
    assertThat(unassigned.getValuation(), is(Money.of(CurrencyUnit.EUR, 50_00)));
    assertThat(unassigned.getPositions().size(), is(1));
}
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 7 with TaxonomyBuilder

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

the class GroupByTaxonomyTest method testThatPartialAssignmentsAreSeparated.

@Test
public void testThatPartialAssignmentsAreSeparated() {
    Client client = new Client();
    Taxonomy taxonomy = // 
    new TaxonomyBuilder().addClassification(// 
    "debt").addClassification(// 
    "equity").addTo(client);
    Security a = // 
    new SecurityBuilder().addPrice("2010-01-01", // 
    Values.Quote.factorize(10)).assign(taxonomy, "debt", // 
    Classification.ONE_HUNDRED_PERCENT / 2).assign(taxonomy, "equity", // 
    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);
    AssetCategory debt = grouping.byClassification(taxonomy.getClassificationById("debt"));
    assertThat(debt.getValuation(), is(Money.of(CurrencyUnit.EUR, 50_00)));
    assertThat(debt.getPositions().size(), is(1));
    AssetCategory equity = grouping.byClassification(taxonomy.getClassificationById("equity"));
    assertThat(equity.getValuation(), is(Money.of(CurrencyUnit.EUR, 50_00)));
    assertThat(equity.getPositions().size(), is(1));
}
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