Search in sources :

Example 11 with MutableMoney

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 *.*");
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Client(name.abuchen.portfolio.model.Client) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) IOException(java.io.IOException) Messages(name.abuchen.portfolio.Messages) MutableMoney(name.abuchen.portfolio.money.MutableMoney) Matcher(java.util.regex.Matcher) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Pattern(java.util.regex.Pattern) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) MutableMoney(name.abuchen.portfolio.money.MutableMoney) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Example 12 with MutableMoney

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()));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Client(name.abuchen.portfolio.model.Client) Transaction(name.abuchen.portfolio.model.Transaction) Account(name.abuchen.portfolio.model.Account) EnumMap(java.util.EnumMap) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) TransactionPair(name.abuchen.portfolio.model.TransactionPair) HashMap(java.util.HashMap) Security(name.abuchen.portfolio.model.Security) Messages(name.abuchen.portfolio.Messages) MutableMoney(name.abuchen.portfolio.money.MutableMoney) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) Unit(name.abuchen.portfolio.model.Transaction.Unit) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) MoneyCollectors(name.abuchen.portfolio.money.MoneyCollectors) LocalDate(java.time.LocalDate) Map(java.util.Map) Collections(java.util.Collections) Portfolio(name.abuchen.portfolio.model.Portfolio) MutableMoney(name.abuchen.portfolio.money.MutableMoney) HashMap(java.util.HashMap) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction)

Example 13 with MutableMoney

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);
}
Also used : Money(name.abuchen.portfolio.money.Money) MutableMoney(name.abuchen.portfolio.money.MutableMoney) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction)

Example 14 with MutableMoney

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());
}
Also used : MutableMoney(name.abuchen.portfolio.money.MutableMoney) Transaction(name.abuchen.portfolio.model.Transaction)

Aggregations

MutableMoney (name.abuchen.portfolio.money.MutableMoney)14 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)9 Client (name.abuchen.portfolio.model.Client)7 Money (name.abuchen.portfolio.money.Money)7 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)6 Unit (name.abuchen.portfolio.model.Transaction.Unit)6 Messages (name.abuchen.portfolio.Messages)5 Transaction (name.abuchen.portfolio.model.Transaction)5 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)5 ArrayList (java.util.ArrayList)4 Account (name.abuchen.portfolio.model.Account)4 LocalDate (java.time.LocalDate)3 Collections (java.util.Collections)3 EnumMap (java.util.EnumMap)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 Portfolio (name.abuchen.portfolio.model.Portfolio)3 Security (name.abuchen.portfolio.model.Security)3