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. Exponential smoothing - Wikipedia
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”:
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 for looking into this Frank! I also thought about Simplify before, but unfortunately it doesn’t scale. If you generate a path of length 1,000 then
Simplify[smooth]
takes forever (I aborted the evaluation). And a time series sample of size 1,000 isn’t even large (approx. 1 day of 1 minute bars)… Do you have any other ideas?