Search in sources :

Example 1 with RandomNumber

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;
}
Also used : CalendarDate(org.ojalgo.type.CalendarDate) Deterministic(org.ojalgo.random.Deterministic) RandomNumber(org.ojalgo.random.RandomNumber) CalendarDateSeries(org.ojalgo.series.CalendarDateSeries) GeometricBrownianMotion(org.ojalgo.random.process.GeometricBrownianMotion)

Aggregations

Deterministic (org.ojalgo.random.Deterministic)1 RandomNumber (org.ojalgo.random.RandomNumber)1 GeometricBrownianMotion (org.ojalgo.random.process.GeometricBrownianMotion)1 CalendarDateSeries (org.ojalgo.series.CalendarDateSeries)1 CalendarDate (org.ojalgo.type.CalendarDate)1