Calculate the Beta, a measurement that assess the systematic risk of a stock or investment.

Beta is a financial metric used to assess the systematic risk of a stock or investment in relation to the overall market. It provides valuable insights into how a particular asset’s returns tend to move in response to fluctuations in the broader market. A stock’s Beta is calculated by analyzing its historical price movements and their correlation with the movements of a market index, typically the benchmark index like the S&P 500.

The formula is as follows:

\[\text{Beta} = \text{Covariance of Asset Returns and Benchmark Returns} / \text{Variance of Benchmark Returns}\]

For a given period, for example monthly, this translates into the following:

\[\text{Beta} = \text{Monthly Covariance of Asset Returns and Benchmark Returns} / \text{Monthly Variance of Benchmark Returns}\]

See definition: https://en.wikipedia.org/wiki/Beta_(finance)

Also known as: market sensitivity, systematic risk.

No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Beta for you. Just ask in plain English.

Calculate the Beta in Python

The Beta is available in the Performance module of the open-source Finance Toolkit. Install it with:

pip install financetoolkit -U

Then call get_beta as shown below.

from financetoolkit import Toolkit

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

toolkit.performance.get_beta()

Which returns:

Date AAPL AMZN
2021 1.3093 1.0276
2022 1.2989 1.6292
2023 1.1 1.5133
2024 0.9656 1.5442
2025 1.2485 1.3264
2026 0.7887 1.281

Parameters

get_beta accepts the following parameters:

  • period (str, optional): The period to use for the calculation. Defaults to “quarterly” if the Toolkit is initialised with quarterly=True, otherwise “yearly”.
  • rolling (int, optional): The rolling period to use for the calculation. If you select period = ‘monthly’ and set rolling to 12 you obtain the rolling 12-month Sharpe Ratio.
  • 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.

The Performance module page introduces the module, and the sidebar lists all of its functions.

Share