Search in sources :

Example 1 with PortfolioSnapshot

use of name.abuchen.portfolio.snapshot.PortfolioSnapshot in project portfolio by buchen.

the class AbstractSecurityTransactionModel method updateSharesAndQuote.

protected void updateSharesAndQuote() {
    // do not auto-suggest shares and quote when editing an existing transaction
    if (hasSource())
        return;
    if (type == PortfolioTransaction.Type.SELL || type == PortfolioTransaction.Type.DELIVERY_OUTBOUND) {
        boolean hasPosition = false;
        if (portfolio != null) {
            // since the security position has always the currency of the
            // investment vehicle, actually no conversion is needed. Hence
            // we can use an arbitrary converter.
            CurrencyConverter converter = new CurrencyConverterImpl(getExchangeRateProviderFactory(), CurrencyUnit.EUR);
            PortfolioSnapshot snapshot = PortfolioSnapshot.create(portfolio, converter, date);
            SecurityPosition position = snapshot.getPositionsBySecurity().get(security);
            if (position != null) {
                setShares(position.getShares());
                setTotal(position.calculateValue().getAmount());
                hasPosition = true;
            }
        }
        if (!hasPosition) {
            setShares(0);
            setQuote(new BigDecimal(security.getSecurityPrice(date).getValue() / Values.Quote.divider()));
        }
    } else {
        setQuote(new BigDecimal(security.getSecurityPrice(date).getValue() / Values.Quote.divider()));
    }
}
Also used : SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) PortfolioSnapshot(name.abuchen.portfolio.snapshot.PortfolioSnapshot) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) BigDecimal(java.math.BigDecimal) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Example 2 with PortfolioSnapshot

use of name.abuchen.portfolio.snapshot.PortfolioSnapshot in project portfolio by buchen.

the class AccountTransactionDialog method sharesMenuAboutToShow.

private // NOSONAR
void sharesMenuAboutToShow(// NOSONAR
IMenuManager manager) {
    manager.add(new LabelOnly(Messages.DividendsDialogTitleShares));
    CurrencyConverter converter = new CurrencyConverterImpl(model.getExchangeRateProviderFactory(), client.getBaseCurrency());
    ClientSnapshot snapshot = ClientSnapshot.create(client, converter, model().getDate());
    if (snapshot != null && model().getSecurity() != null) {
        PortfolioSnapshot jointPortfolio = snapshot.getJointPortfolio();
        addAction(manager, jointPortfolio, Messages.ColumnSharesOwned);
        List<PortfolioSnapshot> list = snapshot.getPortfolios();
        if (list.size() > 1) {
            for (PortfolioSnapshot ps : list) addAction(manager, ps, ps.getPortfolio().getName());
        }
    }
    manager.add(new Action(Messages.DividendsDialogLabelSpecialDistribution) {

        @Override
        public void run() {
            model().setShares(0);
        }
    });
}
Also used : ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) Action(org.eclipse.jface.action.Action) LabelOnly(name.abuchen.portfolio.ui.util.LabelOnly) PortfolioSnapshot(name.abuchen.portfolio.snapshot.PortfolioSnapshot) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Example 3 with PortfolioSnapshot

use of name.abuchen.portfolio.snapshot.PortfolioSnapshot in project portfolio by buchen.

the class SecurityTransferModel method updateSharesAndQuote.

private void updateSharesAndQuote() {
    // transaction
    if (source != null)
        return;
    SecurityPosition position = null;
    if (security != null) {
        CurrencyConverter converter = new CurrencyConverterImpl(getExchangeRateProviderFactory(), client.getBaseCurrency());
        PortfolioSnapshot snapshot = sourcePortfolio != null ? PortfolioSnapshot.create(sourcePortfolio, converter, date) : ClientSnapshot.create(client, converter, date).getJointPortfolio();
        position = snapshot.getPositionsBySecurity().get(security);
    }
    if (position != null) {
        setShares(position.getShares());
        // setAmount will also set quote
        setAmount(position.calculateValue().getAmount());
    } else if (security != null) {
        setShares(0);
        setQuote(new BigDecimal(security.getSecurityPrice(date).getValue() / Values.Quote.divider()));
    } else {
        setShares(0);
        setQuote(BigDecimal.ZERO);
    }
}
Also used : SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) PortfolioSnapshot(name.abuchen.portfolio.snapshot.PortfolioSnapshot) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) BigDecimal(java.math.BigDecimal) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Example 4 with PortfolioSnapshot

use of name.abuchen.portfolio.snapshot.PortfolioSnapshot in project portfolio by buchen.

the class SecurityPerformanceSnapshot method addPseudoValuationTansactions.

private static void addPseudoValuationTansactions(Portfolio portfolio, CurrencyConverter converter, ReportingPeriod period, Map<Security, SecurityPerformanceRecord> records) {
    PortfolioSnapshot snapshot = PortfolioSnapshot.create(portfolio, converter, period.getStartDate());
    for (SecurityPosition position : snapshot.getPositions()) {
        records.get(position.getSecurity()).addTransaction(new DividendInitialTransaction(position, period.getStartDate().atStartOfDay()));
    }
    snapshot = PortfolioSnapshot.create(portfolio, converter, period.getEndDate());
    for (SecurityPosition position : snapshot.getPositions()) {
        records.get(position.getSecurity()).addTransaction(new DividendFinalTransaction(position, period.getEndDate().atStartOfDay()));
    }
}
Also used : SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) PortfolioSnapshot(name.abuchen.portfolio.snapshot.PortfolioSnapshot)

Aggregations

PortfolioSnapshot (name.abuchen.portfolio.snapshot.PortfolioSnapshot)4 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)3 CurrencyConverterImpl (name.abuchen.portfolio.money.CurrencyConverterImpl)3 SecurityPosition (name.abuchen.portfolio.snapshot.SecurityPosition)3 BigDecimal (java.math.BigDecimal)2 ClientSnapshot (name.abuchen.portfolio.snapshot.ClientSnapshot)1 LabelOnly (name.abuchen.portfolio.ui.util.LabelOnly)1 Action (org.eclipse.jface.action.Action)1