The Startup
Published in

The Startup

Bayesian CAPM Beta Estimation

Continuing with my (mostly) healthy obsession with Bayesian statistics (see my previous article), in this article, I’ll use a linear regression model from a Bayesian perspective.

To demonstrate how linear regressions in the context of Bayesian statistics work, I will use the CAPM to estimate stock’s Betas.

Introduction

It’s not fundamentally important that you are familiar with CAPM to understand the example of regressions using Bayesian statistics. However, for those out there who might be interested, CAPM stands for Capital Asset Pricing Model. The model defines a relationship between an asset’s (usually stocks) expected returns and the market risk premium. In essence, it describes how a stock’s expected return reacts to the market risk premium.

The Capital Asset Pricing Model
The Capital Asset Pricing Model

As can be seen in the model specification, this relationship is linear with a β coefficient describing the effect of a change in the market risk premium on the stock’s expected return. In finance, this coefficient is commonly known as (you guessed it) Beta.

Yahoo! Finance showing the value of Beta for Amazon (AMZN)
Yahoo! Finance showing the value of Beta for Amazon (AMZN)

Beta

The interpretation for this Beta coefficient is that it represents a measure of the volatility of the asset. In practice, the expected market returns used are the returns for investing in the S&P 500. As a result, Beta ends up being a measure of the correlation between the S&P 500’s expected returns and the stock’s expected returns.

I’m not going to go any deeper into the CAPM, or why it’s good and why it’s bad, but if you found it interesting, I encourage you to read more about it here.

Measuring the Beta of a stock is nothing extraordinary or remarkable. In fact, if you go to Yahoo! Finance right now and search for any stock, you will find the Beta for that stock as part of the basic data that Yahoo! provides. However, as you can see, the number provided by Yahoo! Finance is a single point-estimate of the Beta for the stock. Whenever you are given a single number, always (seriously, always) ask yourself the following question: How certain are they?

This applies to almost any statical estimation, from stocks’ Betas to COVID-19 vaccine efficiency. If I tell you that a vaccine is 90% effective against COVID-19, you might be extremely impressed. But, how certain are you really that the vaccine has a 90% efficiency? What is the probability of the vaccine having a 90% efficiency? What is the probability of it being lower than 90%? These are all questions that should immediately come to your mind whenever someone gives you a point-value estimate.

Remember: Always doubt point-estimates, ask yourself what is the probability of the estimate actually having that value.

We will see how we can use our Bayesian approach to solve this issue and give more information about our uncertainty.

Model

The model is quite straightforward, but we need to take care of how we operationalize it. We can re-arrange the model to find that the expected excess returns from the stock should be proportional to the excess return of the market, with β being the constant of proportionality.

Furthermore, the returns for both the stock and the market, are basically the percentage change in closing prices at the stock market. The risk-free rate to use and subtract from the returns is an entire discussion on its own. We will avoid this discussion by assuming a risk-free rate of zero. This is obviously wrong, but the point of this post is not on perfect estimation of CAPM Betas, but Bayesian linear regression. In any case, you can do the entire procedure and simply subtract whichever risk-free rate you find appropriate (an exercise for the reader). Let’s call the excess returns for the stock Y and the excess returns for the market X. We can add an 𝛼 term to capture everything else that is not captured by the proportionality between X and Y, and get the following linear regression model:

Linear regression model

Data

Now that we have defined our model, we can get some data to start fitting it and estimate the coefficients. In this case, all we need are the closing prices for the S&P 500 (the market returns) and whichever stocks we want to use. In this case, let’s give it a try with Microsoft (MSFT), Amazon (AMZN), Facebook (FB) and Google (GOOG). As you can see from Yahoo! Finance, they use data from the last 5 years and on a monthly interval, so we’ll do the same.

To get all these data, we’ll use a Python package called yfinance. This package lets us download data from Yahoo! Finance for any stock. We need to do a bit of data wrangling first to get all the data we need in a nice and convenient format.

Ordinary Least Squares

To have a benchmark to compare our results, we will first fit and OLS model to our data before taking the Bayesian approach. This is fairly simple using the statsmodels Python package:

Great, now let’s run this for the four stocks:

MSFT:  0.8079265809137846
GOOG: 0.9806040506006948
AMZN: 1.152025182533014
FB: 1.2664985151863173

Now, if we compare with the values in Yahoo! Finance, we see that they are quite close to each other. These are the Betas for those 4 stocks at the time of writing:

MSFT:  0.83
GOOG: 0.99
AMZN: 1.20
FB: 1.18

By the way, did you see that R²? Do we really think this relationship is linear? Absolutely not! But let’s not get into that for now…

Bayesian Linear Regression

Now that we have seen the results of this model using OLS, let’s try it out with a Bayesian approach. We will use the same model and we’ll even use the same assumptions as OLS. One of the great advantages of going Bayesian is the ability to choose our own assumptions and add domain knowledge into our model estimation through the use of priors. In this case, we’ll stick with the usual priors for a linear regression. We will assume all of our coefficients come from normal distributions and our error term is also normally distributed.

Having defined our model and our priors, we can start coding it using PyMC3, an amazing Python library for probabilistic programming.

After sampling from our model and checking we have convergence by looking at the trace plots, we can get our posterior distribution for our Beta. Remember, because we are going the Bayesian way, we are not getting a value as a result, but an entire distribution. This distribution will reflect the uncertainty we have on our prediction for Beta. But enough talking, let’s look at the distribution:

Posterior distribution for Amazon’s Beta

We can see that the Beta for Amazon is most likely between 0.9 and 1.3, in fact, there’s about a 70% chance of the Beta for Amazon being between 0.9 and 1.3. That’s the beauty of our Bayesian analysis, we can actually talk probabilities.

This result is also in line with the value from Yahoo! Finance. However, it’s when we take advantage of this distribution, that Bayesian analysis really shines. For example, we can now ask questions like “What is the probability that the Beta for Amazon is greater than 1.2?”

There we have it, there’s around a 32% probability that the Beta for Amazon is actually greater than 1.2.

We can run the same process for all of our stocks and compare the result with Yahoo! Finance and OLS.

Posterior distributions for Betas

We can see that results from our Bayesian linear regression are consistent with our OLS example and the value reported in Yahoo! Finance. However, the Bayesian approach has the advantage of letting us customise our assumptions for the model and quantify our uncertainty.

--

--

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +768K followers.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Juan Gesino

Economist • Insights Lead @ Belvo • Ex-Data Analytics Manager @ Zenvia • Ex-Head of Data @ Sirena