# Correlation Matrix not Symmetric

Hi,

I have used Tomasz's code from here with the only changes selecting filter watchlist being log returns instead of Close prices directly.

Code:

``````wlnumber = GetOption( "FilterIncludeWatchlist" );
symlist = GetCategorySymbols( categoryWatchlist, wlnumber );

Filter = Status( "lastbarinrange" );

pC = log(( C / Ref( C, -1 ) ));

for ( i = 0; ( sym = StrExtract( symlist, i ) ) != ""; i++ )
{
FC = Foreign( sym, "C" );
pFC = log((FC / Ref(FC, -1)));
Corr = Correlation( pC, pFC, 252 );

Clr = 32 + LastValue( Corr ) * 32;
ColorHSB( 128 + Clr, 255, 255 ),
ColorHSB( Clr, 255, 255 ) );
}

SetSortColumns( 1 );
``````

I am not getting a symmetric correlation matrix, as can be seen in the image below:

Is this a settings related issue? When doing plotting correlation using following code, I am seeing the same correlation graphs:

``````pC = log(( C / Ref( C, -1 ) ));

NC = Foreign( "NIFTY_F1", "C" );
pNC = log((NC / Ref(NC, -1)) - 1);

Plot(Correlation(pC, pFC, 52), "Correl1", colorWhite);
Plot(Correlation(pFC, pC, 52), "Correl2", colorYellow);
``````

Rakesh.

I have done some more exploration and found that the matrix is symmetric, but only in daily timeframe. Is there a reason for that? I'd prefer to be using weekly candles and thus the period of 52, which is what was being used in the question.

Simply right click your watchlist and choose "Sort alphabetically".

The watchlist is already sorted alphabetically. The correlation matrix is symmetric in Daily, but not so in Weekly.

Intraday and Daily Timeframe Correlation Matrices are Symmetric.
Above Daily, they are not. I don't understand why. Screenshots below.

15 Minute, 252 * 25 Periods (25 Candles per Day) - Symmetric:

Daily, 252 Periods - Symmetric:

Weekly, 52 Periods - Not Symmetric:

Monthly, 12 Periods - Not Symmetric:

Quarterly, 4 Periods - Not Symmetric: