January 2020
Beginner to intermediate
432 pages
11h 24m
English
Execute the following steps to implement the CAPM in Python.
import pandas as pdimport yfinance as yfimport statsmodels.api as sm
RISKY_ASSET = 'AMZN'MARKET_BENCHMARK = '^GSPC'START_DATE = '2014-01-01'END_DATE = '2018-12-31'
df = yf.download([RISKY_ASSET, MARKET_BENCHMARK], start=START_DATE, end=END_DATE, adjusted=True, progress=False)
X = df['Adj Close'].rename(columns={RISKY_ASSET: 'asset', MARKET_BENCHMARK: 'market'}) \ .resample('M') \ .last() \ .pct_change() \ .dropna()
covariance = X.cov().iloc[0,1] ...
Read now
Unlock full access