14

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!

chrisaycock
  • 34,416
  • 14
  • 83
  • 119
Arthur Coimbra
  • 348
  • 1
  • 4
  • 14

1 Answers1

30

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

df['Asset1'].rolling(10).corr(df['Asset2'])
chrisaycock
  • 34,416
  • 14
  • 83
  • 119