use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class SecurityPositionTest method testPurchasePriceIfSharesArePartiallyTransferredOut.
@Test
public void testPurchasePriceIfSharesArePartiallyTransferredOut() {
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, 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.TestCurrencyConverter in project portfolio by buchen.
the class SecurityPositionTest method testThatTransferInDoesNotCountIfMatchingTransferOutIsIncluded.
@Test
public void testThatTransferInDoesNotCountIfMatchingTransferOutIsIncluded() {
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));
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.TestCurrencyConverter in project portfolio by buchen.
the class SecurityPositionTest method testSplittingPositionsWithForexGrossValue.
@Test
public void testSplittingPositionsWithForexGrossValue() {
Security security = new Security("", CurrencyUnit.EUR);
SecurityPrice price = new SecurityPrice(LocalDate.of(2016, Month.DECEMBER, 2), Values.Quote.factorize(10.19));
PortfolioTransaction inbound_delivery = new PortfolioTransaction();
inbound_delivery.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
inbound_delivery.setDateTime(LocalDateTime.parse("2016-01-01T00:00"));
inbound_delivery.setSecurity(security);
inbound_delivery.setMonetaryAmount(Money.of(CurrencyUnit.USD, Values.Amount.factorize(27409.55)));
inbound_delivery.setShares(Values.Share.factorize(2415.794));
Unit grossValue = new //
Unit(//
Unit.Type.GROSS_VALUE, Money.of(CurrencyUnit.USD, Values.Amount.factorize(27409.55)), Money.of(CurrencyUnit.EUR, Values.Amount.factorize(24616.95)), BigDecimal.valueOf(1.1134421608));
inbound_delivery.addUnit(grossValue);
SecurityPosition position = new SecurityPosition(security, new TestCurrencyConverter(), price, Arrays.asList(inbound_delivery));
// 20%
SecurityPosition third = SecurityPosition.split(position, 20 * Values.Weight.factor());
// 24616.95 EUR * 0.2 = 4923,39 EUR
assertThat(third.getFIFOPurchaseValue(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(4923.39))));
assertThat(third.getFIFOPurchaseValue(), is(Money.of(CurrencyUnit.EUR, Math.round(position.getFIFOPurchaseValue().getAmount() * 0.2))));
assertThat(third.getMovingAveragePurchaseValue(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(4923.39))));
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class SecurityPositionTest method testPurchasePriceNaNIfOnlySellTransactions.
@Test
public void testPurchasePriceNaNIfOnlySellTransactions() {
SecurityPosition position = new SecurityPosition(new Security(), new TestCurrencyConverter(), new SecurityPrice(), //
Arrays.asList(new PortfolioTransaction(LocalDateTime.now(), CurrencyUnit.EUR, 500_00, null, 50 * Values.Share.factor(), Type.SELL, 0, 0)));
assertThat(position.getShares(), is(-50L * Values.Share.factor()));
assertThat(position.getFIFOPurchasePrice(), is(Money.of(CurrencyUnit.EUR, 0)));
assertThat(position.getMovingAveragePurchasePrice(), is(Money.of(CurrencyUnit.EUR, 0)));
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class SecurityPositionTest method testThatOnlyMatchingTransfersAreRemoved_InRemains.
@Test
public void testThatOnlyMatchingTransfersAreRemoved_InRemains() {
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, 50 * Values.Share.factor(), Type.TRANSFER_IN, 0, 0));
SecurityPosition position = new SecurityPosition(new Security(), new TestCurrencyConverter(), price, tx);
assertThat(position.getShares(), is(100L * Values.Share.factor()));
assertThat(position.getFIFOPurchasePrice(), is(Money.of(CurrencyUnit.EUR, 10_50)));
assertThat(position.getFIFOPurchaseValue(), is(Money.of(CurrencyUnit.EUR, 1050_00)));
assertThat(position.getMovingAveragePurchasePrice(), is(Money.of(CurrencyUnit.EUR, 10_50)));
assertThat(position.getMovingAveragePurchaseValue(), is(Money.of(CurrencyUnit.EUR, 1050_00)));
assertThat(position.calculateValue(), is(Money.of(CurrencyUnit.EUR, 2000_00)));
assertThat(position.getProfitLoss(), is(Money.of(CurrencyUnit.EUR, 950_00)));
}
Aggregations