Skip to content

Commit

Permalink
Merge 19ce6c7 into 946021a
Browse files Browse the repository at this point in the history
  • Loading branch information
dfrusdn committed Dec 30, 2013
2 parents 946021a + 19ce6c7 commit d7a6b37
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions statsmodels/tsa/Expsmooth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'''
contains
--------
Exponential Smoothing
Holt Winters Exponential smoothing
License: BSD-3
TODO
----
[]Add Holt double Exponential smoothing
[]Add time series decomposition
[]Fix Holt Winters Additive model (just an if statement and change
seasonal calculation from division to
addition)
[]Add/improve Forcasting for Holt Winters to take multiple variables
[]Add confidence intervals to forcast
[]Add solver to fit Holt Winters parameters
[]Improve data summary RMS error, Sum of Square Residual,
'''

import numpy as np

def ExpSmoothing(y, alpha, forecast=None):
'''
Brown's simple exponential smoothing
Parameters
----------
y: array
Time series data
alpha: float
Smoothing factor between 0 and 1. Alpha can be calculated using
Method of least squares
forecast: int
Number of periods ahead. Forcast with bootstrapping method
s_t+1 = y_origin*a + (1-a)s_t
Returns
-------
weighted data: array
Data that is filtered using
y_t = a * y_t + a * (1-a)^1 * y_t-1 +... + a*(1-a)^n * y_t-n
References
----------
Wikipedia
Forecasting based on NIST equation for Bootstrapping
http://www.itl.nist.gov/div898/handbook/pmc/section4/pmc432.htm#Single%20Exponential%20Smoothing%20with
'''
#Initialize data
y = np.asarray(y)

ylen = len(y)
weights = alpha * ((1 - alpha)**np.arange(0, ylen))
wdata = y * weights
if forecast >= 0:
fdata = np.zeros(forecast+1)
fdata[0] = wdata[ylen - 1]
for i in range(forecast):
f = fdata[i]
fdata[i + 1] = alpha * y[ylen - 1] + (1 - alpha) * f
fdata = np.delete(fdata, 0)
wdata = np.append(wdata, fdata)
return wdata
else:
return wdata

0 comments on commit d7a6b37

Please sign in to comment.