financial.exponential_moving_average

Calculate the exponential moving average (EMA) on the series of stock prices. Wikipedia Reference: https://en.wikipedia.org/wiki/Exponential_smoothing https://www.investopedia.com/terms/e/ema.asp#toc-what-is-an-exponential -moving-average-ema

Exponential moving average is used in finance to analyze changes stock prices. EMA is used in conjunction with Simple moving average (SMA), EMA reacts to the changes in the value quicker than SMA, which is one of the advantages of using EMA.

Attributes

stock_prices

Functions

exponential_moving_average(...)

Yields exponential moving averages of the given stock prices.

Module Contents

financial.exponential_moving_average.exponential_moving_average(stock_prices: collections.abc.Iterator[float], window_size: int) collections.abc.Iterator[float]

Yields exponential moving averages of the given stock prices. >>> tuple(exponential_moving_average(iter([2, 5, 3, 8.2, 6, 9, 10]), 3)) (2, 3.5, 3.25, 5.725, 5.8625, 7.43125, 8.715625)

Parameters:
  • stock_prices – A stream of stock prices

  • window_size – The number of stock prices that will trigger a new calculation of the exponential average (window_size > 0)

Returns:

Yields a sequence of exponential moving averages

Formula:

st = alpha * xt + (1 - alpha) * st_prev

Where, st : Exponential moving average at timestamp t xt : stock price in from the stock prices at timestamp t st_prev : Exponential moving average at timestamp t-1 alpha : 2/(1 + window_size) - smoothing factor

Exponential moving average (EMA) is a rule of thumb technique for smoothing time series data using an exponential window function.

financial.exponential_moving_average.stock_prices = [2.0, 5, 3, 8.2, 6, 9, 10]