use of name.abuchen.portfolio.money.MutableMoney in project portfolio by buchen.
the class ComdirectPDFExtractor method addBuyTransaction.
@SuppressWarnings("nls")
private void addBuyTransaction() {
DocumentType type = new DocumentType("Wertpapierkauf");
this.addDocumentTyp(type);
Block block = new Block("^(\\* )?Wertpapierkauf *.*");
type.addBlock(block);
Transaction<BuySellEntry> pdfTransaction = new Transaction<BuySellEntry>().subject(() -> {
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.BUY);
return entry;
}).section(//
"date").match(//
"Geschäftstag *: (?<date>\\d+.\\d+.\\d{4}+) .*").assign((t, v) -> t.setDate(asDate(v.get("date")))).section("isin", "name", //
"wkn").find(//
"Wertpapier-Bezeichnung *WPKNR/ISIN *").match(//
"^(?<name>(\\S{1,} )*) *(?<wkn>\\S*) *$").match(//
"(\\S{1,} )* *(?<isin>\\S*) *$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("shares").optional().match(//
"^St\\. *(?<shares>[\\d.]+(,\\d+)?) .*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("shares").optional().match(//
"^ Summe *St\\. *(?<shares>[\\d.]+(,\\d+)?) .*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("amount", //
"currency").find(//
".*Zu Ihren Lasten( vor Steuern)? *").match(//
".* \\d+.\\d+.\\d{4}+ *(?<currency>\\w{3}+) *(?<amount>[\\d.]+,\\d+).*").assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
}).section("tax").optional().match(//
"^a *b *g *e *f *ü *h *r *t *e *S *t *e *u *e *r *n *(?<tax>.*)$").assign((t, v) -> {
Unit unit = createTaxUnit(v.get("tax"));
if (unit == null || unit.getAmount().isZero())
return;
t.getPortfolioTransaction().addUnit(unit);
MutableMoney total = MutableMoney.of(t.getPortfolioTransaction().getCurrencyCode());
total.add(t.getPortfolioTransaction().getMonetaryAmount());
total.add(unit.getAmount());
t.setMonetaryAmount(total.toMoney());
}).wrap(t -> {
if (t.getPortfolioTransaction().getShares() == 0)
throw new IllegalArgumentException(Messages.PDFMsgMissingShares);
return new BuySellEntryItem(t);
});
addFeesSection(pdfTransaction);
block.set(pdfTransaction);
addTaxRefunds(type, "^(\\* )?Wertpapierkauf *.*");
}
use of name.abuchen.portfolio.money.MutableMoney in project portfolio by buchen.
the class ClientPerformanceSnapshot method addCurrencyGains.
private void addCurrencyGains() {
Map<String, MutableMoney> currency2money = new HashMap<>();
for (AccountSnapshot snapshot : snapshotStart.getAccounts()) {
if (converter.getTermCurrency().equals(snapshot.getAccount().getCurrencyCode()))
continue;
MutableMoney value = currency2money.computeIfAbsent(snapshot.getAccount().getCurrencyCode(), c -> MutableMoney.of(converter.getTermCurrency()));
// subtract initial values
value.subtract(snapshot.getFunds());
// add and subtract transactions
for (AccountTransaction t : snapshot.getAccount().getTransactions()) {
if (!period.containsTransaction().test(t))
continue;
switch(t.getType()) {
case DIVIDENDS:
case INTEREST:
case DEPOSIT:
case TAX_REFUND:
case SELL:
case FEES_REFUND:
value.subtract(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
break;
case REMOVAL:
case FEES:
case INTEREST_CHARGE:
case TAXES:
case BUY:
value.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
break;
case TRANSFER_IN:
value.subtract(determineTransferAmount(t));
break;
case TRANSFER_OUT:
value.add(determineTransferAmount(t));
break;
default:
throw new UnsupportedOperationException();
}
}
}
// add final values (if in foreign currency)
for (AccountSnapshot snapshot : snapshotEnd.getAccounts()) {
if (converter.getTermCurrency().equals(snapshot.getAccount().getCurrencyCode()))
continue;
currency2money.computeIfAbsent(snapshot.getAccount().getCurrencyCode(), //
c -> MutableMoney.of(converter.getTermCurrency())).add(snapshot.getFunds());
}
Category currencyGains = categories.get(CategoryType.CURRENCY_GAINS);
currency2money.forEach((currency, money) -> {
currencyGains.valuation = currencyGains.valuation.add(money.toMoney());
currencyGains.positions.add(new Position(currency, money.toMoney()));
});
Collections.sort(currencyGains.positions, (p1, p2) -> p1.getLabel().compareTo(p2.getLabel()));
}
use of name.abuchen.portfolio.money.MutableMoney in project portfolio by buchen.
the class ClientPerformanceSnapshot method addEarningTransaction.
private void addEarningTransaction(Account account, AccountTransaction transaction, MutableMoney mEarnings, MutableMoney mOtherEarnings, MutableMoney mTaxes, Map<Security, MutableMoney> earningsBySecurity) {
this.earnings.add(new TransactionPair<AccountTransaction>(account, transaction));
Money tax = transaction.getUnitSum(Unit.Type.TAX, converter).with(converter.at(transaction.getDateTime()));
Money earned = transaction.getGrossValue().with(converter.at(transaction.getDateTime()));
mEarnings.add(earned);
if (!tax.isZero()) {
mTaxes.add(tax);
taxes.add(new TransactionPair<AccountTransaction>(account, transaction));
}
if (transaction.getSecurity() != null)
earningsBySecurity.computeIfAbsent(transaction.getSecurity(), k -> MutableMoney.of(converter.getTermCurrency())).add(earned);
else
mOtherEarnings.add(earned);
}
use of name.abuchen.portfolio.money.MutableMoney in project portfolio by buchen.
the class SecurityPerformanceRecord method calculateMarketValue.
private void calculateMarketValue(CurrencyConverter converter, ReportingPeriod period) {
MutableMoney mv = MutableMoney.of(converter.getTermCurrency());
for (Transaction t : transactions) if (t instanceof DividendFinalTransaction)
mv.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
this.marketValue = mv.toMoney();
this.quote = security.getSecurityPrice(period.getEndDate());
}
Aggregations