Search in sources :

Example 81 with PortfolioTransaction

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

the class FinTechGroupBankPDFExtractorTest method testWertpapierÜbertrag2.

@Test
public void testWertpapierÜbertrag2() throws IOException {
    FinTechGroupBankPDFExtractor extractor = new FinTechGroupBankPDFExtractor(new Client());
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "FlatexDepoteingang2.txt"), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(2));
    Optional<Item> item;
    // security
    item = results.stream().filter(i -> i instanceof SecurityItem).findFirst();
    assertThat(item.isPresent(), is(true));
    Security security = ((SecurityItem) item.get()).getSecurity();
    assertThat(security.getIsin(), is("DE000US9RGR9"));
    assertThat(security.getName(), is("UBS AG LONDON 14/16 RWE"));
    item = results.stream().filter(i -> i instanceof TransactionItem).findFirst();
    assertThat(item.isPresent(), is(true));
    assertThat(item.get().getSubject(), instanceOf(PortfolioTransaction.class));
    PortfolioTransaction entry = (PortfolioTransaction) item.get().getSubject();
    assertThat(entry.getType(), is(PortfolioTransaction.Type.DELIVERY_INBOUND));
    assertThat(entry.getAmount(), is(Values.Amount.factorize(7517.50)));
    assertThat(entry.getDateTime(), is(LocalDateTime.parse("2015-11-24T00:00")));
    assertThat(entry.getShares(), is(Values.Share.factorize(250)));
}
Also used : SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Item(name.abuchen.portfolio.datatransfer.Extractor.Item) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) FinTechGroupBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.FinTechGroupBankPDFExtractor) ArrayList(java.util.ArrayList) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) IOException(java.io.IOException) Test(org.junit.Test)

Example 82 with PortfolioTransaction

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

the class ConsorsbankPDFExtractorTest method testWertpapierVerkauf1.

@Test
public void testWertpapierVerkauf1() throws IOException {
    ConsorsbankPDFExtractor extractor = new ConsorsbankPDFExtractor(new Client());
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "ConsorsbankVerkauf1.txt"), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(2));
    // check security
    Security security = results.stream().filter(i -> i instanceof SecurityItem).findFirst().get().getSecurity();
    assertThat(security.getWkn(), is("A0DPR2"));
    assertThat(security.getName(), is("VOLKSWAGEN AG VZ ADR1/5"));
    new AssertImportActions().check(results, CurrencyUnit.EUR);
    // check buy sell transaction
    Item item = results.get(0);
    BuySellEntry entry = (BuySellEntry) item.getSubject();
    PortfolioTransaction t = entry.getPortfolioTransaction();
    assertThat(t.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 5794_56L)));
    assertThat(t.getUnitSum(Type.FEE), is(Money.of(CurrencyUnit.EUR, 26_65L)));
    assertThat(t.getUnitSum(Type.TAX), is(Money.of(CurrencyUnit.EUR, 226_79L)));
    assertThat(t.getDateTime(), is(LocalDateTime.of(2015, 2, 18, 12, 10, 30)));
    assertThat(t.getShares(), is(Values.Share.factorize(140)));
    assertThat(t.getGrossPricePerShare(), is(Quote.of(CurrencyUnit.EUR, Values.Quote.factorize(43.2))));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) Quote(name.abuchen.portfolio.money.Quote) Item(name.abuchen.portfolio.datatransfer.Extractor.Item) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) LocalDateTime(java.time.LocalDateTime) IsEmptyCollection.empty(org.hamcrest.collection.IsEmptyCollection.empty) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) ArrayList(java.util.ArrayList) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) Status(name.abuchen.portfolio.datatransfer.ImportAction.Status) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) CheckCurrenciesAction(name.abuchen.portfolio.datatransfer.actions.CheckCurrenciesAction) ConsorsbankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.ConsorsbankPDFExtractor) Account(name.abuchen.portfolio.model.Account) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Type(name.abuchen.portfolio.model.Transaction.Unit.Type) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) List(java.util.List) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) Unit(name.abuchen.portfolio.model.Transaction.Unit) Code(name.abuchen.portfolio.datatransfer.ImportAction.Status.Code) Optional(java.util.Optional) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) ConsorsbankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.ConsorsbankPDFExtractor) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) ArrayList(java.util.ArrayList) Security(name.abuchen.portfolio.model.Security) IOException(java.io.IOException) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) Item(name.abuchen.portfolio.datatransfer.Extractor.Item) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 83 with PortfolioTransaction

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

the class SecurityPositionTest method testFIFOPurchasePriceWithForex.

@Test
public void testFIFOPurchasePriceWithForex() {
    CurrencyConverter currencyConverter = new TestCurrencyConverter().with(CurrencyUnit.USD);
    Security security = new Security("", CurrencyUnit.USD);
    PortfolioTransaction t = new PortfolioTransaction();
    t.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
    t.setDateTime(LocalDateTime.parse("2017-01-25T00:00"));
    t.setShares(Values.Share.factorize(13));
    t.setSecurity(security);
    t.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(9659.24)));
    t.addUnit(new Unit(Unit.Type.GROSS_VALUE, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(9644.24)), Money.of(CurrencyUnit.USD, Values.Amount.factorize(10287.13)), BigDecimal.valueOf(0.937470704040499)));
    t.addUnit(new Unit(Unit.Type.FEE, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(15)), Money.of(CurrencyUnit.USD, Values.Amount.factorize(16)), BigDecimal.valueOf(0.937470704040499)));
    List<PortfolioTransaction> tx = new ArrayList<>();
    tx.add(t);
    SecurityPosition position = new SecurityPosition(security, currencyConverter, new SecurityPrice(), tx);
    assertThat(position.getShares(), is(13L * Values.Share.factor()));
    // 10287.13 / 13 = 791.32
    assertThat(position.getFIFOPurchasePrice(), is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(791.32))));
    assertThat(position.getMovingAveragePurchasePrice(), is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(791.32))));
    // 9659.24 EUR x ( 1 / 0.937470704040499) = 10303,51
    assertThat(position.getFIFOPurchaseValue(), is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(9659.24 * (1 / 0.937470704040499)))));
    Client client = new Client();
    client.addSecurity(security);
    Account a = new Account();
    client.addAccount(a);
    Portfolio p = new Portfolio();
    p.setReferenceAccount(a);
    p.addTransaction(t);
    client.addPortfolio(p);
    SecurityPerformanceSnapshot snapshot = SecurityPerformanceSnapshot.create(client, currencyConverter, new ReportingPeriod.FromXtoY(LocalDate.parse("2016-12-31"), LocalDate.parse("2017-02-01")));
    assertThat(snapshot.getRecords().size(), is(1));
    SecurityPerformanceRecord record = snapshot.getRecords().get(0);
    assertThat(record.getSecurity(), is(security));
    assertThat(record.getFifoCost(), is(position.getFIFOPurchaseValue()));
    assertThat(record.getFifoCostPerSharesHeld().toMoney(), is(position.getFIFOPurchasePrice()));
}
Also used : Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) ArrayList(java.util.ArrayList) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Security(name.abuchen.portfolio.model.Security) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 84 with PortfolioTransaction

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

the class SecurityPositionTest method testFIFOPurchasePrice.

@Test
public void testFIFOPurchasePrice() {
    List<PortfolioTransaction> tx = new ArrayList<PortfolioTransaction>();
    tx.add(new PortfolioTransaction(LocalDateTime.now(), CurrencyUnit.EUR, 100000, null, 100 * Values.Share.factor(), Type.BUY, 0, 0));
    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.getShares(), is(50L * Values.Share.factor()));
    assertThat(position.getFIFOPurchasePrice(), is(Money.of(CurrencyUnit.EUR, 10_00)));
    assertThat(position.getMovingAveragePurchasePrice(), is(Money.of(CurrencyUnit.EUR, 10_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 85 with PortfolioTransaction

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

the class SecurityPositionTest method testPurchasePriceWithMultipleBuyTransactionsMiddlePrice.

@Test
public void testPurchasePriceWithMultipleBuyTransactionsMiddlePrice() {
    List<PortfolioTransaction> tx = new ArrayList<PortfolioTransaction>();
    tx.add(new PortfolioTransaction(LocalDateTime.now(), CurrencyUnit.EUR, 75000, null, 75 * Values.Share.factor(), Type.BUY, 0, 0));
    tx.add(new PortfolioTransaction(LocalDateTime.now(), CurrencyUnit.EUR, 50000, null, 25 * 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, 15_00)));
    // expected: (750 + 500) * (50/100) / 50 (shares held)
    assertThat(position.getMovingAveragePurchasePrice(), is(Money.of(CurrencyUnit.EUR, 12_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)

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