use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class SecurityPositionTest method testFIFOPurchasePriceWithForex.
@Test
public void testFIFOPurchasePriceWithForex() {
CurrencyConverter currencyConverter = new TestCurrencyConverter().with(CurrencyUnit.USD);
Security security = new Security("", CurrencyUnit.USD);
PortfolioTransaction t = new PortfolioTransaction();
t.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
t.setDateTime(LocalDateTime.parse("2017-01-25T00:00"));
t.setShares(Values.Share.factorize(13));
t.setSecurity(security);
t.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(9659.24)));
t.addUnit(new Unit(Unit.Type.GROSS_VALUE, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(9644.24)), Money.of(CurrencyUnit.USD, Values.Amount.factorize(10287.13)), BigDecimal.valueOf(0.937470704040499)));
t.addUnit(new Unit(Unit.Type.FEE, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(15)), Money.of(CurrencyUnit.USD, Values.Amount.factorize(16)), BigDecimal.valueOf(0.937470704040499)));
List<PortfolioTransaction> tx = new ArrayList<>();
tx.add(t);
SecurityPosition position = new SecurityPosition(security, currencyConverter, new SecurityPrice(), tx);
assertThat(position.getShares(), is(13L * Values.Share.factor()));
// 10287.13 / 13 = 791.32
assertThat(position.getFIFOPurchasePrice(), is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(791.32))));
assertThat(position.getMovingAveragePurchasePrice(), is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(791.32))));
// 9659.24 EUR x ( 1 / 0.937470704040499) = 10303,51
assertThat(position.getFIFOPurchaseValue(), is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(9659.24 * (1 / 0.937470704040499)))));
Client client = new Client();
client.addSecurity(security);
Account a = new Account();
client.addAccount(a);
Portfolio p = new Portfolio();
p.setReferenceAccount(a);
p.addTransaction(t);
client.addPortfolio(p);
SecurityPerformanceSnapshot snapshot = SecurityPerformanceSnapshot.create(client, currencyConverter, new ReportingPeriod.FromXtoY(LocalDate.parse("2016-12-31"), LocalDate.parse("2017-02-01")));
assertThat(snapshot.getRecords().size(), is(1));
SecurityPerformanceRecord record = snapshot.getRecords().get(0);
assertThat(record.getSecurity(), is(security));
assertThat(record.getFifoCost(), is(position.getFIFOPurchaseValue()));
assertThat(record.getFifoCostPerSharesHeld().toMoney(), is(position.getFIFOPurchasePrice()));
}
use of name.abuchen.portfolio.model.Portfolio 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.Portfolio in project portfolio by buchen.
the class PortfolioClientFilterTest method testCrossPortfolioTransfersAreKept.
@Test
public void testCrossPortfolioTransfersAreKept() {
Portfolio portfolioA = client.getPortfolios().get(0);
Portfolio portfolioB = client.getPortfolios().get(1);
PortfolioTransferEntry entry = new PortfolioTransferEntry(portfolioA, portfolioB);
entry.setDate(LocalDateTime.parse("2016-04-01T00:00"));
entry.setAmount(Values.Amount.factorize(10));
entry.setShares(Values.Share.factorize(1));
entry.setSecurity(client.getSecurities().get(0));
entry.insert();
Client result = new PortfolioClientFilter(Arrays.asList(portfolioA, portfolioB), Collections.emptyList()).filter(client);
assertThat(result.getPortfolios().size(), is(2));
assertThat(result.getAccounts().size(), is(2));
Portfolio portfolio = result.getPortfolios().get(0);
// check that the 4 transactions are transformed:
// - buy -> inbound delivery
// - transfer must exist
assertThat(portfolio.getTransactions().size(), is(2));
assertThat(//
portfolio.getTransactions().stream().filter(//
t -> t.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-02-01T00:00"))).findAny().isPresent(), is(true));
assertThat(//
portfolio.getTransactions().stream().filter(//
t -> t.getType() == PortfolioTransaction.Type.TRANSFER_OUT).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-04-01T00:00"))).findAny().isPresent(), is(true));
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class PortfolioClientFilterTest method testCrossPortfolioTransfersAreConvertedToDeliveries.
@Test
public void testCrossPortfolioTransfersAreConvertedToDeliveries() {
Portfolio portfolioA = client.getPortfolios().get(0);
Portfolio portfolioB = client.getPortfolios().get(1);
PortfolioTransferEntry entry = new PortfolioTransferEntry(portfolioA, portfolioB);
entry.setDate(LocalDateTime.parse("2016-04-01T00:00"));
entry.setAmount(Values.Amount.factorize(10));
entry.setShares(Values.Share.factorize(1));
entry.setSecurity(client.getSecurities().get(0));
entry.insert();
Client result = new PortfolioClientFilter(Arrays.asList(portfolioA), Collections.emptyList()).filter(client);
assertThat(result.getPortfolios().size(), is(1));
assertThat(result.getAccounts().size(), is(1));
Portfolio portfolio = result.getPortfolios().get(0);
// check that the 4 transactions are transformed:
// - buy -> inbound delivery
// - transfer -> outbound delivery
assertThat(portfolio.getTransactions().size(), is(2));
assertThat(//
portfolio.getTransactions().stream().filter(//
t -> t.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-02-01T00:00"))).findAny().isPresent(), is(true));
assertThat(//
portfolio.getTransactions().stream().filter(//
t -> t.getType() == PortfolioTransaction.Type.DELIVERY_OUTBOUND).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-04-01T00:00"))).findAny().isPresent(), is(true));
// check the other portfolio
result = new PortfolioClientFilter(Arrays.asList(portfolioB), Collections.emptyList()).filter(client);
assertThat(//
result.getPortfolios().get(0).getTransactions().stream().filter(//
t -> t.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-04-01T00:00"))).findAny().isPresent(), is(true));
}
use of name.abuchen.portfolio.model.Portfolio 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));
}
Aggregations