ewmMean#

swordfish.function.ewmMean()#

Calculate exponentially weighted moving average.

Exactly one of the parameters com, span, halfLife and alpha must be specified.

Parameters:
  • X (Constant) – A numeric vector.

  • com (Constant, optional) – A non-negative floating number and specifies decay in terms of center of mass. alpha=1/(1+com) where alpha is the decay factor.

  • span (Constant, optional) – A positive floating number larger than 1 and specifies decay in terms of span. alpha=2/(span+1).

  • halfLife (Constant, optional) – A positive floating number or a scalar of DURATION type specifying the half-life. alpha=1-exp(ln(2)/halfLife). If halfLife is a DURATION, the times must be specified with the same time unit.

  • alpha (Constant, optional) – A floating number between 0 and 1 and directly specifies decay.

  • minPeriods (Constant, optional) – An integer indicating the minimum number of observations in window required to have a value (otherwise result is NULL). The default value is 0.

  • adjust (Constant, optional) –

    A Boolean value. The default value is true.

    • If adjust=true, the weights are (1-alpha)^(n-1), (1-alpha)^(n-2), …, 1-alpha, 1 divided by their sum.

    • If adjust=false, the weights are (1-alpha)^(n-1), (1-alpha)^(n-2)*alpha, (1-alpha)^(n-3)*alpha^2,…, (1-alpha)*alpha, alpha.

  • ignoreNA (Constant, optional) –

    A Boolean value indicating whether to ignore null values when calculating weights. The default value is false.

    Take [x0, NULL, x2] for example,

    • If ignoreNA = true,

      • adjust = false, the weights of x0 and x2 are 1-α and α.

      • adjust = true, the weights of x0 and x2 are 1-α and 1.

    • If ignoreNA = false,

      • adjust = false, the weights of x0 and x2 are (1-α)2 and α.

      • adjust = true, the weights of x0 and x2 are (1-α)2 and 1.

  • times (Constant, optional) –

    A strictly increasing vector of temporal type, with the same length as X. Required only when halfLife is a DURATION, and must have the same unit as halfLife.

    Note

    If halfLife uses B (business day) or a trading calendar unit, times must be a vector of DATE type.