Rolling average pairwise correlation in Python
<p>I have daily returns from three markets (GLD, SPY, and USO). My goal is to calculate the the average pairwise correlation from a correlation matrix on a rolling basis of 130 days. </p>

<p>My starting point was:</p>

<pre><code>import numpy as np
import pandas as pd
import os as os
import pandas.io.data as web
import datetime as datetime
from pandas.io.data import DataReader

stocks = ['spy', 'gld', 'uso']
start = datetime.datetime(2010,1,1)
end = datetime.datetime(2016,1,1)

df = web.DataReader(stocks, 'yahoo', start, end)
adj_close_df = df['Adj Close']

returns = adj_close_df.pct_change(1).dropna()
returns = returns.dropna()

rollingcor = returns.rolling(130).corr()
</code></pre>

<p>This creates a panel of correlation matrices. However, extracting the lower(or upper) triangles, removing the diagonals and then calculating the average for each observation is where I've drawn a blank. Ideally I would like the output for each date to be in a Series where I can then index it by the dates.</p>

<p>Maybe I've started from the wrong place but any help would be appreciated.</p>