Search in sources :

Example 71 with TestCurrencyConverter

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

the class PortfolioMergeTest method testMergingPortfolioSnapshots.

@Test
public void testMergingPortfolioSnapshots() {
    ClientSnapshot snapshot = ClientSnapshot.create(client, new TestCurrencyConverter(), referenceDate);
    assertNotNull(snapshot);
    PortfolioSnapshot jointPortfolio = snapshot.getJointPortfolio();
    SecurityPosition positionA = jointPortfolio.getPositionsBySecurity().get(securityA);
    assertThat(positionA.getShares(), is(Values.Share.factorize(10)));
    assertThat(positionA.calculateValue(), is(Money.of(CurrencyUnit.EUR, 100_00)));
    SecurityPosition positionB = jointPortfolio.getPositionsBySecurity().get(securityB);
    assertThat(positionB.getShares(), is(Values.Share.factorize(10)));
    assertThat(positionB.calculateValue(), is(Money.of(CurrencyUnit.EUR, 110_00)));
    SecurityPosition positionX = jointPortfolio.getPositionsBySecurity().get(securityX);
    assertThat(positionX.getShares(), is(Values.Share.factorize(10 * 2)));
    assertThat(positionX.calculateValue(), is(Money.of(CurrencyUnit.EUR, 240_00)));
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Test(org.junit.Test)

Example 72 with TestCurrencyConverter

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

the class Issue371PurchaseValueWithTransfers method testPurchaseValueOfSecurityPositionWithTransfers.

@Test
public void testPurchaseValueOfSecurityPositionWithTransfers() throws IOException {
    Client client = ClientFactory.load(Issue371PurchaseValueWithTransfers.class.getResourceAsStream(// $NON-NLS-1$
    "Issue371PurchaseValueWithTransfers.xml"));
    Security adidas = client.getSecurities().get(0);
    // $NON-NLS-1$
    assertThat(adidas.getName(), is("Adidas AG"));
    ReportingPeriod period = new // $NON-NLS-1$
    ReportingPeriod.FromXtoY(// $NON-NLS-1$
    LocalDate.parse("2010-11-20"), // $NON-NLS-1$
    LocalDate.parse("2015-11-20"));
    // make sure that the transfer entry exists
    assertThat(client.getPortfolios().size(), is(2));
    assertThat(client.getPortfolios().stream().flatMap(p -> p.getTransactions().stream()).filter(t -> t.getSecurity() == adidas).filter(t -> t.getCrossEntry() instanceof PortfolioTransferEntry).filter(t -> t.getType() == PortfolioTransaction.Type.TRANSFER_IN).findAny().isPresent(), is(true));
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientSnapshot snapshot = ClientSnapshot.create(client, converter, period.getEndDate());
    SecurityPosition securityPosition = snapshot.getPositionsByVehicle().get(adidas).getPosition();
    SecurityPerformanceSnapshot securitySnapshot = SecurityPerformanceSnapshot.create(client, converter, period);
    SecurityPerformanceRecord securityRecord = securitySnapshot.getRecords().get(0);
    assertThat(securityRecord.getSecurity(), is(adidas));
    assertThat(securityPosition.getFIFOPurchaseValue(), is(securityRecord.getFifoCost()));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Client(name.abuchen.portfolio.model.Client) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Assert.assertThat(org.junit.Assert.assertThat) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) ClientFactory(name.abuchen.portfolio.model.ClientFactory) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Security(name.abuchen.portfolio.model.Security) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Client(name.abuchen.portfolio.model.Client) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) Test(org.junit.Test)

Example 73 with TestCurrencyConverter

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

the class Issue672CapitalGainsIfSecurityIsTransferred method testPurchaseValueOfSecurityPositionWithTransfers.

@Test
public void testPurchaseValueOfSecurityPositionWithTransfers() throws IOException {
    Client client = ClientFactory.load(Issue371PurchaseValueWithTransfers.class.getResourceAsStream(// $NON-NLS-1$
    "Issue672CapitalGainsIfSecurityIsTransferred.xml"));
    CurrencyConverter converter = new TestCurrencyConverter();
    Portfolio secondPortfolio = client.getPortfolios().get(1);
    ReportingPeriod period = new // $NON-NLS-1$
    ReportingPeriod.FromXtoY(// $NON-NLS-1$
    LocalDate.parse("2016-01-01"), // $NON-NLS-1$
    LocalDate.parse("2017-01-01"));
    SecurityPerformanceSnapshot snapshot = SecurityPerformanceSnapshot.create(client, converter, secondPortfolio, period);
    assertThat(snapshot.getRecords().size(), is(1));
    SecurityPerformanceRecord record = snapshot.getRecords().get(0);
    assertThat(record.getMarketValue(), is(Money.of(CurrencyUnit.EUR, Values.Money.factorize(971.41))));
    assertThat(record.getFifoCost(), is(Money.of(CurrencyUnit.EUR, Values.Money.factorize(883.1))));
    assertThat(record.getCapitalGainsOnHoldings(), is(Money.of(CurrencyUnit.EUR, Values.Money.factorize(88.31))));
    assertThat(record.getCapitalGainsOnHoldingsPercent(), is(IsCloseTo.closeTo(0.1d, 0.0000000001)));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Portfolio(name.abuchen.portfolio.model.Portfolio) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Client(name.abuchen.portfolio.model.Client) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 74 with TestCurrencyConverter

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

the class IssueCurrencyGainsRoundingError method testPurchaseValueOfSecurityPositionWithTransfers.

@Test
public void testPurchaseValueOfSecurityPositionWithTransfers() throws IOException {
    Client client = ClientFactory.load(IssueCurrencyGainsRoundingError.class.getResourceAsStream(// $NON-NLS-1$
    "IssueCurrencyGainsRoundingError.xml"));
    ReportingPeriod period = new // $NON-NLS-1$
    ReportingPeriod.FromXtoY(// $NON-NLS-1$
    LocalDate.parse("2015-01-09"), // $NON-NLS-1$
    LocalDate.parse("2016-01-09"));
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, period);
    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 : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) MutableMoney(name.abuchen.portfolio.money.MutableMoney) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Client(name.abuchen.portfolio.model.Client) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) ClientPerformanceSnapshot(name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot) 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