Correlations Heatmap

Posted By: Sphin

Correlations Heatmap - 05/10/17 22:08

Trying the correlations heatmap script from Financial Hacker with an own ETF set I run in 034 (no asset data) and 047 (not enough bars). I think this depends on that the lifetime of the selected ETFs is too short or I should adjust the test period and the LookBack accordingly. Shall the ratio be kept or is a LookBack of 4*252 in a test period of 5 years also okay?
Nevertheless LookBacks of some years are long periods in my understanding, what periods are criticized with 'They used too long, mean-reverting time periods for sampling the returns and covariances', are 10 or 20 years meant to be too long?

Finally a coding question:
Code:
100*annual(Moment(Returns[i],LookBack,1))

Where the annual function is hidden?

Thanks, Sphin
Posted By: jcl

Re: Correlations Heatmap - 05/11/17 07:45

Yes, the history of some ETFs goes back only a few years, so they can not be used for backtests. The lookback period for portfolio rebalancing is normally 6..12 months. If I remember right, Z8 uses 200 days.

The annual function was in the script:

var annual(var daily)
{
return pow(daily+1.,252)-1.;
}
Posted By: Sphin

Re: Correlations Heatmap - 05/11/17 15:22

Quote:
The lookback period for portfolio rebalancing is normally 6..12 months
I meant the LookBack period of the Correlation/Heatmap script that is set originally to 6*252 and these 6 years I think are a long time concerning a total period of 7 years.

Thanks for the hint to the script archives these I totally missed to see ...
Posted By: Sphin

Re: Correlations Heatmap - 05/11/17 22:29

Modifying some parameters the heatmap turns completely to white. While debugging I read in the manual about plotHeatmap:
Quote:
The matrix elements must be in the 0..1 range
That's strange because Pearson correlation ranges from -1 to 1 and so do the Correlations' values in the original script if I print them to log.
Posted By: Sphin

Re: Correlations Heatmap - 05/15/17 21:59

There are some other questions:

1. Is the declaration

var Correlations[NN][NN]

equal to

var Correlations[NN * NN] ?


I thought that Correlations[NN][NN] defines a 2-dimensonal variable for use as Correlations[0][0], Correlations[0][1] etc.? In the financial hacker script Correlations is defined this way but used as a 1-dimensioal variable with

Correlations[N*i+j] = Correlation(Returns[i],Returns[j],LookBack)


2. plotHeatmap()

Correlation ranges from -1 to 1 but plotHeatmap() only from 0..1, so

Code:
function main() {
	
        ...
	
	Correlations[0] = 1;
	Correlations[1] = 0;
	Correlations[2] = -0.5;
	Correlations[3] = -1;
	
	plotHeatmap("Correlation",Correlations,2,2);
}


leads to



Isn't it a bit confusing to display the whole spectrum from 0 (no correlation) to -1 (perfect negative correlation) with the same color?

Thanks, Sphin
© 2024 lite-C Forums