Pandas.ewma — Pandas 0.17.1 Documentation

Embed Size (px)

Citation preview

  • 8/18/2019 Pandas.ewma — Pandas 0.17.1 Documentation

    1/2

    pandas.ewmapandas.ewmapandas. ewma (arg , com=None , span=None , halflife=None , min_periods=0 , freq=None ,adjust=True , how=None , ignore_na=False )

    Exponentially-weighted moving average

    Parameters: arg : Series, DataFramecom : float. optional

    Center of mass: ,

    span : float, optional Specify decay in terms of span,

    halflife : float, optional Specify decay in terms of halflife,

    min_periods : int, default 0 Minimum number of observations in window required to havea value (otherwise result is NA).

    freq : None or string alias / date offset object, default=NoneFrequency to conform to before computing statistic

    adjust : boolean, default TrueDivide by decaying adjustment factor in beginning periods to

    account for imbalance in relative weightings (viewing EWMAas a moving average)

    how : string, default ‘mean’ Method for down- or re-sampling

    ignore_na : boolean, default FalseIgnore missing values when calculating weights; specify Trueto reproduce pre-0.15.0 behavior

    Returns: y : type of input argument

    Notes

    Either center of mass, span or halflife must be specified

    EWMA is sometimes specified using a “span” parameter s , we have that the decayparameter is related to the span as

    where c is the center of mass. Given a span, the associated center of mass is

    So a “20-day EWMA” would have center 9.5.

    pandas.ewma — pandas 0.17.1 documentation http://pandas.pydata.org/pandas-docs/stable/generated/pandas...

    1 de 2 1/3/16 17:27

  • 8/18/2019 Pandas.ewma — Pandas 0.17.1 Documentation

    2/2

    When adjust is True (default), weighted averages are calculated using weights

    (1-alpha)**(n-1), (1-alpha)**(n-2), ..., 1-alpha, 1.

    When adjust is False, weighted averages are calculated recursively as:

    weighted_average[0] = arg[0]; weighted_average[i] =(1-alpha)*weighted_average[i-1] + alpha*arg[i].

    When ignore_na is False (default), weights are based on absolute positions. For example, the weights of x and y used in calculating the final weighted average of [x,None, y] are (1-alpha)**2 and 1 (if adjust is True), and (1-alpha)**2 and alpha (if adjustis False).

    When ignore_na is True (reproducing pre-0.15.0 behavior), weights are based onrelative positions. For example, the weights of x and y used in calculating the finalweighted average of [x, None, y] are 1-alpha and 1 (if adjust is True), and 1-alpha andalpha (if adjust is False).

    More details can be found at http://pandas.pydata.org/pandas-docs/stable/computation.html#exponentially-weighted-moment-functions

    pandas.ewma — pandas 0.17.1 documentation http://pandas.pydata.org/pandas-docs/stable/generated/pandas...

    2 de 2 1/3/16 17:27