use of name.abuchen.portfolio.model.AccountTransaction in project portfolio by buchen.
the class CSVAccountTransactionExtractorTest method testTypeIsDeterminedByNegativeUnaryMinusOperator.
@Test
public void testTypeIsDeterminedByNegativeUnaryMinusOperator() {
Client client = new Client();
CSVExtractor extractor = new CSVAccountTransactionExtractor(client);
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(0, Arrays.<String[]>asList(new String[] { "2013-01-01", "", "", "", "-100", "EUR", "", "", "10", "Notiz" }), buildField2Column(extractor), errors);
assertThat(errors, empty());
assertThat(results.size(), is(1));
AccountTransaction t = (AccountTransaction) results.get(0).getSubject();
assertThat(t.getType(), is(AccountTransaction.Type.REMOVAL));
assertThat(t.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 100_00)));
assertThat(t.getNote(), is("Notiz"));
assertThat(t.getDateTime(), is(LocalDateTime.parse("2013-01-01T00:00")));
assertThat(t.getShares(), is(0L));
assertThat(t.getSecurity(), is(nullValue()));
}
use of name.abuchen.portfolio.model.AccountTransaction in project portfolio by buchen.
the class SBrokerPDFExtractorTest method testErtragsgutschrift1.
@Test
public void testErtragsgutschrift1() throws IOException {
SBrokerPDFExtractor extractor = new SBrokerPDFExtractor(new Client());
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "sBroker_Ertragsgutschrift1.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.getIsin(), is("DE000A0H0785"));
assertThat(security.getName(), is("iS.EO G.B.C.1.5-10.5y.U.ETF DE"));
// check buy sell transaction
AccountTransaction t = (AccountTransaction) results.stream().filter(i -> i instanceof TransactionItem).findFirst().get().getSubject();
assertThat(t.getType(), is(AccountTransaction.Type.DIVIDENDS));
assertThat(t.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 12_70)));
assertThat(t.getDateTime(), is(LocalDateTime.parse("2014-11-17T00:00")));
assertThat(t.getShares(), is(Values.Share.factorize(16)));
}
use of name.abuchen.portfolio.model.AccountTransaction in project portfolio by buchen.
the class AccountBuilder method dividend.
public AccountBuilder dividend(String date, long amount, Security security) {
AccountTransaction t = new AccountTransaction(asDateTime(date), account.getCurrencyCode(), amount, security, Type.DIVIDENDS);
account.addTransaction(t);
return this;
}
use of name.abuchen.portfolio.model.AccountTransaction in project portfolio by buchen.
the class ClientPerformanceSnapshot method determineTransferAmount.
/**
* Determine the monetary amount when transferring cash between accounts.
* Because the actual exchange rate of the transferal might differ from the
* historical rate given by the exchange rate provider (e.g. ECB), we would
* get rounding differences if we do not take the original amount. If the
* transferal does not involve the term currency at all, we calculate the
* average value out of both converted amounts.
*/
private Money determineTransferAmount(AccountTransaction t) {
if (converter.getTermCurrency().equals(t.getCurrencyCode()))
return t.getMonetaryAmount();
Transaction other = t.getCrossEntry().getCrossTransaction(t);
if (converter.getTermCurrency().equals(other.getCurrencyCode()))
return other.getMonetaryAmount();
MutableMoney m = MutableMoney.of(converter.getTermCurrency());
m.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
m.add(other.getMonetaryAmount().with(converter.at(t.getDateTime())));
return m.divide(2).toMoney();
}
use of name.abuchen.portfolio.model.AccountTransaction in project portfolio by buchen.
the class ClientPerformanceSnapshot method addEarnings.
private void addEarnings() {
MutableMoney mEarnings = MutableMoney.of(converter.getTermCurrency());
MutableMoney mOtherEarnings = MutableMoney.of(converter.getTermCurrency());
MutableMoney mFees = MutableMoney.of(converter.getTermCurrency());
MutableMoney mTaxes = MutableMoney.of(converter.getTermCurrency());
MutableMoney mDeposits = MutableMoney.of(converter.getTermCurrency());
MutableMoney mRemovals = MutableMoney.of(converter.getTermCurrency());
Map<Security, MutableMoney> earningsBySecurity = new HashMap<>();
for (Account account : client.getAccounts()) {
for (AccountTransaction t : account.getTransactions()) {
if (!period.containsTransaction().test(t))
continue;
switch(t.getType()) {
case DIVIDENDS:
case INTEREST:
addEarningTransaction(account, t, mEarnings, mOtherEarnings, mTaxes, earningsBySecurity);
break;
case INTEREST_CHARGE:
Money charged = t.getMonetaryAmount().with(converter.at(t.getDateTime()));
mEarnings.subtract(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
earnings.add(new TransactionPair<AccountTransaction>(account, t));
mOtherEarnings.subtract(charged);
break;
case DEPOSIT:
mDeposits.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
break;
case REMOVAL:
mRemovals.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
break;
case FEES:
mFees.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
fees.add(new TransactionPair<AccountTransaction>(account, t));
break;
case FEES_REFUND:
mFees.subtract(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
fees.add(new TransactionPair<AccountTransaction>(account, t));
break;
case TAXES:
mTaxes.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
taxes.add(new TransactionPair<AccountTransaction>(account, t));
break;
case TAX_REFUND:
mTaxes.subtract(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
taxes.add(new TransactionPair<AccountTransaction>(account, t));
break;
case BUY:
case SELL:
case TRANSFER_IN:
case TRANSFER_OUT:
// no operation
break;
default:
throw new UnsupportedOperationException();
}
}
}
for (Portfolio portfolio : client.getPortfolios()) {
for (PortfolioTransaction t : portfolio.getTransactions()) {
if (!period.containsTransaction().test(t))
continue;
Money unit = t.getUnitSum(Unit.Type.FEE, converter);
if (!unit.isZero()) {
mFees.add(unit);
fees.add(new TransactionPair<PortfolioTransaction>(portfolio, t));
}
unit = t.getUnitSum(Unit.Type.TAX, converter);
if (!unit.isZero()) {
mTaxes.add(unit);
taxes.add(new TransactionPair<PortfolioTransaction>(portfolio, t));
}
switch(t.getType()) {
case DELIVERY_INBOUND:
mDeposits.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
break;
case DELIVERY_OUTBOUND:
mRemovals.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
break;
case BUY:
case SELL:
case TRANSFER_IN:
case TRANSFER_OUT:
break;
default:
throw new UnsupportedOperationException();
}
}
}
Category earningsCategory = categories.get(CategoryType.EARNINGS);
earningsCategory.valuation = mEarnings.toMoney();
earningsCategory.positions = earningsBySecurity.entrySet().stream().filter(entry -> !entry.getValue().isZero()).map(entry -> new Position(entry.getKey(), entry.getValue().toMoney())).sorted(//
(p1, p2) -> p1.getLabel().compareToIgnoreCase(p2.getLabel())).collect(Collectors.toList());
if (!mOtherEarnings.isZero())
earningsCategory.positions.add(new Position(Messages.LabelInterest, mOtherEarnings.toMoney()));
categories.get(CategoryType.FEES).valuation = mFees.toMoney();
categories.get(CategoryType.TAXES).valuation = mTaxes.toMoney();
categories.get(CategoryType.TRANSFERS).valuation = mDeposits.toMoney().subtract(mRemovals.toMoney());
categories.get(CategoryType.TRANSFERS).positions.add(new Position(Messages.LabelDeposits, mDeposits.toMoney()));
categories.get(CategoryType.TRANSFERS).positions.add(new Position(Messages.LabelRemovals, mRemovals.toMoney()));
}
Aggregations