Calculate the Mean Absolute Deviation (MAD) of an investment portfolio or asset’s returns for a given period based on the daily historical returns.

MAD measures the average absolute distance of each return from the mean return. Unlike Variance and Volatility, it does not square the deviations, making it less sensitive to outliers.

The formula is as follows:

\[\text{Mean Absolute Deviation} = \text{Σ} | \text{Return}_{t} - \text{Mean} | / n\]

Where the returns are the n daily returns within each period, without scaling to the period length.

Mean Absolute Deviation (MAD) in Python or via the MCP

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_mean_absolute_deviation as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["KO", "PEP", "MDLZ"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.risk.get_mean_absolute_deviation(period="yearly")

Or, after setting up the Finance Toolkit MCP, ask:

What was the mean absolute deviation of the daily returns of Coca-Cola, PepsiCo, Mondelez and the S&P 500 in each year from 2021 to 2025?

Which returns:

Date KO PEP MDLZ Benchmark
2021 0.007 0.0069 0.0073 0.0061
2022 0.0091 0.009 0.0098 0.0119
2023 0.0063 0.007 0.008 0.0064
2024 0.0061 0.0076 0.0082 0.0058
2025 0.0083 0.0104 0.0104 0.0074

Parameters

get_mean_absolute_deviation accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe data frequency for returns (weekly, monthly, quarterly, or yearly). Defaults to “quarterly” if the Toolkit is initialised with quarterly=True, otherwise “yearly”."quarterly"
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise).2
growthboolWhether to calculate the growth of the MAD values over time. Defaults to False.True
lagint | list[int]The lag to use for the growth calculation. Defaults to 1.4
standardizeboolWhether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.True
Share