Search in sources :

Example 1 with Transaction

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

the class ClientPerformanceSnapshot method determineTransferAmount.

/**
 * Determine the monetary amount when transferring cash between accounts.
 * Because the actual exchange rate of the transferal might differ from the
 * historical rate given by the exchange rate provider (e.g. ECB), we would
 * get rounding differences if we do not take the original amount. If the
 * transferal does not involve the term currency at all, we calculate the
 * average value out of both converted amounts.
 */
private Money determineTransferAmount(AccountTransaction t) {
    if (converter.getTermCurrency().equals(t.getCurrencyCode()))
        return t.getMonetaryAmount();
    Transaction other = t.getCrossEntry().getCrossTransaction(t);
    if (converter.getTermCurrency().equals(other.getCurrencyCode()))
        return other.getMonetaryAmount();
    MutableMoney m = MutableMoney.of(converter.getTermCurrency());
    m.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
    m.add(other.getMonetaryAmount().with(converter.at(t.getDateTime())));
    return m.divide(2).toMoney();
}
Also used : MutableMoney(name.abuchen.portfolio.money.MutableMoney) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.model.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction)

Example 2 with Transaction

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

the class QuoteFromTransactionExtractor method extractQuotes.

/**
 * Extracts the quotes for the given {@link Security}.
 *
 * @param security
 *            {@link Security}
 * @return true if quotes were found, else false
 */
public boolean extractQuotes(Security security) {
    boolean bChanges = false;
    SecurityPrice pLatest = null;
    // walk through all all transactions for securiy
    for (TransactionPair<?> p : security.getTransactions(client)) {
        Transaction t = p.getTransaction();
        // check the type of the transaction
        if (t instanceof PortfolioTransaction) {
            PortfolioTransaction pt = (PortfolioTransaction) t;
            // get date and quote and build a price from it
            Quote q = pt.getGrossPricePerShare();
            LocalDate d = pt.getDateTime().toLocalDate();
            SecurityPrice price = new SecurityPrice(d, q.getAmount());
            bChanges |= security.addPrice(price);
            // remember the lates price
            if ((pLatest == null) || d.isAfter(pLatest.getDate())) {
                pLatest = price;
            }
        }
    }
    // set the latest price (if at leas one price was found)
    if (pLatest != null) {
        LatestSecurityPrice lsp = new LatestSecurityPrice(pLatest.getDate(), pLatest.getValue());
        bChanges |= security.setLatest(lsp);
    }
    return bChanges;
}
Also used : Quote(name.abuchen.portfolio.money.Quote) LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.model.Transaction) LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) LocalDate(java.time.LocalDate)

Example 3 with Transaction

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

the class IRRCalculationTest method testDividendPaymentsWithTaxes.

@Test
public void testDividendPaymentsWithTaxes() {
    List<Transaction> tx = new ArrayList<>();
    Security security = new Security();
    tx.add(new // 
    PortfolioTransaction(// 
    LocalDateTime.of(2015, Month.DECEMBER, 31, 0, 0), // 
    CurrencyUnit.EUR, // 
    Values.Amount.factorize(1000), // 
    security, // 
    Values.Share.factorize(10), // 
    PortfolioTransaction.Type.BUY, Values.Amount.factorize(10), 0));
    DividendTransaction t = new DividendTransaction();
    t.setDateTime(LocalDateTime.parse("2016-06-01T00:00"));
    t.setSecurity(security);
    t.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100)));
    t.setShares(Values.Share.factorize(10));
    t.addUnit(new Unit(Unit.Type.TAX, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(50))));
    tx.add(t);
    tx.add(new // 
    PortfolioTransaction(// 
    LocalDateTime.of(2016, Month.DECEMBER, 31, 0, 0), // 
    CurrencyUnit.EUR, // 
    Values.Amount.factorize(1200), // 
    security, // 
    Values.Share.factorize(10), // 
    PortfolioTransaction.Type.SELL, Values.Amount.factorize(10), Values.Amount.factorize(30)));
    IRRCalculation calculation = Calculation.perform(IRRCalculation.class, new TestCurrencyConverter(), tx);
    // Excel verification
    // 31.12.15 -1000
    // 01.06.16 150
    // 31.12.16 1230
    // =XINTZINSFUSS(B1:B3;A1:A3) = 0,412128788
    assertThat(calculation.getIRR(), IsCloseTo.closeTo(0.412128788d, 0.00000001d));
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.model.Transaction) ArrayList(java.util.ArrayList) Security(name.abuchen.portfolio.model.Security) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit) Test(org.junit.Test)

Example 4 with Transaction

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

the class AccountTransferModel method applyChanges.

@Override
public void applyChanges() {
    if (sourceAccount == null)
        throw new UnsupportedOperationException(Messages.MsgAccountFromMissing);
    if (targetAccount == null)
        throw new UnsupportedOperationException(Messages.MsgAccountToMissing);
    AccountTransferEntry t;
    if (source != null && sourceAccount.equals(source.getOwner(source.getSourceTransaction())) && targetAccount.equals(source.getOwner(source.getTargetTransaction()))) {
        // transaction stays in same accounts
        t = source;
    } else {
        if (source != null) {
            @SuppressWarnings("unchecked") TransactionOwner<Transaction> owner = (TransactionOwner<Transaction>) source.getOwner(source.getSourceTransaction());
            owner.deleteTransaction(source.getSourceTransaction(), client);
            source = null;
        }
        t = new AccountTransferEntry(sourceAccount, targetAccount);
        t.getSourceTransaction().setCurrencyCode(sourceAccount.getCurrencyCode());
        t.getTargetTransaction().setCurrencyCode(targetAccount.getCurrencyCode());
        t.insert();
    }
    t.setDate(date.atStartOfDay());
    t.setNote(note);
    // if source and target account have the same currencies, no forex data
    // needs to be stored
    AccountTransaction sourceTransaction = t.getSourceTransaction();
    sourceTransaction.clearUnits();
    if (sourceAccount.getCurrencyCode().equals(targetAccount.getCurrencyCode())) {
        sourceTransaction.setAmount(amount);
        t.getTargetTransaction().setAmount(amount);
    } else {
        // TODO improve naming of fields: the source amount is called
        // 'fxAmount' while the target amount is just called 'amount' but
        // then the source account holds the 'forex' which is switched
        sourceTransaction.setAmount(fxAmount);
        t.getTargetTransaction().setAmount(amount);
        Transaction.Unit forex = new // 
        Transaction.Unit(// 
        Transaction.Unit.Type.GROSS_VALUE, // 
        Money.of(sourceAccount.getCurrencyCode(), fxAmount), // 
        Money.of(targetAccount.getCurrencyCode(), amount), getInverseExchangeRate());
        sourceTransaction.addUnit(forex);
    }
}
Also used : Transaction(name.abuchen.portfolio.model.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) TransactionOwner(name.abuchen.portfolio.model.TransactionOwner)

Example 5 with Transaction

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

the class BuySellModel method applyChanges.

@Override
public void applyChanges() {
    if (security == null)
        throw new UnsupportedOperationException(Messages.MsgMissingSecurity);
    if (account == null)
        throw new UnsupportedOperationException(Messages.MsgMissingReferenceAccount);
    BuySellEntry entry;
    if (source != null && source.getOwner(source.getPortfolioTransaction()).equals(portfolio) && source.getOwner(source.getAccountTransaction()).equals(account)) {
        entry = source;
    } else {
        if (source != null) {
            @SuppressWarnings("unchecked") TransactionOwner<Transaction> owner = (TransactionOwner<Transaction>) source.getOwner(source.getPortfolioTransaction());
            owner.deleteTransaction(source.getPortfolioTransaction(), client);
            source = null;
        }
        entry = new BuySellEntry(portfolio, account);
        entry.setCurrencyCode(account.getCurrencyCode());
        entry.insert();
    }
    entry.setDate(LocalDateTime.of(date, time));
    entry.setCurrencyCode(account.getCurrencyCode());
    entry.setSecurity(security);
    entry.setShares(shares);
    entry.setAmount(total);
    entry.setType(type);
    entry.setNote(note);
    writeToTransaction(entry.getPortfolioTransaction());
}
Also used : BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.model.Transaction) TransactionOwner(name.abuchen.portfolio.model.TransactionOwner)

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