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()));
}
}
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);
}
});
}
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);
}
}
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()));
}
}
Aggregations