|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#环境&数据准备:安装包[import:导入模块]
#!pip install tushare
#!pip install pyecharts
#!pip install pandas
import sys as sy
import numpy as np
import pandas as pd
import tushare as ts
import pyecharts as pye
from sklearn import datasets as ds
import matplotlib as mpl
from matplotlib import pyplot as plt
import seaborn as sns
import pyecharts as pye
#读入平安银行“000001”2017-01-01 到 2018-11-08复权后数据
df_000001 = ts.get_hist_data('000001', start='2020-01-01', end='2020-11-30')
df_szzs = ts.get_hist_data('szzs',start='2020-01-01', end='2020-11-30')
#数据准备
df_tmp1 = pd.DataFrame()
df_tmp2 = pd.DataFrame()
df_tmp1['rt_000001'] =(df_000001.close.diff(1))/df_000001.close.shift(1)
df_tmp2['rt_szzs'] =(df_szzs.close.diff(1))/df_sz.close.shift(1)
df_tmp = df_tmp1.join(df_tmp2)
df_tmp = df_tmp.dropna()
del df_tmp1
del df_tmp2
#计算Beta系数
cov_sm = np.cov(df_tmp.rt_000001, df_tmp.rt_sz)[0,1]
var_m = np.var(df_tmp.rt_sz)
Beta = cov_sm/var_m
print('Bata = ' + str(Beta))
运行之后的结果是这个样子的:
AttributeError Traceback (most recent call last)
<ipython-input-4-eb0ac5645f1d> in <module>
23 df_tmp2 = pd.DataFrame()
24 df_tmp1['rt_000001'] =(df_000001.close.diff(1))/df_000001.close.shift(1)
---> 25 df_tmp2['rt_szzs'] =(df_szzs.close.diff(1))/df_sz.close.shift(1)
26 df_tmp = df_tmp1.join(df_tmp2)
27 df_tmp = df_tmp.dropna()
AttributeError: 'NoneType' object has no attribute 'close'
请教各位大神,应该怎么修改啊?网上百度的好多种方法都试过,结果不行。
|
|