use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class PortfolioClientFilterTest method testThatDividendTransactionAreIncluded.
@Test
public void testThatDividendTransactionAreIncluded() {
Portfolio portfolio = client.getPortfolios().get(0);
Client result = new PortfolioClientFilter(portfolio).filter(client);
assertThat(result.getPortfolios().size(), is(1));
assertThat(result.getAccounts().size(), is(1));
Account account = result.getAccounts().get(0);
assertThat(account.getTransactions().size(), is(2));
assertThat(account.getTransactions().stream().filter(t -> t.getType() == AccountTransaction.Type.DIVIDENDS).findAny().isPresent(), is(true));
assertThat(account.getTransactions().stream().filter(t -> t.getType() == AccountTransaction.Type.REMOVAL).findAny().isPresent(), is(true));
assertThat(AccountSnapshot.create(account, new TestCurrencyConverter(), LocalDate.parse("2016-09-03")).getFunds(), is(Money.of(CurrencyUnit.EUR, 0)));
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class PortfolioClientFilterTest method testThatFullReferenceAccountIsIncluded.
@Test
public void testThatFullReferenceAccountIsIncluded() {
Portfolio portfolio = client.getPortfolios().get(0);
Client result = new PortfolioClientFilter(portfolio, portfolio.getReferenceAccount()).filter(client);
assertThat(result.getPortfolios().size(), is(1));
assertThat(result.getAccounts().size(), is(1));
Account account = result.getAccounts().get(0);
// 3 transactions: buy, dividend, and deposit
assertThat(account.getTransactions().size(), is(3));
assertThat(account.getTransactions().stream().filter(t -> t.getType() == AccountTransaction.Type.BUY).findAny().isPresent(), is(true));
assertThat(account.getTransactions().stream().filter(t -> t.getType() == AccountTransaction.Type.DIVIDENDS).findAny().isPresent(), is(true));
assertThat(account.getTransactions().stream().filter(t -> t.getType() == AccountTransaction.Type.DEPOSIT).findAny().isPresent(), is(true));
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class PortfolioClientFilterTest method testCrossAccountTransfersAreConvertedIfAccountIsNotIncluded.
@Test
public void testCrossAccountTransfersAreConvertedIfAccountIsNotIncluded() {
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)).filter(client);
assertThat(result.getPortfolios(), empty());
assertThat(result.getAccounts().size(), is(1));
Account account = result.getAccounts().get(0);
// check that the 4 transactions are transformed:
// - buy -> removal
// - deposit
// - dividend -> deposit
// - transfer -> removal
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.REMOVAL).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-04-01T00:00"))).findAny().isPresent(), is(true));
// check other account
result = new PortfolioClientFilter(Collections.emptyList(), Arrays.asList(accountB)).filter(client);
assertThat(//
result.getAccounts().get(0).getTransactions().stream().filter(//
t -> t.getType() == AccountTransaction.Type.DEPOSIT).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-04-01T00:00"))).findAny().isPresent(), is(true));
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class PortfolioClientFilterTest method setupClient.
/**
* Creates three portfolios (A-C) with a reference account each.
*/
@Before
public void setupClient() {
client = new Client();
Security security = new SecurityBuilder().addTo(client);
// 2016-01-01 deposit
// 2016-02-01 buy
// 2016-03-01 dividend
Arrays.asList("A", "B", "C").forEach(index -> {
Account a = //
new AccountBuilder().deposit_("2016-01-01", Values.Amount.factorize(100)).dividend("2016-03-01", Values.Amount.factorize(10), //
security).addTo(client);
a.setName(index);
Portfolio p = //
new PortfolioBuilder(a).buy(security, "2016-02-01", Values.Share.factorize(1), Values.Amount.factorize(100)).addTo(client);
p.setName(index);
});
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ClientIndexTest method testThatPerformanceOfAnInvestmentIntoAnIndexIsIdenticalToIndex.
@Test
public void testThatPerformanceOfAnInvestmentIntoAnIndexIsIdenticalToIndex() {
LocalDate startDate = LocalDate.of(2012, 1, 1);
// a weekend
LocalDate endDate = LocalDate.of(2012, 4, 29);
long startPrice = Values.Quote.factorize(100);
Client client = new Client();
Security security = //
new SecurityBuilder().generatePrices(startPrice, startDate, //
endDate).addTo(client);
PortfolioBuilder portfolio = new PortfolioBuilder(new Account());
// add some buy transactions
LocalDate date = startDate;
while (date.isBefore(endDate)) {
// performance is only identical if the capital invested
// additionally has the identical performance on its first day -->
// use the closing quote of the previous day
long p = security.getSecurityPrice(date.minusDays(1)).getValue();
portfolio.inbound_delivery(security, date.atStartOfDay(), Values.Share.factorize(100), p);
date = date.plusDays(20);
}
portfolio.addTo(client);
ReportingPeriod.FromXtoY period = new ReportingPeriod.FromXtoY(startDate, endDate);
List<Exception> warnings = new ArrayList<Exception>();
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex index = PerformanceIndex.forClient(client, converter, period, warnings);
assertTrue(warnings.isEmpty());
double[] accumulated = index.getAccumulatedPercentage();
long lastPrice = security.getSecurityPrice(endDate).getValue();
assertThat((double) (lastPrice - startPrice) / (double) startPrice, IsCloseTo.closeTo(accumulated[accumulated.length - 1], PRECISION));
PerformanceIndex benchmark = PerformanceIndex.forSecurity(index, security);
assertThat(benchmark.getFinalAccumulatedPercentage(), IsCloseTo.closeTo(index.getFinalAccumulatedPercentage(), PRECISION));
}
Aggregations