Search in sources :

Example 6 with MutableMoney

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

Example 7 with MutableMoney

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 *.*");
}
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 8 with MutableMoney

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

Example 9 with MutableMoney

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

Example 10 with MutableMoney

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()));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) MutableMoney(name.abuchen.portfolio.money.MutableMoney) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Client(name.abuchen.portfolio.model.Client) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) ClientPerformanceSnapshot(name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot) Test(org.junit.Test)

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