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)));
}
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()));
}
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)));
}
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()));
}
Aggregations