use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class CSVPortfolioTransactionExtractorTest method testBuyTransactionWithForex.
@Test
public void testBuyTransactionWithForex() throws ParseException {
Client client = new Client();
Security security = new Security();
security.setTickerSymbol("SAP.DE");
security.setCurrencyCode("USD");
client.addSecurity(security);
CSVExtractor extractor = new CSVPortfolioTransactionExtractor(client);
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(0, Arrays.<String[]>asList(new String[] { "2013-01-02", "DE0007164600", "SAP.DE", "", "SAP SE", "-100", "EUR", "", "12", "110", "USD", "0,9091", "1,9", "SELL", "Notiz" }), buildField2Column(extractor), errors);
assertThat(errors, empty());
assertThat(results.size(), is(1));
new AssertImportActions().check(results, CurrencyUnit.EUR);
BuySellEntry entry = (BuySellEntry) results.stream().filter(i -> i instanceof BuySellEntryItem).findAny().get().getSubject();
PortfolioTransaction t = entry.getPortfolioTransaction();
assertThat(t.getType(), is(PortfolioTransaction.Type.SELL));
assertThat(t.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 100_00)));
assertThat(t.getSecurity(), is(security));
assertThat(t.getUnitSum(Unit.Type.TAX), is(Money.of("EUR", 12_00)));
assertThat(t.getUnit(Unit.Type.FEE).isPresent(), is(false));
Unit grossAmount = t.getUnit(Unit.Type.GROSS_VALUE).get();
assertThat(grossAmount.getAmount(), is(Money.of("EUR", 100_00)));
assertThat(grossAmount.getForex(), is(Money.of("USD", 110_00)));
assertThat(grossAmount.getExchangeRate(), is(BigDecimal.valueOf(0.9091)));
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class DeutscheBankPDFExtractorTest method testErtragsgutschrift2.
@Test
public void testErtragsgutschrift2() throws IOException {
DeutscheBankPDFExtractor extractor = new DeutscheBankPDFExtractor(new Client());
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "DeutscheBankErtragsgutschrift2.txt"), errors);
assertThat(errors, empty());
assertThat(results.size(), is(2));
new AssertImportActions().check(results, CurrencyUnit.EUR);
// check security
Security security = results.stream().filter(i -> i instanceof SecurityItem).findFirst().get().getSecurity();
assertThat(security.getName(), is("ISHS-MSCI N. AMERIC.UCITS ETF BE.SH.(DT.ZT.)"));
assertThat(security.getIsin(), is("DE000A0J2060"));
assertThat(security.getWkn(), is("A0J206"));
assertThat(security.getCurrencyCode(), is("USD"));
// check transaction
Optional<Item> item = results.stream().filter(i -> i instanceof TransactionItem).findFirst();
assertThat(item.isPresent(), is(true));
assertThat(item.get().getSubject(), instanceOf(AccountTransaction.class));
AccountTransaction transaction = (AccountTransaction) item.get().getSubject();
assertThat(transaction.getType(), is(AccountTransaction.Type.DIVIDENDS));
assertThat(transaction.getSecurity(), is(security));
assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2015-03-24T00:00")));
assertThat(transaction.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 16_17L)));
assertThat(transaction.getShares(), is(Values.Share.factorize(123)));
Optional<Unit> grossValue = transaction.getUnit(Unit.Type.GROSS_VALUE);
assertThat(grossValue.isPresent(), is(true));
assertThat(grossValue.get().getAmount(), is(Money.of("EUR", 16_17L)));
assertThat(grossValue.get().getForex(), is(Money.of("USD", 17_38L)));
assertThat(grossValue.get().getExchangeRate().doubleValue(), IsCloseTo.closeTo(0.930578, 0.000001));
}
use of name.abuchen.portfolio.model.Transaction.Unit 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()));
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class CheckCurrenciesAccountTransactionTest method testCheckTransactionUnitIfCurrenciesAreEqual.
@Test
public void testCheckTransactionUnitIfCurrenciesAreEqual() {
Account account = new Account();
account.setCurrencyCode("EUR");
Security security = new Security("", "EUR");
AccountTransaction t = new AccountTransaction();
t.setMonetaryAmount(Money.of("EUR", 1_00));
t.setSecurity(security);
assertThat(action.process(t, account).getCode(), is(Status.Code.OK));
Unit unit = new Unit(Unit.Type.GROSS_VALUE, Money.of("EUR", 1_00), Money.of("USD", 2_00), BigDecimal.valueOf(0.5));
t.addUnit(unit);
assertThat(action.process(t, account).getCode(), is(Status.Code.ERROR));
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class CheckCurrenciesAccountTransactionTest method testCheckTransactionUnitIfCurrenciesAreDifferent.
@Test
public void testCheckTransactionUnitIfCurrenciesAreDifferent() {
Account account = new Account();
account.setCurrencyCode("EUR");
Security security = new Security("", "USD");
Unit unit = new Unit(Unit.Type.GROSS_VALUE, Money.of("EUR", 1_00), Money.of("USD", 2_00), BigDecimal.valueOf(0.5));
AccountTransaction t = new AccountTransaction();
t.setMonetaryAmount(Money.of("EUR", 1_00));
t.setSecurity(security);
t.addUnit(unit);
assertThat(action.process(t, account).getCode(), is(Status.Code.OK));
t.removeUnit(unit);
assertThat(action.process(t, account).getCode(), is(Status.Code.ERROR));
Unit other = new Unit(Unit.Type.GROSS_VALUE, Money.of("EUR", 1_00), Money.of("JPY", 2_00), BigDecimal.valueOf(0.5));
t.addUnit(other);
assertThat(action.process(t, account).getCode(), is(Status.Code.ERROR));
}
Aggregations