use of org.ojalgo.random.RandomNumber in project ojAlgo-finance by optimatika.
the class FinanceUtils method forecast.
public static CalendarDateSeries<RandomNumber> forecast(final CalendarDateSeries<? extends Number> series, final int pointCount, final CalendarDateUnit timeUnit, final boolean includeOriginalSeries) {
final CalendarDateSeries<RandomNumber> retVal = new CalendarDateSeries<>(timeUnit);
retVal.name(series.getName()).colour(series.getColour());
final double tmpSamplePeriod = (double) series.getAverageStepSize() / (double) timeUnit.size();
final GeometricBrownianMotion tmpProcess = GeometricBrownianMotion.estimate(series.asPrimitive(), tmpSamplePeriod);
if (includeOriginalSeries) {
for (final Entry<CalendarDate, ? extends Number> tmpEntry : series.entrySet()) {
retVal.put(tmpEntry.getKey(), new Deterministic(tmpEntry.getValue()));
}
}
final CalendarDate tmpLastKey = series.lastKey();
final double tmpLastValue = series.lastValue().doubleValue();
tmpProcess.setValue(tmpLastValue);
for (int i = 1; i <= pointCount; i++) {
retVal.put(tmpLastKey.millis + (i * timeUnit.size()), tmpProcess.getDistribution(i));
}
return retVal;
}
Aggregations