Skip to content

A lean package to estimate financial asset betas

License

Notifications You must be signed in to change notification settings

oronimbus/pybeta

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyBeta

Beta Estimation and Shrinkage Methods

This project gives alternative ways to look at beta for security analysis, strategy development and hedging purposes. Traditionally, beta in finance quantifies by how much an asset moves if its benchmark changes. The beta is therefore the non-diversifiable, systemic market risk and is formally given by $\beta_{i,t}=cov(r_{i,t},r_{m,t}) / \sigma^2_{m,t}$ for an asset $i$, benchmark $m$ at time $t$. It might be more intuitive to think of it as the correlation of stock $i$ to market $m$ returns multiplied by a volatility ratio: $\beta_{i_t}=\rho\times \frac{\sigma_{i,t}}{\sigma_{m,t}}$. This also establishes an explicit link between Pearson's correlation coefficient and the normal equation of the OLS estimator. Typically, the returns are expressed as excess returns (net of risk free return) which is being omitted here.

Multiple papers have been published on how best to estimate beta, some offering simple improvements to the OLS version and others more complex, iterative procedures (see references). A great summary can be found in Hollstein et al. (2018) and Welch (2021).

So far included in this project are the following estimators:

  • OLS (incl. Blume, 1975)
  • Vasicek (1973)
  • Dimson (1979)
  • EWMA (Hollstein, 2018)
  • Welch (2021)
  • Robeco (2022)
  • Scholes & Williams (1977)
  • Forecast Combination (Bates & Granger, 2018)
  • Bayesian Model Averaging (Diebold & Pauly, 1990)

Do note that simply having a better estimator for security beta does not guarantee you to make money (if that wasn't obvious already)! However, it might help removing some of the noise when dealing with financial data. Similarly, having a more complex model does not automatically result in a better estimation of beta per se.

Finally, this is by no means a study of beta estimation but merely a demonstration of various implementations. I am using a single, arbitrarily chosen estimation horizon (1 month) across all examples. One ought to compare long term estimation (e.g. 3 years) as well as shorter, intraday horizons.

Installation

The latest version is available from PyPi and can be easily installed by running:

pip install pybeta

Usage

Usage is straight forward but please refer to the notebooks/demo.ipynb for an overview. The package can be imported and used as follows:

from pybeta import Beta

Beta(market_returns, asset_returns).ols()

References