Last Update: February 12, 2020
Asset pricing models consist of estimating asset expected return through its expected risk premium linear relationship with factors portfolios expected risk premiums and macroeconomic factors.
This topic is part of Investment Portfolio Analysis with R course. Feel free to take a look at Course Curriculum.
This tutorial has an educational and informational purpose and doesn’t constitute any type of trading or investment advice. All content, including code and data, is presented for personal educational use exclusively and with no guarantee of exactness of completeness. Past performance doesn’t guarantee future results. Please read full Disclaimer.
An example of asset pricing models is capital asset pricing model CAPM [1] which consists of estimating asset expected return through its expected risk premium linear relationship with market expected risk premium.
 CAPM Beta coefficient consists of estimating asset market systematic risk through the linear relationship between asset and market risk premiums.
 Jensen’s alpha [2] consists of estimating asset average realized excess return through the difference between asset average realized return and its estimated expected return using capital asset pricing model CAPM.
1. Formula notation.
1.1. Capital asset pricing model CAPM formula notation.
Where = asset expected return, = expected risk free return, = asset CAPM beta coefficient, = market expected risk premium.
1.2. CAPM Beta coefficient formula notation.
Where = risk free return, = constant, = asset CAPM beta coefficient, = asset and market returns covariance, = market returns variance, = asset and market risk premiums covariance, = market risk premiums variance.
1.3. Jensen’s alpha formula notation.

 Note: CAPM formula recasting using average realized returns (expost) instead of expected returns (exante). For full reference, please read Jensen’s alpha [2] .
Where = asset average realized excess return, = asset average realized return, = average realized risk free return, = asset CAPM beta coefficient, = market average realized return.
2. R script code example.
2.1. Load R package [3].
library(‘PerformanceAnalytics’)
2.2. CAPM single factor model data reading.
 Data: S&P 500® index replicating ETF (ticker symbol: SPY) adjusted close prices and market portfolio [4] monthly arithmetic returns risk premiums (20072016).
returns < read.csv(‘CAPMSingleFactorModelData.txt’,header=T)
returns < xts(returns[,2:3],order.by=as.Date(returns[,1]))
2.3. CAPM Single Factor Model Linear Regression Calculation and Output.
In:
summary(lm(returns$SPY.RF~returns$MKT.RF))
Out:
Call:
lm(formula = returns$SPY.RF ~ returns$MKT.RF)
Residuals:
Min 1Q Median 3Q Max
0.0102907 0.0028757 0.0001876 0.0029452 0.0102712
Coefficients:
Estimate Std. Error t value Pr(>t)
(Intercept) 0.0001598 0.0003637 0.439 0.661
returns$MKT.RF 0.9701754 0.0079800 121.575 <2e16 ***

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.003947 on 118 degrees of freedom
Multiple Rsquared: 0.9921, Adjusted Rsquared: 0.992
Fstatistic: 1.478e+04 on 1 and 118 DF, pvalue: < 2.2e16
2.4. CAPM Beta PerformanceAnalytics R Package Function Calculation and Output.
In:
CAPM.beta(Ra=returns$SPY.RF,Rb=returns$MKT.RF)
Out:
0.9701754
2.5. CAPM Beta Formula Calculation and Output.
In:
cov(returns$SPY.RF,returns$MKT.RF)/var(returns$MKT.RF)
Out:
0.9701754
2.6. Jensen’s Alpha PerformanceAnalytcis R Package Function Calculation and Output.
In:
CAPM.alpha(Ra=returns$SPY.RF,Rb=returns$MKT.RF)
Out:
0.0001598023
3. References
[1] Jack Treynor (1961, 1962), William F. Sharpe (1964), John Lintner (1965), Jan Mossin (1966). Craig W. French. “The Treynor Capital Asset Pricing Model”. Journal of Investment Management. 2003.
[2] Michael C. Jensen. “The Performance of Mutual Funds in the Period 19451964”. Journal of Finance. 1968.
[3] Brian G. Peterson and Peter Carl. “PerformanceAnalytics: Econometric Tools for Performance and Risk Analysis”. R package version 1.5.3. 2019.
[4] Eugene F. Fama and Kenneth F. French. “Common Risk Factors in the Returns on Stocks and Bonds”. Journal of Financial Economics. 1993.