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;
}
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);
}
Aggregations