0
$\begingroup$

I have the following SAS code that uses PROC FORECAST that I would like to replicated with the Python Pandas pandas.stats.moments.ewma

proc forecast data=ewma method=expo 
  interval=weekday weight=(0.05) /*i.e. lambda=0.95*/
  nstart=20 lead=0
  out=out_ewma outfull;
  id date;
  var sq_gspc cross_returns;
run;

My DataFrame in Pandas is set up to mimic the ewma dataset in SAS -- same column names and everything, including same starting values. However, I can't seem to get the same values calculated with Pandas, probably due to a lack of understanding of the SAS options and how to set up the same calculation with Pandas. For example, to add the sq_gspc and cross_returns columns to my Pandas DataFrame, I'm doing the following:

ewmadf['f_sq_gspc']       = pd.ewma(ewmadf["sq_gspc"],       span=20, freq="D")
ewmadf['f_cross_returns'] = pd.ewma(ewmadf["cross_returns"], span=20, freq="D")

How do I replicate the PROC FORECAST here with the Python parameters?

Edit: SAS documentation provides the following:

For METHOD=EXPO, n beginning values of the series are used in forming the exponentially smoothed values S1, S2, and S3, where n is the value of the NSTART= option. The parameters are initialized by fitting a time trend regression to the first n nonmissing values of the series.

$\endgroup$

1 Answer 1

2
$\begingroup$

Short answer is that I don't think you can. Pandas doesn't provide anything like the nstart option or many of the other options that SAS provides. It's not entirely clear to me without looking at the source what exactly pandas is doing here since the docs don't follow the literature I'm familiar with.

You'll find more fully featured exponential smoothing in this PR for statsmodels. We still don't have anything like an nstart parameter. We estimate the starting values heuristically from suggestions in the literature, but you could compute them yourself and pass them in. It's not done yet. I'm still implementing the optimization for starting values and parameters.

https://github.com/statsmodels/statsmodels/pull/1489

$\endgroup$
1
  • $\begingroup$ Thanks! I very much appreciate all of the statsmodels work! $\endgroup$
    – Clay
    Apr 23, 2014 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.