Search in sources :

Example 31 with PerformanceIndex

use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.

the class PerformanceHeatmapWidget method fillTable.

private void fillTable() {
    // fill the table lines according to the supplied period
    // calculate the performance with a temporary reporting period
    // calculate the color interpolated between red and green with yellow as
    // the median
    Interval interval = get(ReportingPeriodConfig.class).getReportingPeriod().toInterval();
    DoubleFunction<Color> coloring = buildColorFunction();
    addHeaderRow();
    DataSeries dataSeries = get(DataSeriesConfig.class).getDataSeries();
    // adapt interval to include the first and last month fully
    Interval calcInterval = Interval.of(interval.getStart().getDayOfMonth() == interval.getStart().lengthOfMonth() ? interval.getStart() : interval.getStart().withDayOfMonth(1).minusDays(1), interval.getEnd().withDayOfMonth(interval.getEnd().lengthOfMonth()));
    PerformanceIndex performanceIndex = getDashboardData().calculate(dataSeries, new ReportingPeriod.FromXtoY(calcInterval));
    Interval actualInterval = performanceIndex.getActualInterval();
    for (Integer year : actualInterval.iterYears()) {
        // year
        Cell cell = new Cell(table, () -> {
            int numColumns = getDashboardData().getDashboard().getColumns().size();
            return numColumns > 2 ? String.valueOf(year % 100) : String.valueOf(year);
        });
        GridDataFactory.fillDefaults().grab(true, false).applyTo(cell);
        // monthly data
        for (LocalDate month = LocalDate.of(year, 1, 1); month.getYear() == year; month = month.plusMonths(1)) {
            if (actualInterval.contains(month)) {
                cell = createCell(performanceIndex, month, coloring);
                InfoToolTip.attach(cell, Messages.PerformanceHeatmapToolTip);
            } else {
                // $NON-NLS-1$
                cell = new Cell(table, () -> "");
            }
            GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.FILL).applyTo(cell);
        }
    }
    table.layout(true);
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Color(org.eclipse.swt.graphics.Color) DataSeries(name.abuchen.portfolio.ui.views.dataseries.DataSeries) LocalDate(java.time.LocalDate) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) Point(org.eclipse.swt.graphics.Point) Interval(name.abuchen.portfolio.util.Interval)

Example 32 with PerformanceIndex

use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.

the class PerformanceChartSeriesBuilder method addClient.

private void addClient(DataSeries series, PerformanceIndex clientIndex, Aggregation.Period aggregationPeriod) {
    PerformanceIndex index = aggregationPeriod != null ? Aggregation.aggregate(clientIndex, aggregationPeriod) : clientIndex;
    switch((ClientDataSeries) series.getInstance()) {
        case TOTALS:
            ILineSeries lineSeries = getChart().addDateSeries(index.getDates(), index.getAccumulatedPercentage(), series.getLabel());
            configure(series, lineSeries);
            break;
        case DELTA_PERCENTAGE:
            String aggreagtionPeriodLabel = aggregationPeriod != null ? aggregationPeriod.toString() : Messages.LabelAggregationDaily;
            IBarSeries barSeries = getChart().addDateBarSeries(index.getDates(), index.getDeltaPercentage(), aggreagtionPeriodLabel);
            // update label, e.g. 'daily' to 'weekly'
            series.setLabel(aggreagtionPeriodLabel);
            configure(series, barSeries);
            break;
        default:
            break;
    }
}
Also used : IBarSeries(org.swtchart.IBarSeries) ClientDataSeries(name.abuchen.portfolio.ui.views.dataseries.DataSeries.ClientDataSeries) ILineSeries(org.swtchart.ILineSeries) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex)

Example 33 with PerformanceIndex

use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.

the class StatementOfAssetsSeriesBuilder method build.

public void build(DataSeries series, ReportingPeriod reportingPeriod) {
    PerformanceIndex index = getCache().lookup(series, reportingPeriod);
    if (series.getType() == DataSeries.Type.CLIENT) {
        addClient(series, index);
    } else {
        ILineSeries lineSeries = getChart().addDateSeries(index.getDates(), toDouble(index.getTotals(), Values.Amount.divider()), series.getLabel());
        configure(series, lineSeries);
    }
}
Also used : ILineSeries(org.swtchart.ILineSeries) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex)

Aggregations

PerformanceIndex (name.abuchen.portfolio.snapshot.PerformanceIndex)33 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)23 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)22 Test (org.junit.Test)22 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)19 Security (name.abuchen.portfolio.model.Security)18 Client (name.abuchen.portfolio.model.Client)17 Classification (name.abuchen.portfolio.model.Classification)15 LocalDate (java.time.LocalDate)14 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)14 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)14 Taxonomy (name.abuchen.portfolio.model.Taxonomy)14 LocalDateTime (java.time.LocalDateTime)13 List (java.util.List)13 Collectors (java.util.stream.Collectors)13 ClientFactory (name.abuchen.portfolio.model.ClientFactory)13 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)13 Money (name.abuchen.portfolio.money.Money)13 Values (name.abuchen.portfolio.money.Values)13