use of name.abuchen.portfolio.model.SecurityPrice 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)));
}
use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.
the class SecurityPositionTest method testPurchasePriceWithMultipleBuyTransactions.
@Test
public void testPurchasePriceWithMultipleBuyTransactions() {
List<PortfolioTransaction> tx = new ArrayList<PortfolioTransaction>();
tx.add(new PortfolioTransaction(LocalDateTime.now(), CurrencyUnit.EUR, 25000, null, 25 * Values.Share.factor(), Type.BUY, 0, 0));
tx.add(new PortfolioTransaction(LocalDateTime.now(), CurrencyUnit.EUR, 150000, null, 75 * 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, 20_00)));
// expected: (250 + 1500) * (50/100) / 50 (shares held)
assertThat(position.getMovingAveragePurchasePrice(), is(Money.of(CurrencyUnit.EUR, 17_50)));
}
use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.
the class SecurityPositionTest method testThatTransferInCountsIfTransferOutIsMissingPlusBuyTransaction.
@Test
public void testThatTransferInCountsIfTransferOutIsMissingPlusBuyTransaction() {
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_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)));
}
use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.
the class SimpleMovingAverageTest method prepareSecurity.
@Before
public void prepareSecurity() {
securityOnePrice = new Security();
securityTenPrices = new Security();
SecurityPrice price = new SecurityPrice();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
formatter = formatter.withLocale(Locale.GERMANY);
LocalDate date = LocalDate.parse("01.01.2017", formatter);
price.setDate(date);
price.setValue(0);
securityOnePrice.addPrice(price);
int i = 1;
while (i <= 10) {
if (i < 10)
date = LocalDate.parse("0" + i + ".01.2017", formatter);
else
date = LocalDate.parse(i + ".01.2017", formatter);
price = new SecurityPrice();
price.setDate(date);
price.setValue(i);
securityTenPrices.addPrice(price);
i++;
}
}
use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.
the class YahooFinanceQuoteFeedTest method testCalculateDate.
@Test
public void testCalculateDate() throws IOException {
YahooFinanceQuoteFeed feed = new YahooFinanceQuoteFeed();
Security security = new Security();
security.setName("Daimler AG");
security.setIsin("DE0007100000");
security.setTickerSymbol("DAI.DE");
LocalDate nineteenHundred = LocalDate.of(1900, 1, 1);
LocalDate date = feed.caculateStart(security);
assertThat(date, equalTo(nineteenHundred));
security.addPrice(new SecurityPrice(LocalDate.now(), 100));
date = feed.caculateStart(security);
assertThat(date, equalTo(LocalDate.now()));
}
Aggregations