public override TimeSeries BuildForecasts(TimeSeries simulatedData, List <DateTime> futureTimes) { // fit model first, using maximum likelihood estimation var model = new ARMAModel(mAROrder, mMAOrder); // create the model object model.TheData = simulatedData; // this is the data we want to fit the model to model.FitByMLE(mNumberIterLDS, mNumberIterOpt, 0, null); // first param is # low discrepancy sequence iterations, should be at least about 200 // second param is # standard optimizer iterations, should be at least about 100 // now do some forecasting beyond the end of the data var forecaster = new ForecastTransform(); forecaster.FutureTimes = futureTimes.ToArray(); // these are future times at which we want forecasts // for now, ARMA models do not use the times in any meaningful way when forecasting, // they just assume that these are the timestamps for the next sequential points // after the end of the existing time series forecaster.SetInput(0, model, null); // the ARMA model used for forecasting forecaster.SetInput(1, simulatedData, null); // the original data // normally you would call the Recompute() method of a transform, but there is no need // here; it is automatically called as soon as all inputs are set to valid values (in the 2 statements above) var predictors = forecaster.GetOutput(0) as TimeSeries; return(predictors); }
// forecasts values for the given dates from the model public TimeSeries predictARMA(List <DateTime> futureTimes, ARMAModel model) { var forecaster = new ForecastTransform(); forecaster.FutureTimes = futureTimes.ToArray(); forecaster.SetInput(0, model, null); forecaster.SetInput(1, model.TheData, null); var predictors = forecaster.GetOutput(0) as TimeSeries; // now we need to merge the forecast time series and the original time series with the original data var merger = new MergeTransform(); merger.SetInput(0, model.TheData, null); merger.SetInput(1, predictors, null); merger.Recompute(); return(merger.GetOutput(0) as TimeSeries); }