Gamestudio Links
Zorro Links
Newest Posts
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
LPDIRECT3DCUBETEXTUR
E9

by Ayumi. 04/12/24 11:00
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 04/11/24 14:56
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (firecrest, AndrewAMD), 387 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
11honza11, ccorrea, sakolin, rajesh7827, juergen_wue
19045 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: 98
O
OptimusPrime Offline
Junior Member
OptimusPrime  Offline
Junior Member
O

Joined: Aug 2018
Posts: 98
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: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
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