How to calculate Rolling Correlation with pandas?

那年仲夏 提交于 2020-05-25 06:48:48

问题


I understand how to calculate a rolling sum, std or average. Example:

df['MA10'] = df['Asset1'].rolling(10).mean()

But I don't understand the syntax to calculate the rolling correlation between two dataframes columns: df['Asset1'] and df['Asset2']

The documentation doesn't provide any example regarding the correlation.

https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.rolling.html

Any insights?

Thanks!


回答1:


It's in there, even if hidden a bit:

df['Asset1'].rolling(10).corr(df['Asset2'])


来源:https://stackoverflow.com/questions/51957186/how-to-calculate-rolling-correlation-with-pandas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!