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();
}
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()));
}
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();
}
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;
}
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);
}
Aggregations