covariance_matrix = clean_returns.cov()
temp_list = []
for row in temp.iterrows():
index, data = row
temp_list = data.tolist()
npa = np.asarray(temp_list)
npa_trans = npa.transpose()
Portfolio_Returns['Volatility'] = np.sqrt(
np.dot(npa_trans, np.dot(covariance_matrix, npa)))
我希望获得不同的波动率值,但是数据框显示的是相同的值0.022906
答案 0 :(得分:0)
该代码保存在整个“波动率”列中计算的波动率的最后一个值,而不是在每一行中保存每个波动率值
Portfolio_Returns['Volatility'] = np.sqrt(
np.dot(npa_trans, np.dot(covariance_matrix, npa))