#### Overview of this book

Python for Finance
Credits
Acknowledgments
www.PacktPub.com
Preface
Free Chapter
Introduction and Installation of Python
13 Lines of Python to Price a Call Option
Introduction to Modules
Statistical Analysis of Time Series
Index

## Linear regression and Capital Assets Pricing Model (CAPM)

According to the famous CAPM, the returns of a stock are linearly correlated with its market returns. Usually, we consider the relationship of the excess stock returns versus the excess market returns.

Here Ri is the stock i's return; is the slope (market risk); Rmkt is the market return and Rf is the risk-free rate. Eventually, the preceding equation could be rewritten as follows:

The following lines of code are an example of this:

```>>>from scipy import stats
>>>stock_ret = [0.065, 0.0265, -0.0593, -0.001,0.0346]
>>>mkt_ret  = [0.055, -0.09, -0.041,0.045,0.022]
>>>beta, alpha, r_value, p_value, std_err =
stats.linregress(stock_ret,mkt_ret)
>>>print beta, alpha
0.507743187877  -0.00848190035246
>>>print "R-squared=", r_value**2
R-squared =0.147885662966
>>>print "p-value =", p_value
0.522715523909
```