Tracking Error is a financial metric that quantifies the volatility or dispersion of the difference between the returns of an investment portfolio or asset and the returns of a benchmark index. It measures how closely the portfolio tracks its benchmark and provides insights into the consistency of the portfolio’s performance relative to the benchmark. A higher Tracking Error indicates greater divergence from the benchmark, while a lower Tracking Error suggests that the portfolio closely follows the benchmark.

The formula is as follows:

\[\text{Tracking Error} (\text{TE}) = \text{Standard Deviation of} (\text{Portfolio Returns} - \text{Benchmark Returns})\]

See definition: https://en.wikipedia.org/wiki/Tracking_error

Also known as: active risk, benchmark deviation.

Tracking Error in Python

get_tracking_error is part of the Performance module of the open-source Finance Toolkit. Install it with:

pip install financetoolkit -U

Then call get_tracking_error as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(["AAPL", "TSLA"], api_key="FINANCIAL_MODELING_PREP_KEY")

toolkit.performance.get_tracking_error()

Which returns:

Date AAPL TSLA
2021 0.0118 0.0317
2022 0.0115 0.0344
2023 0.009 0.0304
2024 0.0121 0.0369
2025 0.0139 0.0328
2026 0.0154 0.0226

Parameters

get_tracking_error accepts the following parameters:

  • period (str, optional): The period to use for the calculation. Defaults to “quarterly” if the Toolkit is initialized with quarterly=True, otherwise “yearly”.
  • rolling (int, optional): The rolling window size to use for the calculation. If set, Tracking Error is calculated over a rolling window of this many periods across the full return history instead of per period. Defaults to None.
  • rounding (int, optional): The number of decimals to round the results to. Defaults to 4.
  • growth (bool, optional): Whether to calculate the growth of the ratios. Defaults to False.
  • lag (int | str, optional): The lag to use for the growth calculation. Defaults to 1.
  • 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.
Share