use of name.abuchen.portfolio.snapshot.AssetPosition 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();
}
use of name.abuchen.portfolio.snapshot.AssetPosition in project portfolio by buchen.
the class SecuritiesChart method getPurchasePrice.
private Optional<Double> getPurchasePrice(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().getFIFOPurchasePrice();
if (!purchasePrice.isZero())
return Optional.of(purchasePrice.getAmount() / Values.Amount.divider());
else
return Optional.empty();
}
use of name.abuchen.portfolio.snapshot.AssetPosition in project portfolio by buchen.
the class StackedChartViewer method updateChart.
private void updateChart() {
final Map<InvestmentVehicle, VehicleBuilder> vehicle2builder = new HashMap<>();
final Map<TaxonomyNode, SeriesBuilder> node2series = new LinkedHashMap<>();
getModel().visitAll(node -> {
if (node.isClassification()) {
node2series.put(node, new SeriesBuilder(node, dates.size()));
} else {
InvestmentVehicle vehicle = node.getAssignment().getInvestmentVehicle();
VehicleBuilder builder = vehicle2builder.get(vehicle);
if (builder == null) {
builder = new VehicleBuilder();
vehicle2builder.put(vehicle, builder);
}
builder.add(node.getWeight(), node2series.get(node.getParent()));
}
});
final long[] totals = new long[dates.size()];
int index = 0;
for (LocalDate current : dates) {
ClientSnapshot snapshot = ClientSnapshot.create(getModel().getFilteredClient(), getModel().getCurrencyConverter(), current);
totals[index] = snapshot.getMonetaryAssets().getAmount();
Map<InvestmentVehicle, AssetPosition> p = snapshot.getPositionsByVehicle();
for (Map.Entry<InvestmentVehicle, VehicleBuilder> entry : vehicle2builder.entrySet()) {
AssetPosition pos = p.get(entry.getKey());
if (pos != null)
entry.getValue().book(index, pos);
}
index++;
}
// if the unassigned category is excluded, reduce the total values
if (getModel().isUnassignedCategoryInChartsExcluded()) {
SeriesBuilder unassigned = node2series.get(getModel().getUnassignedNode());
for (int ii = 0; ii < totals.length; ii++) totals[ii] -= unassigned.values[ii];
}
Stream<SeriesBuilder> seriesStream = node2series.values().stream().filter(SeriesBuilder::hasValues);
if (getModel().isUnassignedCategoryInChartsExcluded())
seriesStream = seriesStream.filter(s -> !s.node.isUnassignedCategory());
List<SeriesBuilder> series = seriesStream.collect(Collectors.toList());
if (getModel().isOrderByTaxonomyInStackChart()) {
// reverse because chart is stacked bottom-up
Collections.reverse(series);
} else {
Collections.sort(series);
}
Display.getDefault().asyncExec(() -> rebuildChartSeries(totals, series));
}
Aggregations