use of name.abuchen.portfolio.snapshot.SecurityPosition in project portfolio by buchen.
the class AccountTransactionDialog method addAction.
private void addAction(IMenuManager manager, PortfolioSnapshot portfolio, final String label) {
final SecurityPosition position = portfolio.getPositionsBySecurity().get(model().getSecurity());
if (position != null) {
Action action = new Action(MessageFormat.format(Messages.DividendsDialogLabelPortfolioSharesHeld, Values.Share.format(position.getShares()), label, Values.Date.format(portfolio.getTime()))) {
@Override
public void run() {
model().setShares(position.getShares());
}
};
manager.add(action);
}
}
use of name.abuchen.portfolio.snapshot.SecurityPosition 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.SecurityPosition in project portfolio by buchen.
the class AccountTransactionModel method updateShares.
private void updateShares() {
// transaction
if (sourceTransaction != null)
return;
if (!supportsShares() || security == null)
return;
CurrencyConverter converter = new CurrencyConverterImpl(getExchangeRateProviderFactory(), client.getBaseCurrency());
ClientSnapshot snapshot = ClientSnapshot.create(client, converter, date);
SecurityPosition p = snapshot.getJointPortfolio().getPositionsBySecurity().get(security);
setShares(p != null ? p.getShares() : 0);
}
use of name.abuchen.portfolio.snapshot.SecurityPosition 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.SecurityPosition in project portfolio by buchen.
the class Issue371PurchaseValueWithTransfers method testPurchaseValueOfSecurityPositionWithTransfers.
@Test
public void testPurchaseValueOfSecurityPositionWithTransfers() throws IOException {
Client client = ClientFactory.load(Issue371PurchaseValueWithTransfers.class.getResourceAsStream(// $NON-NLS-1$
"Issue371PurchaseValueWithTransfers.xml"));
Security adidas = client.getSecurities().get(0);
// $NON-NLS-1$
assertThat(adidas.getName(), is("Adidas AG"));
ReportingPeriod period = new // $NON-NLS-1$
ReportingPeriod.FromXtoY(// $NON-NLS-1$
LocalDate.parse("2010-11-20"), // $NON-NLS-1$
LocalDate.parse("2015-11-20"));
// make sure that the transfer entry exists
assertThat(client.getPortfolios().size(), is(2));
assertThat(client.getPortfolios().stream().flatMap(p -> p.getTransactions().stream()).filter(t -> t.getSecurity() == adidas).filter(t -> t.getCrossEntry() instanceof PortfolioTransferEntry).filter(t -> t.getType() == PortfolioTransaction.Type.TRANSFER_IN).findAny().isPresent(), is(true));
CurrencyConverter converter = new TestCurrencyConverter();
ClientSnapshot snapshot = ClientSnapshot.create(client, converter, period.getEndDate());
SecurityPosition securityPosition = snapshot.getPositionsByVehicle().get(adidas).getPosition();
SecurityPerformanceSnapshot securitySnapshot = SecurityPerformanceSnapshot.create(client, converter, period);
SecurityPerformanceRecord securityRecord = securitySnapshot.getRecords().get(0);
assertThat(securityRecord.getSecurity(), is(adidas));
assertThat(securityPosition.getFIFOPurchaseValue(), is(securityRecord.getFifoCost()));
}
Aggregations