Search in sources :

Example 21 with Portfolio

use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.

the class ClientPerformanceSnapshotTest method testCapitalGains.

@Test
public void testCapitalGains() {
    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));
    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)));
    assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1100_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 22 with Portfolio

use of name.abuchen.portfolio.model.Portfolio 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 23 with Portfolio

use of name.abuchen.portfolio.model.Portfolio 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 24 with Portfolio

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

Example 25 with Portfolio

use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.

the class PortfolioMergeTest method setUpClient.

@Before
public void setUpClient() {
    // Portfolio A : Security A + Security X
    // Portfolio B : Security B + Security X
    client = new Client();
    securityA = new Security();
    securityA.addPrice(new SecurityPrice(LocalDate.of(2010, Month.JANUARY, 1), Values.Quote.factorize(10)));
    client.addSecurity(securityA);
    securityB = new Security();
    securityB.addPrice(new SecurityPrice(LocalDate.of(2010, Month.JANUARY, 1), Values.Quote.factorize(11)));
    client.addSecurity(securityB);
    securityX = new Security();
    securityX.addPrice(new SecurityPrice(LocalDate.of(2010, Month.JANUARY, 1), Values.Quote.factorize(12)));
    client.addSecurity(securityX);
    Portfolio portfolioA = new Portfolio();
    portfolioA.addTransaction(new PortfolioTransaction(LocalDateTime.of(2010, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 100_00, securityA, Values.Share.factorize(10), PortfolioTransaction.Type.BUY, 0, 0));
    portfolioA.addTransaction(new PortfolioTransaction(LocalDateTime.of(2010, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 121_00, securityX, Values.Share.factorize(10), PortfolioTransaction.Type.BUY, 100, 0));
    client.addPortfolio(portfolioA);
    Portfolio portfolioB = new Portfolio();
    portfolioB.addTransaction(new PortfolioTransaction(LocalDateTime.of(2010, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 110_00, securityB, Values.Share.factorize(10), PortfolioTransaction.Type.BUY, 0, 0));
    portfolioB.addTransaction(new PortfolioTransaction(LocalDateTime.of(2010, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 100_00, securityX, Values.Share.factorize(10), PortfolioTransaction.Type.BUY, 0, 0));
    client.addPortfolio(portfolioB);
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) Before(org.junit.Before)

Aggregations

Portfolio (name.abuchen.portfolio.model.Portfolio)75 Security (name.abuchen.portfolio.model.Security)52 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)44 Test (org.junit.Test)41 Account (name.abuchen.portfolio.model.Account)39 Client (name.abuchen.portfolio.model.Client)38 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)24 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)21 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)20 Unit (name.abuchen.portfolio.model.Transaction.Unit)19 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)17 LocalDate (java.time.LocalDate)16 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)12 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)11 Money (name.abuchen.portfolio.money.Money)11 ArrayList (java.util.ArrayList)10 Values (name.abuchen.portfolio.money.Values)10 AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)9 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)9 Collections (java.util.Collections)8