use of name.abuchen.portfolio.model.PortfolioTransaction 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.PortfolioTransaction 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.PortfolioTransaction 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.PortfolioTransaction in project portfolio by buchen.
the class TransactionComparatorTest method testTwoInboundTransactionsStay.
@Test
public void testTwoInboundTransactionsStay() {
Portfolio portfolio = //
new PortfolioBuilder().buy(security, "2010-01-01", 1, //
100).buy(security, "2010-01-01", 2, //
100).addTo(client);
List<PortfolioTransaction> list = portfolio.getTransactions();
Collections.sort(list, new TransactionComparator());
assertThat(list.get(0).getShares(), is(1L));
assertThat(list.get(1).getShares(), is(2L));
}
use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class TransactionComparatorTest method testBuyIsPreferredOverSell2.
@Test
public void testBuyIsPreferredOverSell2() {
Portfolio portfolio = //
new PortfolioBuilder().buy(security, "2010-01-01", 100, //
100).sell(security, "2010-01-01", 100, //
100).addTo(client);
List<PortfolioTransaction> list = portfolio.getTransactions();
Collections.sort(list, new TransactionComparator());
assertThat(list.get(0).getType(), is(Type.BUY));
assertThat(list.get(1).getType(), is(Type.SELL));
}
Aggregations