Correlation -1.#IND00

Posted By: tradingest

Correlation -1.#IND00 - 01/18/19 13:57

Hi guys,

why using the code below I see this message?

Code:
vars serie1, serie2, serie3;

function run(){
	
	StartDate = 2013;
	EndDate = 2018;

	LookBack = 0;
	BarPeriod = 1;
	assetList("Assets");
	
	
	asset("GBP/USD");
	serie2 = series(priceClose());
	
	asset("EUR/USD");
	serie3 = series(priceClose());
	
	printf("n %f", Correlation(serie2, serie3, 240));
}





Attached picture ind.png
Posted By: chsmac85

Re: Correlation -1.#IND00 - 01/19/19 16:05

#IND means that the result is indeterminate. Most likely based on this operation it is due to dividing by 0.

Looking at the formula for correlation, this could be because the standard deviation of asset 1 or asset 2 is 0 or that the series themselves are empty.

I'm going to take a guess. Can you confirm that the length of the two series is the same? Perhaps there is an issue with how correlation calculations are figured when one series is of a different length than an other series?
Posted By: AndrewAMD

Re: Correlation -1.#IND00 - 01/19/19 16:44

Lookback should not be set to zero. Try a higher number.
Posted By: tradingest

Re: Correlation -1.#IND00 - 01/20/19 15:38

Originally Posted By: AndrewAMD
Lookback should not be set to zero. Try a higher number.


Doesn't works also with lookback 1000...

can you help me?
Posted By: AndrewAMD

Re: Correlation -1.#IND00 - 01/20/19 18:01

You also need to prevent printing while run() is being used during the Lookback period. You can check for this with is(LOOKBACK).

Behold:
Code:
function run(){
	assetList("AssetsOanda.csv");
	BarPeriod = 1;
	LookBack = 300;
	StartDate = 2013;
	EndDate = 2018;
	
	asset("GBP/USD");
	vars series2 = series(priceClose());
	
	asset("EUR/USD");
	vars series3 = series(priceClose());

	var cor = Correlation(series2, series3, 240);
	
	if(!is(LOOKBACK))
		printf("\n %f", cor);
}

Posted By: tradingest

Re: Correlation -1.#IND00 - 01/20/19 18:05

Thanks so much AndrewAMD

thanks thanks thanks
Posted By: tradingest

Re: Correlation -1.#IND00 - 01/20/19 18:55

Andrew,

I read the manual but I can not quite understand the value inserted within the correlation ... should indicate the bars so if barperiod = 1 and set 240 I should get the correlation relative to 4 hour I say well?
Posted By: AndrewAMD

Re: Correlation -1.#IND00 - 01/20/19 19:02

Originally Posted By: tradingest
Andrew,

I read the manual but I can not quite understand the value inserted within the correlation ... should indicate the bars so if barperiod = 1 and set 240 I should get the correlation relative to 4 hour I say well?

The way you wrote your code, you are checking for the correlation between the two assets, for the one-minute bars, for the past 240 samples, which would be the last four hours. That is, you gain a sample and lose a sample once a minute.
Posted By: chsmac85

Re: Correlation -1.#IND00 - 01/21/19 01:07

Would taking the average of that sequence yield a meaningful value?

Something like the average correlation in a resampled population.
Posted By: AndrewAMD

Re: Correlation -1.#IND00 - 01/21/19 16:37

Originally Posted By: chsmac85
Would taking the average of that sequence yield a meaningful value?

Something like the average correlation in a resampled population.
I have not attempted this, so I'm not sure.
© 2024 lite-C Forums