Search in sources :

Example 46 with PortfolioTransaction

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

Example 47 with PortfolioTransaction

use of name.abuchen.portfolio.model.PortfolioTransaction 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 48 with PortfolioTransaction

use of name.abuchen.portfolio.model.PortfolioTransaction 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 49 with PortfolioTransaction

use of name.abuchen.portfolio.model.PortfolioTransaction 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 50 with PortfolioTransaction

use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.

the class IRRCalculationTest method testDividendPaymentsWithTaxes.

@Test
public void testDividendPaymentsWithTaxes() {
    List<Transaction> tx = new ArrayList<>();
    Security security = new Security();
    tx.add(new // 
    PortfolioTransaction(// 
    LocalDateTime.of(2015, Month.DECEMBER, 31, 0, 0), // 
    CurrencyUnit.EUR, // 
    Values.Amount.factorize(1000), // 
    security, // 
    Values.Share.factorize(10), // 
    PortfolioTransaction.Type.BUY, Values.Amount.factorize(10), 0));
    DividendTransaction t = new DividendTransaction();
    t.setDateTime(LocalDateTime.parse("2016-06-01T00:00"));
    t.setSecurity(security);
    t.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100)));
    t.setShares(Values.Share.factorize(10));
    t.addUnit(new Unit(Unit.Type.TAX, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(50))));
    tx.add(t);
    tx.add(new // 
    PortfolioTransaction(// 
    LocalDateTime.of(2016, Month.DECEMBER, 31, 0, 0), // 
    CurrencyUnit.EUR, // 
    Values.Amount.factorize(1200), // 
    security, // 
    Values.Share.factorize(10), // 
    PortfolioTransaction.Type.SELL, Values.Amount.factorize(10), Values.Amount.factorize(30)));
    IRRCalculation calculation = Calculation.perform(IRRCalculation.class, new TestCurrencyConverter(), tx);
    // Excel verification
    // 31.12.15 -1000
    // 01.06.16 150
    // 31.12.16 1230
    // =XINTZINSFUSS(B1:B3;A1:A3) = 0,412128788
    assertThat(calculation.getIRR(), IsCloseTo.closeTo(0.412128788d, 0.00000001d));
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.model.Transaction) ArrayList(java.util.ArrayList) Security(name.abuchen.portfolio.model.Security) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit) Test(org.junit.Test)

Aggregations

PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)131 Security (name.abuchen.portfolio.model.Security)85 Test (org.junit.Test)84 Client (name.abuchen.portfolio.model.Client)70 ArrayList (java.util.ArrayList)64 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)64 Unit (name.abuchen.portfolio.model.Transaction.Unit)56 Money (name.abuchen.portfolio.money.Money)56 IOException (java.io.IOException)47 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)44 List (java.util.List)43 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)42 Values (name.abuchen.portfolio.money.Values)41 LocalDateTime (java.time.LocalDateTime)39 Portfolio (name.abuchen.portfolio.model.Portfolio)39 CoreMatchers.is (org.hamcrest.CoreMatchers.is)35 Assert.assertThat (org.junit.Assert.assertThat)35 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)33 Collectors (java.util.stream.Collectors)30 BuySellEntryItem (name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem)28