use of name.abuchen.portfolio.money.MutableMoney in project portfolio by buchen.
the class ClientPerformanceSnapshotTest method assertThatCalculationWorksOut.
private void assertThatCalculationWorksOut(ClientPerformanceSnapshot snapshot, CurrencyConverter converter) {
MutableMoney valueAtEndOfPeriod = MutableMoney.of(converter.getTermCurrency());
valueAtEndOfPeriod.add(snapshot.getValue(CategoryType.INITIAL_VALUE));
valueAtEndOfPeriod.add(snapshot.getValue(CategoryType.CAPITAL_GAINS));
valueAtEndOfPeriod.add(snapshot.getValue(CategoryType.EARNINGS));
valueAtEndOfPeriod.subtract(snapshot.getValue(CategoryType.FEES));
valueAtEndOfPeriod.subtract(snapshot.getValue(CategoryType.TAXES));
valueAtEndOfPeriod.add(snapshot.getValue(CategoryType.CURRENCY_GAINS));
valueAtEndOfPeriod.add(snapshot.getValue(CategoryType.TRANSFERS));
assertThat(valueAtEndOfPeriod.toMoney(), is(snapshot.getValue(CategoryType.FINAL_VALUE)));
}
use of name.abuchen.portfolio.money.MutableMoney in project portfolio by buchen.
the class ComdirectPDFExtractor method addSellTransaction.
@SuppressWarnings("nls")
private void addSellTransaction() {
DocumentType type = new DocumentType("Wertpapierverkauf");
this.addDocumentTyp(type);
Block block = new Block("^(\\* )?Wertpapierverkauf *.*");
type.addBlock(block);
Transaction<BuySellEntry> pdfTransaction = new Transaction<BuySellEntry>().subject(() -> {
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.SELL);
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 Gunsten 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.subtract(unit.getAmount());
t.setMonetaryAmount(total.toMoney());
}).wrap(BuySellEntryItem::new);
addFeesSection(pdfTransaction);
block.set(pdfTransaction);
addTaxRefunds(type, "^(\\* )?Wertpapierverkauf *.*");
}
use of name.abuchen.portfolio.money.MutableMoney in project portfolio by buchen.
the class TaxonomyModel method visitActuals.
private void visitActuals(ClientSnapshot snapshot, TaxonomyNode node) {
MutableMoney actual = MutableMoney.of(snapshot.getCurrencyCode());
for (TaxonomyNode child : node.getChildren()) {
visitActuals(snapshot, child);
actual.add(child.getActual());
}
if (node.isAssignment()) {
Assignment assignment = node.getAssignment();
AssetPosition p = snapshot.getPositionsByVehicle().get(assignment.getInvestmentVehicle());
if (p != null) {
Money valuation = p.getValuation();
actual.add(Money.of(valuation.getCurrencyCode(), Math.round(valuation.getAmount() * assignment.getWeight() / (double) Classification.ONE_HUNDRED_PERCENT)));
}
}
node.setActual(actual.toMoney());
}
use of name.abuchen.portfolio.money.MutableMoney in project portfolio by buchen.
the class AccountListView method updateBalance.
private void updateBalance(Account account) {
transaction2balance.clear();
if (account == null)
return;
List<AccountTransaction> tx = new ArrayList<>(account.getTransactions());
Collections.sort(tx, new AccountTransaction.ByDateAmountTypeAndHashCode());
MutableMoney balance = MutableMoney.of(account.getCurrencyCode());
for (AccountTransaction t : tx) {
switch(t.getType()) {
case DEPOSIT:
case INTEREST:
case DIVIDENDS:
case TAX_REFUND:
case SELL:
case TRANSFER_IN:
case FEES_REFUND:
balance.add(t.getMonetaryAmount());
break;
case REMOVAL:
case FEES:
case INTEREST_CHARGE:
case TAXES:
case BUY:
case TRANSFER_OUT:
balance.subtract(t.getMonetaryAmount());
break;
default:
throw new IllegalArgumentException();
}
transaction2balance.put(t, balance.toMoney());
}
}
use of name.abuchen.portfolio.money.MutableMoney in project portfolio by buchen.
the class IssueCurrencyGainsRoundingError method testPurchaseValueOfSecurityPositionWithTransfers.
@Test
public void testPurchaseValueOfSecurityPositionWithTransfers() throws IOException {
Client client = ClientFactory.load(IssueCurrencyGainsRoundingError.class.getResourceAsStream(// $NON-NLS-1$
"IssueCurrencyGainsRoundingError.xml"));
ReportingPeriod period = new // $NON-NLS-1$
ReportingPeriod.FromXtoY(// $NON-NLS-1$
LocalDate.parse("2015-01-09"), // $NON-NLS-1$
LocalDate.parse("2016-01-09"));
CurrencyConverter converter = new TestCurrencyConverter();
ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, period);
MutableMoney currencyGains = MutableMoney.of(converter.getTermCurrency());
currencyGains.subtract(snapshot.getValue(CategoryType.INITIAL_VALUE));
currencyGains.subtract(snapshot.getValue(CategoryType.CAPITAL_GAINS));
currencyGains.subtract(snapshot.getValue(CategoryType.EARNINGS));
currencyGains.add(snapshot.getValue(CategoryType.FEES));
currencyGains.add(snapshot.getValue(CategoryType.TAXES));
currencyGains.add(snapshot.getValue(CategoryType.TRANSFERS));
currencyGains.add(snapshot.getValue(CategoryType.FINAL_VALUE));
assertThat(snapshot.getCategoryByType(CategoryType.CURRENCY_GAINS).getValuation(), is(currencyGains.toMoney()));
}
Aggregations