Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
4 registered members (AndrewAMD, dBc, clonman, TipmyPip), 18,735 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Multi asset correlation #476332
02/18/19 17:23
02/18/19 17:23
Joined: Jun 2018
Posts: 16
P
Paul_der_Zweite Offline OP
Newbie
Paul_der_Zweite  Offline OP
Newbie
P

Joined: Jun 2018
Posts: 16
Hi,
I want to check a list of assets for correlation. Each asset in the list should be checked with each asset in the list.

I don't want to write a time for every possibility, of course, but by while(asset(loop())

Unfortunately I can't get it to work yet wink
I would like a list, on which the following is shown to me:
asset a to asset b: Correlation x
asset a to asset c: Correlation x
asset a to asset d: Correlation x
and so on.

I tried the following, which doesn't work yet:

Code:
function run()
{
	BarPeriod = 240;
	LookBack = 300;
	StartDate = 2017;
	//EndDate = 2019;
		
	while(asset(loop("AUD/CAD","AUD/JPY","AUD/NZD","AUD/USD","CAD/CHF","CAD/JPY","CHF/JPY","Cocoa","Coffee","Copper","Corn","Cotton","Esp35","EuBund","EUR/AUD","EUR/CAD","EUR/CHF","EUR/GBP","EUR/HUF","EUR/JPY","EUR/NOK","EUR/NZD","Euro50","EUR/PLN","EUR/SEK","EUR/SGD","EUR/TRY","EUR/USD","Fra40","Gasol","GBP/AUD","GBP/CAD","GBP/CHF","GBP/JPY","GBP/NZD","GBP/USD","GER30","GerTec","GOLD","Jp225","LCrude","Neth25","NGas","NZD/CAD","NZD/CHF","NZD/JPY","NZD/USD","OJ","SGD/JPY","SILVER","Soybns","Sugar","Swi20","TRY/JPY","UK100","Usa500","UsaInd","UsaRus","UsaTB","UsaTec","UsaVix","USD/BRL","USD/CAD","USD/CHF","USD/CNH","USD/HUF","USD/JPY","USD/MXN","USD/NOK","USD/PLN","USD/RUB","USD/SEK","USD/SGD","USD/TRY","USD/ZAR","Wheat")))
	
	vars price_asset_1 = series(price());
	
	while(asset(loop("AUD/CAD","AUD/JPY","AUD/NZD","AUD/USD","CAD/CHF","CAD/JPY","CHF/JPY","Cocoa","Coffee","Copper","Corn","Cotton","Esp35","EuBund","EUR/AUD","EUR/CAD","EUR/CHF","EUR/GBP","EUR/HUF","EUR/JPY","EUR/NOK","EUR/NZD","Euro50","EUR/PLN","EUR/SEK","EUR/SGD","EUR/TRY","EUR/USD","Fra40","Gasol","GBP/AUD","GBP/CAD","GBP/CHF","GBP/JPY","GBP/NZD","GBP/USD","GER30","GerTec","GOLD","Jp225","LCrude","Neth25","NGas","NZD/CAD","NZD/CHF","NZD/JPY","NZD/USD","OJ","SGD/JPY","SILVER","Soybns","Sugar","Swi20","TRY/JPY","UK100","Usa500","UsaInd","UsaRus","UsaTB","UsaTec","UsaVix","USD/BRL","USD/CAD","USD/CHF","USD/CNH","USD/HUF","USD/JPY","USD/MXN","USD/NOK","USD/PLN","USD/RUB","USD/SEK","USD/SGD","USD/TRY","USD/ZAR","Wheat")))
	
	vars price_asset_2 = series(price());
	
	var corr = Correlation(price_asset_1, price_asset_2, 240);
	
	if(!is(LOOKBACK))
		printf("n %f", corr);

}



In my beginner version only ones appear (1.000000). *head scratch*

Does anyone have a tip?

Re: Multi asset correlation [Re: Paul_der_Zweite] #476333
02/18/19 20:00
02/18/19 20:00
Joined: Aug 2018
Posts: 101
O
OptimusPrime Offline
Member
OptimusPrime  Offline
Member
O

Joined: Aug 2018
Posts: 101
You are lacking brackets to make the sub-loop work. Right now, you are making price_asset_1 equal to price_asset_2. and both contain the price for the last asset you have in the while loop.


Thanks so much,

OptimusPrime

Re: Multi asset correlation [Re: OptimusPrime] #476384
02/21/19 20:27
02/21/19 20:27
Joined: Jun 2018
Posts: 16
P
Paul_der_Zweite Offline OP
Newbie
Paul_der_Zweite  Offline OP
Newbie
P

Joined: Jun 2018
Posts: 16
Hi OptimusPrime,
Thank you very much for your help.

This is now the current version of the script:
Code:
function run()
{
	//BarPeriod = 240;
	LookBack = 300;
	StartDate = 2018;
	//EndDate = 2019;
		
	vars price_asset_1, price_asset_2;
	var corr;
	
	while(asset(loop("AUD/CAD","AUD/JPY","AUD/NZD","AUD/USD","CAD/CHF","CAD/JPY","CHF/JPY","Cocoa","Coffee","Copper","Corn","Cotton","Esp35","EuBund","EUR/AUD","EUR/CAD","EUR/CHF","EUR/GBP","EUR/HUF","EUR/JPY","EUR/NOK","EUR/NZD","Euro50","EUR/PLN","EUR/SEK","EUR/SGD","EUR/TRY","EUR/USD","Fra40","Gasol","GBP/AUD","GBP/CAD","GBP/CHF","GBP/JPY","GBP/NZD","GBP/USD","GER30","GerTec","GOLD","Jp225","LCrude","Neth25","NGas","NZD/CAD","NZD/CHF","NZD/JPY","NZD/USD","OJ","SGD/JPY","SILVER","Soybns","Sugar","Swi20","TRY/JPY","UK100","Usa500","UsaInd","UsaRus","UsaTB","UsaTec","UsaVix","USD/BRL","USD/CAD","USD/CHF","USD/CNH","USD/HUF","USD/JPY","USD/MXN","USD/NOK","USD/PLN","USD/RUB","USD/SEK","USD/SGD","USD/TRY","USD/ZAR","Wheat")))
	{
		price_asset_1 = series(price());
		printf("n %s to", Asset);
	
	
		while(asset(loop("AUD/CAD","AUD/JPY","AUD/NZD","AUD/USD","CAD/CHF","CAD/JPY","CHF/JPY","Cocoa","Coffee","Copper","Corn","Cotton","Esp35","EuBund","EUR/AUD","EUR/CAD","EUR/CHF","EUR/GBP","EUR/HUF","EUR/JPY","EUR/NOK","EUR/NZD","Euro50","EUR/PLN","EUR/SEK","EUR/SGD","EUR/TRY","EUR/USD","Fra40","Gasol","GBP/AUD","GBP/CAD","GBP/CHF","GBP/JPY","GBP/NZD","GBP/USD","GER30","GerTec","GOLD","Jp225","LCrude","Neth25","NGas","NZD/CAD","NZD/CHF","NZD/JPY","NZD/USD","OJ","SGD/JPY","SILVER","Soybns","Sugar","Swi20","TRY/JPY","UK100","Usa500","UsaInd","UsaRus","UsaTB","UsaTec","UsaVix","USD/BRL","USD/CAD","USD/CHF","USD/CNH","USD/HUF","USD/JPY","USD/MXN","USD/NOK","USD/PLN","USD/RUB","USD/SEK","USD/SGD","USD/TRY","USD/ZAR","Wheat")))
		{
			price_asset_2 = series(price());
	
			corr = Correlation(price_asset_1, price_asset_2, 240);
	
			if(!is(LOOKBACK))
			printf("n %s = %f", Asset, corr);
		}
	}
}



It contains 2 nested while loops but unfortunately hangs.
And I don't understand the explanatory text output of the script yet.

I would like to output something like
"Asset_1 to Asset_2 = Correlation X"
"Asset_1 to Asset_3 = Correlation X"

and so on.

Any hint?

Re: Multi asset correlation [Re: Paul_der_Zweite] #476396
02/22/19 08:57
02/22/19 08:57
Joined: Jul 2000
Posts: 28,024
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,024
Frankfurt
This won't work either: Due to the special loop handling, the run function can call the loop() function once with assets and once with algos. Not two times with assets.

So, replace at least the second loop() call with a normal for() or while() loop, like this:

for(used_assets) { ...


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1