Search in sources :

Example 6 with AccountBuilder

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

the class ClientPerformanceSnapshotTest method testCapitalGainsWithPartialSellDuringReportPeriodWithFees.

@Test
public void testCapitalGainsWithPartialSellDuringReportPeriodWithFees() {
    Client client = new Client();
    Security security = // 
    new SecurityBuilder().addPrice("2010-01-01", // 
    Values.Quote.factorize(100)).addPrice("2011-06-01", // 
    Values.Quote.factorize(110)).addTo(client);
    Account account = // 
    new AccountBuilder().deposit_("2010-01-01", // 
    1_00).withdraw("2011-01-15", // 
    99_00).addTo(client);
    // 
    new PortfolioBuilder(account).buy(security, "2010-01-01", Values.Share.factorize(10), // 
    1_00).sell(security, "2011-01-15", Values.Share.factorize(1), 99_00, // 
    1).addTo(client);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.CAPITAL_GAINS), is(Money.of(CurrencyUnit.EUR, 1000 * 9 + (9900 - 10000) + 1)));
    assertThat(snapshot.getValue(CategoryType.FEES), is(Money.of(CurrencyUnit.EUR, 1)));
    assertThat(snapshot.getAbsoluteDelta(), is(snapshot.getValue(CategoryType.FINAL_VALUE).subtract(snapshot.getValue(CategoryType.TRANSFERS)).subtract(snapshot.getValue(CategoryType.INITIAL_VALUE))));
}
Also used : Account(name.abuchen.portfolio.model.Account) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) AccountBuilder(name.abuchen.portfolio.AccountBuilder) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 7 with AccountBuilder

use of name.abuchen.portfolio.AccountBuilder 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 8 with AccountBuilder

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

the class ClientPerformanceSnapshotTest method testCurrencyGainsWithTransferalInOtherCurrencies.

@Test
public void testCurrencyGainsWithTransferalInOtherCurrencies() {
    Client client = new Client();
    Account usd = // 
    new AccountBuilder("USD").deposit_("2015-01-01", // 
    1000_00).addTo(client);
    Account cad = // 
    new AccountBuilder("CAD").deposit_("2015-01-01", // 
    1000_00).addTo(client);
    // insert account transfer
    AccountTransferEntry entry = new AccountTransferEntry(usd, cad);
    entry.setDate(LocalDateTime.parse("2015-01-10T00:00"));
    AccountTransaction source = entry.getSourceTransaction();
    AccountTransaction target = entry.getTargetTransaction();
    source.setMonetaryAmount(Money.of("USD", 500_00));
    target.setMonetaryAmount(Money.of("CAD", 1000_00));
    source.addUnit(new Unit(Unit.Type.GROSS_VALUE, source.getMonetaryAmount(), target.getMonetaryAmount(), BigDecimal.valueOf(.5)));
    entry.insert();
    // check currency gain calculation of client performance snapshot
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new // 
    ClientPerformanceSnapshot(// 
    client, // 
    converter, LocalDate.parse("2015-01-01"), LocalDate.parse("2015-01-15"));
    MutableMoney currencyGains = MutableMoney.of(converter.getTermCurrency());
    currencyGains.subtract(snapshot.getValue(CategoryType.INITIAL_VALUE));
    currencyGains.subtract(snapshot.getValue(CategoryType.CAPITAL_GAINS));
    currencyGains.subtract(snapshot.getValue(CategoryType.EARNINGS));
    currencyGains.add(snapshot.getValue(CategoryType.FEES));
    currencyGains.add(snapshot.getValue(CategoryType.TAXES));
    currencyGains.add(snapshot.getValue(CategoryType.TRANSFERS));
    currencyGains.add(snapshot.getValue(CategoryType.FINAL_VALUE));
    assertThat(snapshot.getCategoryByType(CategoryType.CURRENCY_GAINS).getValuation(), is(currencyGains.toMoney()));
}
Also used : Account(name.abuchen.portfolio.model.Account) MutableMoney(name.abuchen.portfolio.money.MutableMoney) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) AccountBuilder(name.abuchen.portfolio.AccountBuilder) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Client(name.abuchen.portfolio.model.Client) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 9 with AccountBuilder

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

the class ClientPerformanceSnapshotTest method testCurrencyGainsWithIntermediateTransactions.

@Test
public void testCurrencyGainsWithIntermediateTransactions() {
    Client client = new Client();
    // 
    new AccountBuilder("USD").deposit_("2015-01-01", // 
    1000_00).deposit_("2015-01-05", // 
    200_00).withdraw("2015-01-10", // 
    500_00).fees____("2015-01-12", // 
    20_00).addTo(client);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new // 
    ClientPerformanceSnapshot(// 
    client, // 
    converter, LocalDate.parse("2015-01-02"), LocalDate.parse("2015-01-15"));
    assertThat(snapshot.getValue(CategoryType.INITIAL_VALUE), is(Money.of(CurrencyUnit.EUR, Math.round(1000_00 * (1 / 1.2043)))));
    assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, Math.round(680_00 * (1 / 1.1708)))));
    assertThat(snapshot.getAbsoluteDelta(), is(snapshot.getValue(CategoryType.FINAL_VALUE).subtract(snapshot.getValue(CategoryType.TRANSFERS)).subtract(snapshot.getValue(CategoryType.INITIAL_VALUE))));
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) AccountBuilder(name.abuchen.portfolio.AccountBuilder) Client(name.abuchen.portfolio.model.Client) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 10 with AccountBuilder

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

Aggregations

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