The CAPM states the following:

E(R) = R_{f} + β(E(R_{m}) – R_{f})

where R is the return on the asset of interest, R_{f} is the risk-free rate of return, R_{m} is the rate of return for the entire market (the market portfolio) and β is a parameter that describes the sensitivity of the asset’s return to the market’s return.

To estimate a stock’s β, you therefore need historical data on a stock’s returns, the market’s returns, and the risk-free interest rate. You can calculate returns from an asset’s prices as follows:

R_{t} = (P_{t} + D_{t} – P_{t-1}) / (P_{t-1})

Where R_{t} is the asset’s return in period t, P_{t} is the asset’s price in period t, and D_{t} is the dividend on the stock in period t (usually 0). It is customary to use a broad-based market index (such as the S&P 500 or the Wilshire 5000) to estimate the returns on the market portfolio and to use the returns on short term US Treasury bills to estimate the risk-free rate of return.

The following regression model can then be used to estimate a stock’s β:

R_{t} – R_{ft} = α + β(R_{mt} – R_{ft}) + u_{t}

If the CAPM holds, α = 0, and the regression output allows you to test this hypothesis (as well as other hypotheses related to α and β.