Hello, I apply the exponential smoothing technique to some time series and would like to calculate the optimum smoothing constant (a) that minimize the in-sample sum-of-squared forecast errors with Mathematica. Unfortunately, this takes forever in Mathematica. For the exponential smoothing technique please refer to e.g. http://en.wikipedia.org/wiki/Exponential_smoothing
Let's use some random GBM data
data = RandomFunction[
GeometricBrownianMotionProcess[0.01, 0.1, 100], {1, 100, 1}][
"ValueList"][[1]];
Calculate simple returns
returns = Differences[data]/Drop[data, -1];
Apply the exponential smoothing technique (with constant a)
smooth = ExponentialMovingAverage[returns, a];
And use NMinimize to search for the a that minimizes the "forecast error":
NMinimize[Total[(Drop[returns, 1] - Drop[smooth, -1])^2],
a]
With my machine and Mathematica 10.0.1 this takes approximately 16 seconds, i.e. an eternity. If I do the same in R or Excel this takes a miniscule amount of time. I have the feeling that NMinimize is slow because it takes much time to evaluate the symbolic smooth expression. What am I doing wrong? Is there a way to speed things up? Any hints would be appreciated.
Thanks, Michael