Search in sources :

Example 6 with SecurityBuilder

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

the class ClientPerformanceSnapshotTest method testDividendTransactionWithTaxes.

@Test
public void testDividendTransactionWithTaxes() {
    Client client = new Client();
    Security security = new SecurityBuilder().addTo(client);
    Account account = new AccountBuilder().addTo(client);
    AccountTransaction dividend = new AccountTransaction();
    dividend.setDateTime(LocalDateTime.parse("2011-03-01T00:00"));
    dividend.setType(AccountTransaction.Type.DIVIDENDS);
    dividend.setSecurity(security);
    dividend.setMonetaryAmount(Money.of(CurrencyUnit.EUR, 100_00));
    dividend.addUnit(new Transaction.Unit(Transaction.Unit.Type.TAX, Money.of(CurrencyUnit.EUR, 10_00)));
    assertThat(dividend.getGrossValue(), is(Money.of(CurrencyUnit.EUR, 110_00)));
    account.addTransaction(dividend);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 110_00)));
    assertThat(snapshot.getValue(CategoryType.TAXES), is(Money.of(CurrencyUnit.EUR, 10_00)));
    assertThat(snapshot.getEarnings().size(), is(1));
    assertThat(snapshot.getCategoryByType(CategoryType.EARNINGS).getPositions().get(0).getValuation(), is(Money.of(CurrencyUnit.EUR, 110_00)));
    GroupEarningsByAccount.Item item = new GroupEarningsByAccount(snapshot).getItems().get(0);
    assertThat(item.getSum(), is(Money.of(CurrencyUnit.EUR, 110_00)));
    assertThatCalculationWorksOut(snapshot, converter);
}
Also used : Account(name.abuchen.portfolio.model.Account) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) Unit(name.abuchen.portfolio.model.Transaction.Unit) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.model.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) AccountBuilder(name.abuchen.portfolio.AccountBuilder) Client(name.abuchen.portfolio.model.Client) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Test(org.junit.Test)

Example 7 with SecurityBuilder

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

the class ClientPerformanceSnapshotTest method testInboundDeliveryWithFees.

@Test
public void testInboundDeliveryWithFees() {
    Client client = new Client();
    Security security = new SecurityBuilder().addTo(client);
    Portfolio portfolio = new PortfolioBuilder().addTo(client);
    PortfolioTransaction delivery = new PortfolioTransaction();
    delivery.setDateTime(LocalDateTime.parse("2011-03-01T00:00"));
    delivery.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
    delivery.setSecurity(security);
    delivery.setMonetaryAmount(Money.of(CurrencyUnit.EUR, 100_00));
    delivery.addUnit(new Transaction.Unit(Transaction.Unit.Type.TAX, Money.of(CurrencyUnit.EUR, 10_00)));
    delivery.addUnit(new Transaction.Unit(Transaction.Unit.Type.FEE, Money.of(CurrencyUnit.EUR, 10_00)));
    assertThat(delivery.getGrossValue(), is(Money.of(CurrencyUnit.EUR, 80_00)));
    portfolio.addTransaction(delivery);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 0)));
    assertThat(snapshot.getValue(CategoryType.FEES), is(Money.of(CurrencyUnit.EUR, 10_00)));
    assertThat(snapshot.getValue(CategoryType.TAXES), is(Money.of(CurrencyUnit.EUR, 10_00)));
    assertThat(snapshot.getValue(CategoryType.TRANSFERS), is(Money.of(CurrencyUnit.EUR, 100_00)));
    assertThatCalculationWorksOut(snapshot, converter);
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.model.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Unit(name.abuchen.portfolio.model.Transaction.Unit) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 8 with SecurityBuilder

use of name.abuchen.portfolio.SecurityBuilder 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 9 with SecurityBuilder

use of name.abuchen.portfolio.SecurityBuilder 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 10 with SecurityBuilder

use of name.abuchen.portfolio.SecurityBuilder 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)

Aggregations

SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)25 Client (name.abuchen.portfolio.model.Client)24 Security (name.abuchen.portfolio.model.Security)23 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)22 Test (org.junit.Test)22 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)21 AccountBuilder (name.abuchen.portfolio.AccountBuilder)13 Portfolio (name.abuchen.portfolio.model.Portfolio)13 LocalDate (java.time.LocalDate)12 Account (name.abuchen.portfolio.model.Account)9 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)9 TaxonomyBuilder (name.abuchen.portfolio.TaxonomyBuilder)7 Taxonomy (name.abuchen.portfolio.model.Taxonomy)7 ArrayList (java.util.ArrayList)6 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)3 Unit (name.abuchen.portfolio.model.Transaction.Unit)3 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)2 Transaction (name.abuchen.portfolio.model.Transaction)2 Before (org.junit.Before)2 LocalDateTime (java.time.LocalDateTime)1