Search in sources :

Example 1 with Money

use of name.abuchen.portfolio.money.Money in project portfolio by buchen.

the class ClientPerformanceSnapshot method calculate.

private void calculate() {
    categories.put(CategoryType.INITIAL_VALUE, new // $NON-NLS-1$
    Category(// $NON-NLS-1$
    String.format(Messages.ColumnInitialValue, snapshotStart.getTime()), // $NON-NLS-1$
    "", snapshotStart.getMonetaryAssets()));
    Money zero = Money.of(converter.getTermCurrency(), 0);
    // $NON-NLS-1$
    categories.put(CategoryType.CAPITAL_GAINS, new Category(Messages.ColumnCapitalGains, "+", zero));
    // $NON-NLS-1$
    categories.put(CategoryType.EARNINGS, new Category(Messages.ColumnEarnings, "+", zero));
    // $NON-NLS-1$
    categories.put(CategoryType.FEES, new Category(Messages.ColumnPaidFees, "-", zero));
    // $NON-NLS-1$
    categories.put(CategoryType.TAXES, new Category(Messages.ColumnPaidTaxes, "-", zero));
    // $NON-NLS-1$
    categories.put(CategoryType.CURRENCY_GAINS, new Category(Messages.ColumnCurrencyGains, "+", zero));
    // $NON-NLS-1$
    categories.put(CategoryType.TRANSFERS, new Category(Messages.ColumnTransfers, "+", zero));
    categories.put(CategoryType.FINAL_VALUE, new // $NON-NLS-1$
    Category(// $NON-NLS-1$
    String.format(Messages.ColumnFinalValue, snapshotEnd.getTime()), // $NON-NLS-1$
    "=", snapshotEnd.getMonetaryAssets()));
    irr = ClientIRRYield.create(client, snapshotStart, snapshotEnd).getIrr();
    addCapitalGains();
    addEarnings();
    addCurrencyGains();
}
Also used : Money(name.abuchen.portfolio.money.Money) MutableMoney(name.abuchen.portfolio.money.MutableMoney)

Example 2 with Money

use of name.abuchen.portfolio.money.Money 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()));
}
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) Account(name.abuchen.portfolio.model.Account) HashMap(java.util.HashMap) Portfolio(name.abuchen.portfolio.model.Portfolio) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) Money(name.abuchen.portfolio.money.Money) MutableMoney(name.abuchen.portfolio.money.MutableMoney) MutableMoney(name.abuchen.portfolio.money.MutableMoney) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction)

Example 3 with Money

use of name.abuchen.portfolio.money.Money in project portfolio by buchen.

the class ClientSnapshot method getAssetPositions.

public Stream<AssetPosition> getAssetPositions() {
    List<AssetPosition> answer = new ArrayList<>();
    Money monetaryAssets = getMonetaryAssets();
    for (SecurityPosition p : getJointPortfolio().getPositions()) answer.add(new AssetPosition(p, converter, date, monetaryAssets));
    for (AccountSnapshot a : accounts) answer.add(new AssetPosition(new SecurityPosition(a), converter, date, monetaryAssets));
    return answer.stream();
}
Also used : Money(name.abuchen.portfolio.money.Money) MutableMoney(name.abuchen.portfolio.money.MutableMoney) ArrayList(java.util.ArrayList)

Example 4 with Money

use of name.abuchen.portfolio.money.Money in project portfolio by buchen.

the class SecurityPerformanceRecord method calculateFifoAndMovingAverageCosts.

private void calculateFifoAndMovingAverageCosts(CurrencyConverter converter) {
    CostCalculation cost = Calculation.perform(CostCalculation.class, converter, transactions);
    this.fifoCost = cost.getFifoCost();
    this.movingAverageCost = cost.getMovingAverageCost();
    this.sharesHeld = cost.getSharesHeld();
    Money netFifoCost = cost.getNetFifoCost();
    this.fifoCostPerSharesHeld = Quote.of(netFifoCost.getCurrencyCode(), Math.round(netFifoCost.getAmount() * Values.Share.factor() * Values.Quote.factorToMoney() / (double) sharesHeld));
    Money netMovingAverageCost = cost.getNetMovingAverageCost();
    this.movingAverageCostPerSharesHeld = Quote.of(netMovingAverageCost.getCurrencyCode(), Math.round(netMovingAverageCost.getAmount() * Values.Share.factor() * Values.Quote.factorToMoney() / (double) sharesHeld));
    this.fees = cost.getFees();
    this.taxes = cost.getTaxes();
    this.capitalGainsOnHoldings = marketValue.subtract(fifoCost);
    this.capitalGainsOnHoldingsMovingAverage = marketValue.subtract(movingAverageCost);
    // avoid NaN for securities with no holdings
    if (marketValue.getAmount() == 0L && fifoCost.getAmount() == 0L)
        this.capitalGainsOnHoldingsPercent = 0d;
    else
        this.capitalGainsOnHoldingsPercent = ((double) marketValue.getAmount() / (double) fifoCost.getAmount()) - 1;
    if (marketValue.getAmount() == 0L && movingAverageCost.getAmount() == 0L)
        this.capitalGainsOnHoldingsMovingAveragePercent = 0d;
    else
        this.capitalGainsOnHoldingsMovingAveragePercent = ((double) marketValue.getAmount() / (double) movingAverageCost.getAmount()) - 1;
}
Also used : Money(name.abuchen.portfolio.money.Money) MutableMoney(name.abuchen.portfolio.money.MutableMoney)

Example 5 with Money

use of name.abuchen.portfolio.money.Money in project portfolio by buchen.

the class DeltaCalculation method visit.

@Override
public void visit(CurrencyConverter converter, DividendInitialTransaction t) {
    Money amount = t.getMonetaryAmount().with(converter.at(t.getDateTime()));
    delta.subtract(amount);
    cost.add(amount);
}
Also used : Money(name.abuchen.portfolio.money.Money) MutableMoney(name.abuchen.portfolio.money.MutableMoney)

Aggregations

Money (name.abuchen.portfolio.money.Money)38 Unit (name.abuchen.portfolio.model.Transaction.Unit)19 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)18 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)16 Client (name.abuchen.portfolio.model.Client)15 BigDecimal (java.math.BigDecimal)13 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)13 MutableMoney (name.abuchen.portfolio.money.MutableMoney)12 IOException (java.io.IOException)10 Security (name.abuchen.portfolio.model.Security)10 Block (name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block)9 DocumentType (name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType)9 Transaction (name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction)9 Map (java.util.Map)8 Account (name.abuchen.portfolio.model.Account)7 AssetPosition (name.abuchen.portfolio.snapshot.AssetPosition)7 LocalDate (java.time.LocalDate)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Portfolio (name.abuchen.portfolio.model.Portfolio)6