use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.
the class SecurityPositionTest method testPurchasePriceWithMultipleBuyTransactionsMiddlePrice.
@Test
public void testPurchasePriceWithMultipleBuyTransactionsMiddlePrice() {
List<PortfolioTransaction> tx = new ArrayList<PortfolioTransaction>();
tx.add(new PortfolioTransaction(LocalDateTime.now(), CurrencyUnit.EUR, 75000, null, 75 * Values.Share.factor(), Type.BUY, 0, 0));
tx.add(new PortfolioTransaction(LocalDateTime.now(), CurrencyUnit.EUR, 50000, null, 25 * Values.Share.factor(), Type.BUY, 0, 0));
tx.add(new PortfolioTransaction(LocalDateTime.now(), CurrencyUnit.EUR, 100000, null, 50 * Values.Share.factor(), Type.SELL, 0, 0));
SecurityPosition position = new SecurityPosition(new Security(), new TestCurrencyConverter(), new SecurityPrice(), tx);
assertThat(position.getShares(), is(50L * Values.Share.factor()));
assertThat(position.getFIFOPurchasePrice(), is(Money.of(CurrencyUnit.EUR, 15_00)));
// expected: (750 + 500) * (50/100) / 50 (shares held)
assertThat(position.getMovingAveragePurchasePrice(), is(Money.of(CurrencyUnit.EUR, 12_50)));
}
use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.
the class SecurityPositionTest method testThatTransferInCountsIfTransferOutIsMissing.
@Test
public void testThatTransferInCountsIfTransferOutIsMissing() {
SecurityPrice price = new SecurityPrice(LocalDate.of(2012, Month.DECEMBER, 2), Values.Quote.factorize(20));
List<PortfolioTransaction> tx = new ArrayList<PortfolioTransaction>();
tx.add(new PortfolioTransaction(LocalDateTime.of(2012, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 50000, null, 50 * Values.Share.factor(), Type.TRANSFER_IN, 0, 0));
SecurityPosition position = new SecurityPosition(new Security(), new TestCurrencyConverter(), price, tx);
assertThat(position.getShares(), is(50L * Values.Share.factor()));
assertThat(position.getFIFOPurchasePrice(), is(Money.of(CurrencyUnit.EUR, 10_00)));
assertThat(position.getFIFOPurchaseValue(), is(Money.of(CurrencyUnit.EUR, 500_00)));
assertThat(position.getMovingAveragePurchasePrice(), is(Money.of(CurrencyUnit.EUR, 10_00)));
assertThat(position.getMovingAveragePurchaseValue(), is(Money.of(CurrencyUnit.EUR, 500_00)));
assertThat(position.calculateValue(), is(Money.of(CurrencyUnit.EUR, 1000_00)));
assertThat(position.getProfitLoss(), is(Money.of(CurrencyUnit.EUR, 500_00)));
}
use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.
the class SecurityPositionTest method testThatOnlyMatchingTransfersAreRemoved_OutRemains.
@Test
public void testThatOnlyMatchingTransfersAreRemoved_OutRemains() {
SecurityPrice price = new SecurityPrice(LocalDate.of(2012, Month.DECEMBER, 2), Values.Quote.factorize(20));
List<PortfolioTransaction> tx = new ArrayList<PortfolioTransaction>();
tx.add(new PortfolioTransaction(LocalDateTime.of(2012, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 50000, null, 50 * Values.Share.factor(), Type.BUY, 0, 0));
tx.add(new PortfolioTransaction(LocalDateTime.of(2012, Month.FEBRUARY, 1, 0, 0), CurrencyUnit.EUR, 55000, null, 50 * Values.Share.factor(), Type.TRANSFER_OUT, 0, 0));
tx.add(new PortfolioTransaction(LocalDateTime.of(2012, Month.FEBRUARY, 1, 0, 0), CurrencyUnit.EUR, 55000, null, 50 * Values.Share.factor(), Type.TRANSFER_IN, 0, 0));
tx.add(new PortfolioTransaction(LocalDateTime.of(2012, Month.FEBRUARY, 2, 0, 0), CurrencyUnit.EUR, 55000, null, 25 * Values.Share.factor(), Type.TRANSFER_OUT, 0, 0));
SecurityPosition position = new SecurityPosition(new Security(), new TestCurrencyConverter(), price, tx);
assertThat(position.getShares(), is(25L * Values.Share.factor()));
assertThat(position.getFIFOPurchasePrice(), is(Money.of(CurrencyUnit.EUR, 10_00)));
assertThat(position.getFIFOPurchaseValue(), is(Money.of(CurrencyUnit.EUR, 250_00)));
assertThat(position.getMovingAveragePurchasePrice(), is(Money.of(CurrencyUnit.EUR, 10_00)));
assertThat(position.getMovingAveragePurchaseValue(), is(Money.of(CurrencyUnit.EUR, 250_00)));
assertThat(position.calculateValue(), is(Money.of(CurrencyUnit.EUR, 500_00)));
assertThat(position.getProfitLoss(), is(Money.of(CurrencyUnit.EUR, 250_00)));
}
use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.
the class SecurityPositionTest method testFIFOPurchasePriceWithOnlySell.
@Test
public void testFIFOPurchasePriceWithOnlySell() {
List<PortfolioTransaction> tx = new ArrayList<PortfolioTransaction>();
tx.add(new PortfolioTransaction(LocalDateTime.now(), CurrencyUnit.EUR, 50000, null, 50 * Values.Share.factor(), Type.SELL, 0, 0));
SecurityPosition position = new SecurityPosition(new Security(), new TestCurrencyConverter(), new SecurityPrice(), tx);
assertThat(position.getFIFOPurchasePrice(), is(Money.of(CurrencyUnit.EUR, 0)));
assertThat(position.getMovingAveragePurchasePrice(), is(Money.of(CurrencyUnit.EUR, 0)));
}
use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.
the class ClientPerformanceSnapshotTest method testCapitalGainsWithBuyDuringReportPeriod.
@Test
public void testCapitalGainsWithBuyDuringReportPeriod() {
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));
portfolio.addTransaction(new PortfolioTransaction(LocalDateTime.of(2011, Month.JANUARY, 15, 0, 0), CurrencyUnit.EUR, 99_00, security, Values.Share.factorize(1), PortfolioTransaction.Type.DELIVERY_INBOUND, 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 + (110_00 - 99_00))));
assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1210_00)));
assertThat(snapshot.getAbsoluteDelta(), is(snapshot.getValue(CategoryType.FINAL_VALUE).subtract(snapshot.getValue(CategoryType.TRANSFERS)).subtract(snapshot.getValue(CategoryType.INITIAL_VALUE))));
}
Aggregations