CAPM_Single stock

本文探讨了资本资产定价模型(CAPM)在评估单一股票风险与收益方面的作用。CAPM提供了一种理解预期回报与市场整体风险关系的方法。通过贝塔系数,投资者可以衡量特定股票相对于市场指数的波动性,从而制定更有效的投资策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import statsmodels.api as sm
import pandas as pd
import pandas_datareader as web
import matplotlib.pyplot as plt
%matplotlib inline
start = pd.to_datetime('2010-01-04')
end = pd.to_datetime('2020-04-16')

spy_etf = web.DataReader('SPY', 'yahoo', start, end)
spy_etf.info()

在这里插入图片描述

spy_etf.head()

在这里插入图片描述

aapl = web.DataReader('AAPL', 'yahoo', start, end)
aapl.head()

在这里插入图片描述

aapl['Close'].plot(label = 'AAPL',
                   figsize = (12, 8))
spy_etf['Close'].plot(label = 'SPY Index')
plt.legend()

在这里插入图片描述

aapl['Cumulative'] = aapl['Close'] / aapl['Close'].iloc[0]
spy_etf['Cumulative'] = spy_etf['Close'] / spy_etf['Close'].iloc[0]
aapl['Cumulative'].plot(label = 'AAPL',
                        figsize = (10,8))
spy_etf['Cumulative'].plot(label = 'SPY Index')
plt.legend()
plt.title('Cumulative Return')

在这里插入图片描述

aapl['Daily Return'] = aapl['Close'].pct_change(1)
spy_etf['Daily Return'] = spy_etf['Close'].pct_change(1)
fig = plt.figure(figsize = (12, 8))
plt.scatter(aapl['Daily Return'], spy_etf['Daily Return'],alpha = 0.3)

在这里插入图片描述

aapl['Daily Return'].hist(bins = 100, figsize = (12, 8))

在这里插入图片描述

spy_etf['Daily Return'].hist(bins = 100, figsize = (12, 8))

在这里插入图片描述

X = sm.add_constant(spy_etf['Daily Return'].iloc[1:])
reg1 = sm.OLS(aapl['Daily Return'].iloc[1:], X, missing='drop')
results = reg1.fit()
print(results.summary())

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值