Search in sources :

Example 11 with SecurityPrice

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)));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) ArrayList(java.util.ArrayList) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Security(name.abuchen.portfolio.model.Security) Test(org.junit.Test)

Example 12 with SecurityPrice

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)));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) ArrayList(java.util.ArrayList) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Security(name.abuchen.portfolio.model.Security) Test(org.junit.Test)

Example 13 with SecurityPrice

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)));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) ArrayList(java.util.ArrayList) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Security(name.abuchen.portfolio.model.Security) Test(org.junit.Test)

Example 14 with SecurityPrice

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++;
    }
}
Also used : SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Security(name.abuchen.portfolio.model.Security) DateTimeFormatter(java.time.format.DateTimeFormatter) LocalDate(java.time.LocalDate) Before(org.junit.Before)

Example 15 with SecurityPrice

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()));
}
Also used : LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Security(name.abuchen.portfolio.model.Security) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Aggregations

SecurityPrice (name.abuchen.portfolio.model.SecurityPrice)52 Security (name.abuchen.portfolio.model.Security)34 LocalDate (java.time.LocalDate)24 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)22 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)20 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)15 LatestSecurityPrice (name.abuchen.portfolio.model.LatestSecurityPrice)11 Client (name.abuchen.portfolio.model.Client)10 List (java.util.List)7 Values (name.abuchen.portfolio.money.Values)6 OpenDialogAction (name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction)6 MessageFormat (java.text.MessageFormat)5 BiFunction (java.util.function.BiFunction)5 Function (java.util.function.Function)5 Collectors (java.util.stream.Collectors)5 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)5 Taxonomy (name.abuchen.portfolio.model.Taxonomy)5 Watchlist (name.abuchen.portfolio.model.Watchlist)5 Factory (name.abuchen.portfolio.online.Factory)5