Modified to include a rolling mean of the past 4 quarters return prior to inputting it into a rolling 4 period correlation


I came up with an ingenious way to find stable time series correlations.
Using panda’s rolling function.
10 years, reduce to quarterly data.
corr_set = [[df.pct_change(1).rolling(4).corr()]]
then derive 2 pair combinations of corr_set.columns
iterate over those pairs (this can take a long time, this is where clustering comes in handy)
For a pair’s given set of correlations (for each set of 4 quarters) (i.e. rolling windows of 4 quarters means any given point is a measure of a year’s worth of correlations), which is a single list (1 value for each date). then find the median from this list.
If the median correlation is critical. Then you know half the dataset has a solid correlation identified. You also know this measure is the median correlation of returns within any given year period
I also derived the percent each 4 period set had positive and negative correlations which was always above 50% for only one side of either negative or positive (all correlations converged on positive correlations). So I simply display the median correlation found.
This is over a 10 year period.

