Search in sources :

Example 16 with Transaction

use of name.abuchen.portfolio.model.Transaction in project portfolio by buchen.

the class ClientIRRYield method create.

public static ClientIRRYield create(Client client, ClientSnapshot snapshotStart, ClientSnapshot snapshotEnd) {
    Interval interval = Interval.of(snapshotStart.getTime(), snapshotEnd.getTime());
    List<Transaction> transactions = new ArrayList<>();
    collectAccountTransactions(client, interval, transactions);
    collectPortfolioTransactions(client, interval, transactions);
    Collections.sort(transactions, new Transaction.ByDate());
    List<LocalDate> dates = new ArrayList<>();
    List<Double> values = new ArrayList<>();
    collectDatesAndValues(interval, snapshotStart, snapshotEnd, transactions, dates, values);
    double irr = IRR.calculate(dates, values);
    return new ClientIRRYield(irr);
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.model.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) Interval(name.abuchen.portfolio.util.Interval)

Example 17 with Transaction

use of name.abuchen.portfolio.model.Transaction in project portfolio by buchen.

the class ClientIRRYield method collectDatesAndValues.

private static void collectDatesAndValues(Interval interval, ClientSnapshot snapshotStart, ClientSnapshot snapshotEnd, List<Transaction> transactions, List<LocalDate> dates, List<Double> values) {
    CurrencyConverter converter = snapshotStart.getCurrencyConverter();
    dates.add(interval.getStart());
    // snapshots are always in target currency, no conversion needed
    values.add(-snapshotStart.getMonetaryAssets().getAmount() / Values.Amount.divider());
    for (Transaction t : transactions) {
        dates.add(t.getDateTime().toLocalDate());
        if (t instanceof AccountTransaction) {
            AccountTransaction at = (AccountTransaction) t;
            long amount = converter.convert(t.getDateTime(), t.getMonetaryAmount()).getAmount();
            if (at.getType() == Type.DEPOSIT || at.getType() == Type.TRANSFER_IN)
                amount = -amount;
            values.add(amount / Values.Amount.divider());
        } else if (t instanceof PortfolioTransaction) {
            PortfolioTransaction pt = (PortfolioTransaction) t;
            long amount = converter.convert(t.getDateTime(), t.getMonetaryAmount()).getAmount();
            if (pt.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND || pt.getType() == PortfolioTransaction.Type.TRANSFER_IN)
                amount = -amount;
            values.add(amount / Values.Amount.divider());
        } else {
            throw new UnsupportedOperationException();
        }
    }
    dates.add(interval.getEnd());
    values.add(snapshotEnd.getMonetaryAssets().getAmount() / Values.Amount.divider());
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.model.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Example 18 with Transaction

use of name.abuchen.portfolio.model.Transaction 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)

Example 19 with Transaction

use of name.abuchen.portfolio.model.Transaction in project portfolio by buchen.

the class StockSplitModel method applyChanges.

@Override
public void applyChanges() {
    // $NON-NLS-1$
    SecurityEvent event = new SecurityEvent(exDate, SecurityEvent.Type.STOCK_SPLIT, newShares + ":" + oldShares);
    security.addEvent(event);
    if (isChangeTransactions()) {
        List<TransactionPair<?>> transactions = security.getTransactions(getClient());
        for (TransactionPair<?> pair : transactions) {
            Transaction t = pair.getTransaction();
            if (t.getDateTime().toLocalDate().isBefore(exDate))
                t.setShares(t.getShares() * newShares / oldShares);
        }
    }
    if (isChangeHistoricalQuotes()) {
        List<SecurityPrice> quotes = security.getPrices();
        for (SecurityPrice p : quotes) {
            if (p.getDate().isBefore(exDate))
                p.setValue(p.getValue() * oldShares / newShares);
        }
    }
}
Also used : TransactionPair(name.abuchen.portfolio.model.TransactionPair) SecurityEvent(name.abuchen.portfolio.model.SecurityEvent) Transaction(name.abuchen.portfolio.model.Transaction) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice)

Aggregations

Transaction (name.abuchen.portfolio.model.Transaction)19 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)14 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)13 TransactionOwner (name.abuchen.portfolio.model.TransactionOwner)8 Account (name.abuchen.portfolio.model.Account)7 Portfolio (name.abuchen.portfolio.model.Portfolio)6 Security (name.abuchen.portfolio.model.Security)6 Unit (name.abuchen.portfolio.model.Transaction.Unit)6 TransactionPair (name.abuchen.portfolio.model.TransactionPair)6 MessageFormat (java.text.MessageFormat)5 LocalDate (java.time.LocalDate)5 CurrencyConverterImpl (name.abuchen.portfolio.money.CurrencyConverterImpl)5 Values (name.abuchen.portfolio.money.Values)5 Column (name.abuchen.portfolio.ui.util.viewers.Column)5 ShowHideColumnHelper (name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper)5 NoteColumn (name.abuchen.portfolio.ui.views.columns.NoteColumn)5 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)5 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)5 TableViewer (org.eclipse.jface.viewers.TableViewer)5 CTabFolder (org.eclipse.swt.custom.CTabFolder)5