Search in sources :

Example 66 with TestCurrencyConverter

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

the class ClientPerformanceSnapshotTest method testCapitalGainsWithBuyDuringReportPeriod.

@Test
public void testCapitalGainsWithBuyDuringReportPeriod() {
    Client client = new Client();
    Security security = new Security();
    security.addPrice(new SecurityPrice(LocalDate.of(2010, Month.JANUARY, 1), Values.Quote.factorize(100)));
    security.addPrice(new SecurityPrice(LocalDate.of(2011, Month.JUNE, 1), Values.Quote.factorize(110)));
    client.addSecurity(security);
    Portfolio portfolio = new Portfolio();
    portfolio.setReferenceAccount(new Account());
    portfolio.addTransaction(new PortfolioTransaction(LocalDateTime.of(2010, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 1_00, security, Values.Share.factorize(10), PortfolioTransaction.Type.BUY, 0, 0));
    portfolio.addTransaction(new PortfolioTransaction(LocalDateTime.of(2011, Month.JANUARY, 15, 0, 0), CurrencyUnit.EUR, 99_00, security, Values.Share.factorize(1), PortfolioTransaction.Type.DELIVERY_INBOUND, 0, 0));
    client.addPortfolio(portfolio);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.INITIAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1000_00)));
    assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 0)));
    assertThat(snapshot.getValue(CategoryType.CAPITAL_GAINS), is(Money.of(CurrencyUnit.EUR, 100_00 + (110_00 - 99_00))));
    assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1210_00)));
    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) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Portfolio(name.abuchen.portfolio.model.Portfolio) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 67 with TestCurrencyConverter

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

the class ClientPerformanceSnapshotTest method testDepositPlusInterest.

@Test
public void testDepositPlusInterest() {
    Client client = new Client();
    Account account = new Account();
    account.addTransaction(new AccountTransaction(LocalDateTime.of(2010, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 1000_00, null, AccountTransaction.Type.DEPOSIT));
    account.addTransaction(new AccountTransaction(LocalDateTime.of(2011, Month.JUNE, 1, 0, 0), CurrencyUnit.EUR, 50_00, null, AccountTransaction.Type.INTEREST));
    client.addAccount(account);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertNotNull(snapshot);
    assertNotNull(snapshot.getStartClientSnapshot());
    assertEquals(startDate, snapshot.getStartClientSnapshot().getTime());
    assertNotNull(snapshot.getEndClientSnapshot());
    assertEquals(endDate, snapshot.getEndClientSnapshot().getTime());
    List<Category> categories = snapshot.getCategories();
    assertNotNull(categories);
    assertThat(categories.size(), is(ClientPerformanceSnapshot.CategoryType.values().length));
    assertThat(snapshot.getValue(CategoryType.INITIAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1000_00)));
    assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 50_00)));
    assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1050_00)));
    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) Category(name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot.Category) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Client(name.abuchen.portfolio.model.Client) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 68 with TestCurrencyConverter

use of name.abuchen.portfolio.TestCurrencyConverter 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 69 with TestCurrencyConverter

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

Example 70 with TestCurrencyConverter

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

the class PortfolioMergeTest method testThatTransactionsAreMergedOnSecurityPosition.

@Test
public void testThatTransactionsAreMergedOnSecurityPosition() {
    ClientSnapshot snapshot = ClientSnapshot.create(client, new TestCurrencyConverter(), referenceDate);
    assertNotNull(snapshot);
    PortfolioSnapshot jointPortfolio = snapshot.getJointPortfolio();
    SecurityPosition positionX = jointPortfolio.getPositionsBySecurity().get(securityX);
    assertThat(positionX.getShares(), is(Values.Share.factorize(20)));
    assertThat(positionX.calculateValue(), is(Money.of(CurrencyUnit.EUR, 240_00)));
    // calculate purchase price w/o costs
    assertThat(positionX.getFIFOPurchasePrice(), is(Money.of(CurrencyUnit.EUR, 11_00)));
    // calculate purchase value w/ costs
    assertThat(positionX.getFIFOPurchaseValue(), is(Money.of(CurrencyUnit.EUR, 221_00)));
    assertThat(positionX.getProfitLoss(), is(Money.of(CurrencyUnit.EUR, 19_00)));
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Test(org.junit.Test)

Aggregations

TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)74 Test (org.junit.Test)72 Client (name.abuchen.portfolio.model.Client)55 Security (name.abuchen.portfolio.model.Security)46 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)38 ArrayList (java.util.ArrayList)31 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)26 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)23 Portfolio (name.abuchen.portfolio.model.Portfolio)21 AccountBuilder (name.abuchen.portfolio.AccountBuilder)19 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)19 LocalDate (java.time.LocalDate)18 Account (name.abuchen.portfolio.model.Account)18 SecurityPrice (name.abuchen.portfolio.model.SecurityPrice)15 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)13 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)10 Taxonomy (name.abuchen.portfolio.model.Taxonomy)8 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)8 PerformanceIndex (name.abuchen.portfolio.snapshot.PerformanceIndex)8 IOException (java.io.IOException)7