gpt4 book ai didi

python - 计算与 Pandas 的滚动相关性

转载 作者:行者123 更新时间:2023-12-05 08:17:29 27 4
gpt4 key购买 nike

我有一份由 PERMNO 区分的 10 只股票的 list 。我想按 PERMNO 对这些股票进行分组,并计算每个 PERMNO 的股票 yield (RET) 与市场 yield (vwretd) 之间的滚动相关性。我正在尝试的代码如下。

CRSP['rollingcorr'] = CRSP.groupby('PERMNO').rolling_corr(CRSP['RET'],CRSP['vwretd'],10)

我得到的错误如下。

---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-32-c18e1ce01302> in <module>()
1 #CRSP['rollingcorr'] = CRSP.rolling_corr(CRSP['vwretd'],CRSP['RET'],120)
----> 2 CRSP['rollingmean'] = CRSP.groupby('PERMNO').rolling_corr(CRSP['vwretd'],10)
3 CRSP.head(20)

C:\Users\rebortz\Anaconda\lib\site-packages\pandas\core\groupby.pyc in __getattr__(self, attr)
296
297 raise AttributeError("%r object has no attribute %r" %
--> 298 (type(self).__name__, attr))
299
300 def __getitem__(self, key):

AttributeError: 'DataFrameGroupBy' object has no attribute 'rolling_corr'

请帮忙!

谢谢

最佳答案

正在运行 rolling.corr()在 Python 3.5 上生成警告该函数已弃用,将来可能会停止工作。使用 Series.rolling(window=<period>).corr(other=series)相反,建议。例如

data['scrip1DailyReturn'].rolling(window=90).corr(other=data['scrip2DailyReturn'])

关于python - 计算与 Pandas 的滚动相关性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27069003/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com