Search in sources :

Example 6 with AssetPosition

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();
}
Also used : ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) Money(name.abuchen.portfolio.money.Money) AssetPosition(name.abuchen.portfolio.snapshot.AssetPosition)

Example 7 with AssetPosition

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();
}
Also used : ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) Money(name.abuchen.portfolio.money.Money) AssetPosition(name.abuchen.portfolio.snapshot.AssetPosition)

Example 8 with AssetPosition

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));
}
Also used : ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LocalDate(java.time.LocalDate) AssetPosition(name.abuchen.portfolio.snapshot.AssetPosition) LinkedHashMap(java.util.LinkedHashMap) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

AssetPosition (name.abuchen.portfolio.snapshot.AssetPosition)8 Money (name.abuchen.portfolio.money.Money)5 ClientSnapshot (name.abuchen.portfolio.snapshot.ClientSnapshot)4 BigDecimal (java.math.BigDecimal)1 LocalDate (java.time.LocalDate)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Assignment (name.abuchen.portfolio.model.Classification.Assignment)1 InvestmentVehicle (name.abuchen.portfolio.model.InvestmentVehicle)1 Security (name.abuchen.portfolio.model.Security)1 SecurityPrice (name.abuchen.portfolio.model.SecurityPrice)1 MutableMoney (name.abuchen.portfolio.money.MutableMoney)1 AssetCategory (name.abuchen.portfolio.snapshot.AssetCategory)1 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)1 SecurityPerformanceRecord (name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord)1 SecurityPerformanceSnapshot (name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot)1 Column (name.abuchen.portfolio.ui.util.viewers.Column)1 SharesLabelProvider (name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1