use of name.abuchen.portfolio.model.Account 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.model.Account 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.model.Account 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))));
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class GroupByTaxonomyTest method testThatAccountsAreClassifiedCorrectlyWhenFiltered.
@Test
public void testThatAccountsAreClassifiedCorrectlyWhenFiltered() {
// bug report:
// https://forum.portfolio-performance.info/t/vermoegensaufstellung-klassifizierung-mit-filter/1129
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).addTo(client);
Account account = //
new AccountBuilder().deposit_("2010-01-01", Values.Amount.factorize(100)).assign(taxonomy, "debt", //
Classification.ONE_HUNDRED_PERCENT).addTo(client);
//
new PortfolioBuilder(account).inbound_delivery(a, "2010-01-01", Values.Share.factorize(10), //
10000).addTo(client);
ClientFilter filter = new ClientClassificationFilter(taxonomy.getClassificationById("debt"));
LocalDate date = LocalDate.parse("2010-01-01");
ClientSnapshot snapshot = ClientSnapshot.create(filter.filter(client), new TestCurrencyConverter(), date);
assertNotNull(snapshot);
GroupByTaxonomy grouping = snapshot.groupByTaxonomy(taxonomy);
// everything is classified
assertThat(grouping.asList().size(), is(1));
// two positions in 'debt' category
AssetCategory debt = grouping.byClassification(taxonomy.getClassificationById("debt"));
assertThat(debt.getValuation(), is(Money.of(CurrencyUnit.EUR, Values.Money.factorize(200))));
assertThat(debt.getPositions().size(), is(2));
// nothing in unassigned
AssetCategory unassigned = null;
for (AssetCategory category : grouping.asList()) if (category.getClassification().getId().equals(Classification.UNASSIGNED_ID))
unassigned = category;
assertThat(unassigned, nullValue());
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class PortfolioClientFilterTest method testCrossAccountTransfersAreKept.
@Test
public void testCrossAccountTransfersAreKept() {
Account accountA = client.getAccounts().get(0);
Account accountB = client.getAccounts().get(1);
AccountTransferEntry entry = new AccountTransferEntry(accountA, accountB);
entry.setDate(LocalDateTime.parse("2016-04-01T00:00"));
entry.setAmount(Values.Amount.factorize(10));
entry.setCurrencyCode(accountA.getCurrencyCode());
entry.insert();
Client result = new PortfolioClientFilter(Collections.emptyList(), Arrays.asList(accountA, accountB)).filter(client);
assertThat(result.getPortfolios(), empty());
assertThat(result.getAccounts().size(), is(2));
Account account = result.getAccounts().get(0);
// check that the 4 transactions are transformed:
// - buy -> removal
// - deposit
// - dividend -> deposit
// - transfer must exist
assertThat(account.getTransactions().size(), is(4));
assertThat(//
account.getTransactions().stream().filter(//
t -> t.getType() == AccountTransaction.Type.REMOVAL).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-02-01T00:00"))).findAny().isPresent(), is(true));
assertThat(//
account.getTransactions().stream().filter(//
t -> t.getType() == AccountTransaction.Type.DEPOSIT).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-01-01T00:00"))).findAny().isPresent(), is(true));
assertThat(//
account.getTransactions().stream().filter(//
t -> t.getType() == AccountTransaction.Type.DEPOSIT).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-03-01T00:00"))).findAny().isPresent(), is(true));
assertThat(//
account.getTransactions().stream().filter(//
t -> t.getType() == AccountTransaction.Type.TRANSFER_OUT).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-04-01T00:00"))).findAny().isPresent(), is(true));
}
Aggregations