Calculate the Moving Average (MA) for a given price series.

The Moving Average (MA) is a commonly used technical indicator that smooths out price data by calculating the average price over a specified number of periods.

The formula is as follows:

\[\text{MA} = (\text{Sum of Prices}) / (\text{Number of Prices})\]

Also known as: SMA, simple moving average, MA.

Simple Moving Average (SMA) in Python

get_moving_average is part of the Technicals module of the open-source Finance Toolkit. Install it with:

pip install financetoolkit -U

Then call get_moving_average as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(tickers=["AAPL", "MSFT"])

toolkit.technicals.get_moving_average()

Which returns:

Date AAPL MSFT Benchmark
2026-06-18 300.742 408.527 745.79
2026-06-22 300.078 401.871 744.779
2026-06-23 298.585 397.059 742.923
2026-06-24 297.358 392.639 741.423
2026-06-25 294.781 387.266 739.795
2026-06-26 293.098 384.145 739.184
2026-06-29 291.684 381.061 739.311
2026-06-30 291.599 378.891 740.005
2026-07-01 291.799 377.956 741.457
2026-07-02 292.727 377.967 741.959

Parameters

get_moving_average accepts the following parameters:

  • period (str, optional): The time period to consider for historical data. Can be “daily”, “weekly”, “quarterly”, or “yearly”. Defaults to “daily”.
  • close_column (str, optional): The column name for closing prices in the historical data. Defaults to “Adj Close”.
  • window (int, optional): Number of periods to consider for the moving average. The number of periods (time intervals) over which to calculate the MA.
  • rounding (int | None, optional): The number of decimals to round the results to. Defaults to 4.
  • growth (bool, optional): Whether to calculate the growth of the MA. Defaults to False.
  • lag (int | list[int], optional): The lag to use for the growth calculation.
  • standardize (bool, optional): Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. Defaults to 1.
Share