Search in sources :

Example 6 with ConsumerPriceIndex

use of name.abuchen.portfolio.model.ConsumerPriceIndex in project portfolio by buchen.

the class UpdateCPIJob method run.

@Override
protected IStatus run(IProgressMonitor monitor) {
    monitor.beginTask(Messages.JobLabelUpdateCPI, 1);
    CPIFeed feed = new DestatisCPIFeed();
    List<IStatus> errors = new ArrayList<IStatus>();
    try {
        List<ConsumerPriceIndex> prices = feed.getConsumerPriceIndices();
        boolean isDirty = getClient().setConsumerPriceIndices(prices);
        if (isDirty)
            getClient().markDirty();
    } catch (IOException e) {
        errors.add(new Status(IStatus.ERROR, PortfolioPlugin.PLUGIN_ID, e.getMessage(), e));
    }
    if (!errors.isEmpty()) {
        PortfolioPlugin.log(new MultiStatus(PortfolioPlugin.PLUGIN_ID, -1, errors.toArray(new IStatus[0]), Messages.JobMsgErrorUpdatingIndices, null));
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) CPIFeed(name.abuchen.portfolio.online.CPIFeed) DestatisCPIFeed(name.abuchen.portfolio.online.DestatisCPIFeed) IStatus(org.eclipse.core.runtime.IStatus) ConsumerPriceIndex(name.abuchen.portfolio.model.ConsumerPriceIndex) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) IOException(java.io.IOException) DestatisCPIFeed(name.abuchen.portfolio.online.DestatisCPIFeed)

Example 7 with ConsumerPriceIndex

use of name.abuchen.portfolio.model.ConsumerPriceIndex in project portfolio by buchen.

the class CPIIndex method calculate.

/* package */
void calculate(PerformanceIndex clientIndex) {
    Interval actualInterval = clientIndex.getActualInterval();
    LocalDate firstDataPoint = clientIndex.getFirstDataPoint().orElse(actualInterval.getStart());
    Interval interval = Interval.of(firstDataPoint, actualInterval.getEnd());
    List<ConsumerPriceIndex> cpiSeries = new ArrayList<ConsumerPriceIndex>(clientIndex.getClient().getConsumerPriceIndices());
    Collections.sort(cpiSeries, new ConsumerPriceIndex.ByDate());
    List<LocalDate> dates = new ArrayList<LocalDate>();
    List<Double> accumulated = new ArrayList<Double>();
    int baseline = -1;
    for (ConsumerPriceIndex cpi : cpiSeries) {
        LocalDate date = LocalDate.of(cpi.getYear(), cpi.getMonth(), 1);
        date = date.with(ChronoField.DAY_OF_MONTH, date.lengthOfMonth());
        if (interval.contains(date)) {
            if (baseline == -1)
                baseline = cpi.getIndex();
            dates.add(date);
            accumulated.add(((double) cpi.getIndex() / (double) baseline) - 1);
        }
    }
    this.dates = dates.toArray(new LocalDate[0]);
    this.accumulated = new double[accumulated.size()];
    for (int ii = 0; ii < this.accumulated.length; ii++) this.accumulated[ii] = accumulated.get(ii);
}
Also used : ConsumerPriceIndex(name.abuchen.portfolio.model.ConsumerPriceIndex) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) Interval(name.abuchen.portfolio.util.Interval)

Aggregations

ConsumerPriceIndex (name.abuchen.portfolio.model.ConsumerPriceIndex)7 LocalDate (java.time.LocalDate)3 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2 Lexer (org.htmlparser.lexer.Lexer)2 URL (java.net.URL)1 Scanner (java.util.Scanner)1 CPIFeed (name.abuchen.portfolio.online.CPIFeed)1 DestatisCPIFeed (name.abuchen.portfolio.online.DestatisCPIFeed)1 Column (name.abuchen.portfolio.ui.util.viewers.Column)1 MonthEditingSupport (name.abuchen.portfolio.ui.util.viewers.MonthEditingSupport)1 ShowHideColumnHelper (name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper)1 ValueEditingSupport (name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport)1 Interval (name.abuchen.portfolio.util.Interval)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 Status (org.eclipse.core.runtime.Status)1 Action (org.eclipse.jface.action.Action)1 IMenuListener (org.eclipse.jface.action.IMenuListener)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1