6767"""
6868
6969
70- _ewm_kw = r"""com : float. optional
71- Center of mass: :math:`\alpha = 1 / (1 + com)`,
70+ _ewm_kw = r"""com : float, optional
71+ Specify decay in terms of center of mass,
72+ :math:`\alpha = 1 / (1 + com),\text{ for } com \geq 0`
7273span : float, optional
73- Specify decay in terms of span, :math:`\alpha = 2 / (span + 1)`
74+ Specify decay in terms of span,
75+ :math:`\alpha = 2 / (span + 1),\text{ for } span \geq 1`
7476halflife : float, optional
75- Specify decay in terms of halflife,
76- :math:`\alpha = 1 - exp(log(0.5) / halflife)`
77+ Specify decay in terms of half-life,
78+ :math:`\alpha = 1 - exp(log(0.5) / halflife),\text{ for } halflife > 0`
79+ alpha : float, optional
80+ Specify smoothing factor :math:`\alpha` directly,
81+ :math:`0 < \alpha \leq 1`
82+
83+ .. versionadded:: 0.18.0
84+
7785min_periods : int, default 0
7886 Minimum number of observations in window required to have a value
7987 (otherwise result is NA).
92100_ewm_notes = r"""
93101Notes
94102-----
95- Either center of mass, span or halflife must be specified
96-
97- EWMA is sometimes specified using a "span" parameter `s`, we have that the
98- decay parameter :math:`\alpha` is related to the span as
99- :math:`\alpha = 2 / (s + 1) = 1 / (1 + c)`
100-
101- where `c` is the center of mass. Given a span, the associated center of mass is
102- :math:`c = (s - 1) / 2`
103-
104- So a "20-day EWMA" would have center 9.5.
103+ Exactly one of center of mass, span, half-life, and alpha must be provided.
104+ Allowed values and relationship between the parameters are specified in the
105+ parameter descriptions above; see the link at the end of this section for
106+ a detailed explanation.
105107
106108When adjust is True (default), weighted averages are calculated using weights
107109 (1-alpha)**(n-1), (1-alpha)**(n-2), ..., 1-alpha, 1.
121123True), and 1-alpha and alpha (if adjust is False).
122124
123125More details can be found at
124- http://pandas.pydata.org/pandas-docs/stable/computation.html#exponentially-weighted-moment-functions
126+ http://pandas.pydata.org/pandas-docs/stable/computation.html#exponentially-weighted-windows
125127"""
126128
127129_expanding_kw = """min_periods : int, default None
@@ -323,14 +325,15 @@ def rolling_corr(arg1, arg2=None, window=None, pairwise=None, **kwargs):
323325@Substitution ("Exponentially-weighted moving average" , _unary_arg , _ewm_kw ,
324326 _type_of_input_retval , _ewm_notes )
325327@Appender (_doc_template )
326- def ewma (arg , com = None , span = None , halflife = None , min_periods = 0 , freq = None ,
327- adjust = True , how = None , ignore_na = False ):
328+ def ewma (arg , com = None , span = None , halflife = None , alpha = None , min_periods = 0 ,
329+ freq = None , adjust = True , how = None , ignore_na = False ):
328330 return ensure_compat ('ewm' ,
329331 'mean' ,
330332 arg ,
331333 com = com ,
332334 span = span ,
333335 halflife = halflife ,
336+ alpha = alpha ,
334337 min_periods = min_periods ,
335338 freq = freq ,
336339 adjust = adjust ,
@@ -341,14 +344,15 @@ def ewma(arg, com=None, span=None, halflife=None, min_periods=0, freq=None,
341344@Substitution ("Exponentially-weighted moving variance" , _unary_arg ,
342345 _ewm_kw + _bias_kw , _type_of_input_retval , _ewm_notes )
343346@Appender (_doc_template )
344- def ewmvar (arg , com = None , span = None , halflife = None , min_periods = 0 , bias = False ,
345- freq = None , how = None , ignore_na = False , adjust = True ):
347+ def ewmvar (arg , com = None , span = None , halflife = None , alpha = None , min_periods = 0 ,
348+ bias = False , freq = None , how = None , ignore_na = False , adjust = True ):
346349 return ensure_compat ('ewm' ,
347350 'var' ,
348351 arg ,
349352 com = com ,
350353 span = span ,
351354 halflife = halflife ,
355+ alpha = alpha ,
352356 min_periods = min_periods ,
353357 freq = freq ,
354358 adjust = adjust ,
@@ -361,14 +365,15 @@ def ewmvar(arg, com=None, span=None, halflife=None, min_periods=0, bias=False,
361365@Substitution ("Exponentially-weighted moving std" , _unary_arg ,
362366 _ewm_kw + _bias_kw , _type_of_input_retval , _ewm_notes )
363367@Appender (_doc_template )
364- def ewmstd (arg , com = None , span = None , halflife = None , min_periods = 0 , bias = False ,
365- freq = None , how = None , ignore_na = False , adjust = True ):
368+ def ewmstd (arg , com = None , span = None , halflife = None , alpha = None , min_periods = 0 ,
369+ bias = False , freq = None , how = None , ignore_na = False , adjust = True ):
366370 return ensure_compat ('ewm' ,
367371 'std' ,
368372 arg ,
369373 com = com ,
370374 span = span ,
371375 halflife = halflife ,
376+ alpha = alpha ,
372377 min_periods = min_periods ,
373378 freq = freq ,
374379 adjust = adjust ,
@@ -383,9 +388,9 @@ def ewmstd(arg, com=None, span=None, halflife=None, min_periods=0, bias=False,
383388@Substitution ("Exponentially-weighted moving covariance" , _binary_arg_flex ,
384389 _ewm_kw + _pairwise_kw , _type_of_input_retval , _ewm_notes )
385390@Appender (_doc_template )
386- def ewmcov (arg1 , arg2 = None , com = None , span = None , halflife = None , min_periods = 0 ,
387- bias = False , freq = None , pairwise = None , how = None , ignore_na = False ,
388- adjust = True ):
391+ def ewmcov (arg1 , arg2 = None , com = None , span = None , halflife = None , alpha = None ,
392+ min_periods = 0 , bias = False , freq = None , pairwise = None , how = None ,
393+ ignore_na = False , adjust = True ):
389394 if arg2 is None :
390395 arg2 = arg1
391396 pairwise = True if pairwise is None else pairwise
@@ -401,6 +406,7 @@ def ewmcov(arg1, arg2=None, com=None, span=None, halflife=None, min_periods=0,
401406 com = com ,
402407 span = span ,
403408 halflife = halflife ,
409+ alpha = alpha ,
404410 min_periods = min_periods ,
405411 bias = bias ,
406412 freq = freq ,
@@ -414,8 +420,9 @@ def ewmcov(arg1, arg2=None, com=None, span=None, halflife=None, min_periods=0,
414420@Substitution ("Exponentially-weighted moving correlation" , _binary_arg_flex ,
415421 _ewm_kw + _pairwise_kw , _type_of_input_retval , _ewm_notes )
416422@Appender (_doc_template )
417- def ewmcorr (arg1 , arg2 = None , com = None , span = None , halflife = None , min_periods = 0 ,
418- freq = None , pairwise = None , how = None , ignore_na = False , adjust = True ):
423+ def ewmcorr (arg1 , arg2 = None , com = None , span = None , halflife = None , alpha = None ,
424+ min_periods = 0 , freq = None , pairwise = None , how = None , ignore_na = False ,
425+ adjust = True ):
419426 if arg2 is None :
420427 arg2 = arg1
421428 pairwise = True if pairwise is None else pairwise
@@ -430,6 +437,7 @@ def ewmcorr(arg1, arg2=None, com=None, span=None, halflife=None, min_periods=0,
430437 com = com ,
431438 span = span ,
432439 halflife = halflife ,
440+ alpha = alpha ,
433441 min_periods = min_periods ,
434442 freq = freq ,
435443 how = how ,
0 commit comments