use of name.abuchen.portfolio.snapshot.ClientSnapshot in project portfolio by buchen.
the class CurrencyTestCase method testClientSnapshot.
@Test
public void testClientSnapshot() {
LocalDate requestedTime = LocalDate.parse("2015-01-16");
ClientSnapshot snapshot = ClientSnapshot.create(client, converter, requestedTime);
AccountSnapshot accountEURsnapshot = lookupAccountSnapshot(snapshot, accountEUR);
assertThat(accountEURsnapshot.getFunds(), is(Money.of(CurrencyUnit.EUR, 1000_00)));
assertThat(accountEURsnapshot.getUnconvertedFunds(), is(Money.of(CurrencyUnit.EUR, 1000_00)));
AccountSnapshot accountUSDsnapshot = lookupAccountSnapshot(snapshot, accountUSD);
assertThat(accountUSDsnapshot.getFunds(), is(Money.of(CurrencyUnit.EUR, Math.round(1000_00 * (1 / 1.1588)))));
assertThat(accountUSDsnapshot.getUnconvertedFunds(), is(Money.of("USD", 1000_00)));
GroupByTaxonomy grouping = snapshot.groupByTaxonomy(client.getTaxonomy("30314ba9-949f-4bf4-944e-6a30802f5190"));
testTotals(snapshot, grouping);
testAssetCategories(grouping);
testUSDAssetPosition(grouping);
}
use of name.abuchen.portfolio.snapshot.ClientSnapshot 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.ClientSnapshot 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.ClientSnapshot 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()));
}
use of name.abuchen.portfolio.snapshot.ClientSnapshot in project portfolio by buchen.
the class SecuritiesChart method getMovingAveragePurchasePrice.
private Optional<Double> getMovingAveragePurchasePrice(Client filteredClient, CurrencyConverter currencyConverter, LocalDate date) {
ClientSnapshot snapshot = ClientSnapshot.create(filteredClient, currencyConverter, date);
AssetPosition position = snapshot.getPositionsByVehicle().get(security);
if (position == null)
return Optional.empty();
Money purchasePrice = position.getPosition().getMovingAveragePurchasePrice();
if (!purchasePrice.isZero())
return Optional.of(purchasePrice.getAmount() / Values.Amount.divider());
else
return Optional.empty();
}
Aggregations