use of name.abuchen.portfolio.money.CurrencyConverter 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);
}
use of name.abuchen.portfolio.money.CurrencyConverter 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()));
}
use of name.abuchen.portfolio.money.CurrencyConverter 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))));
}
use of name.abuchen.portfolio.money.CurrencyConverter in project portfolio by buchen.
the class ClientPerformanceSnapshotTest method testDepositPlusInterestLastDay.
@Test
public void testDepositPlusInterestLastDay() {
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.DECEMBER, 31, 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);
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.CAPITAL_GAINS), is(Money.of(CurrencyUnit.EUR, 0)));
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))));
}
use of name.abuchen.portfolio.money.CurrencyConverter in project portfolio by buchen.
the class ClientPerformanceSnapshotTest method testInboundDeliveryWithFees.
@Test
public void testInboundDeliveryWithFees() {
Client client = new Client();
Security security = new SecurityBuilder().addTo(client);
Portfolio portfolio = new PortfolioBuilder().addTo(client);
PortfolioTransaction delivery = new PortfolioTransaction();
delivery.setDateTime(LocalDateTime.parse("2011-03-01T00:00"));
delivery.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
delivery.setSecurity(security);
delivery.setMonetaryAmount(Money.of(CurrencyUnit.EUR, 100_00));
delivery.addUnit(new Transaction.Unit(Transaction.Unit.Type.TAX, Money.of(CurrencyUnit.EUR, 10_00)));
delivery.addUnit(new Transaction.Unit(Transaction.Unit.Type.FEE, Money.of(CurrencyUnit.EUR, 10_00)));
assertThat(delivery.getGrossValue(), is(Money.of(CurrencyUnit.EUR, 80_00)));
portfolio.addTransaction(delivery);
CurrencyConverter converter = new TestCurrencyConverter();
ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 0)));
assertThat(snapshot.getValue(CategoryType.FEES), is(Money.of(CurrencyUnit.EUR, 10_00)));
assertThat(snapshot.getValue(CategoryType.TAXES), is(Money.of(CurrencyUnit.EUR, 10_00)));
assertThat(snapshot.getValue(CategoryType.TRANSFERS), is(Money.of(CurrencyUnit.EUR, 100_00)));
assertThatCalculationWorksOut(snapshot, converter);
}
Aggregations