The Simple Moving Average (SMA) is a smoothing calculation helpful with identifying trends in timeseries data. It applies equal weighting to all values within the period and so follows the trend of the underlying tiemseries.
The SMA is one of the most common and well known indicators due to the calculation being simple to understand and readily avilable in many graphing appliciations. The main downside to the SMA is also due to its simplicity, i.e. lag. The greater the period of time the calculation looks at, the greater this indicator lags behind the timeseries.
The SMA is calculated by taking the average over a specified period of previous data points.
- Period (p) – this is the number of previous data points you want to include in the average calculation
- Index (i) – this is the time series index (e.g. date of current row in time series data)
- Input (input) – this is the data value (e.g. price data of a stock)
Below is the python code to calculate the SMA. To access the maintained version of this code please see python library techind.
The below graphs shows multiple SMA indicators with varying periods against the underlying timeseries.
- techind TestPyPi – link