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
Multiple assets with options #466442
06/14/17 12:20
06/14/17 12:20
Joined: Nov 2016
Posts: 66
GreenBoat Offline OP
Junior Member
GreenBoat  Offline OP
Junior Member

Joined: Nov 2016
Posts: 66
I am trying to use multiple assets for options trading.

I can't make it work. I would like to ask, if it's even possible?

It looks that I can't use the function contractUpdate with multiple assets?

My script is working fine, when I use it with one asset. When I add one more, there are errors like "Invalid contract parameters" or "Invalid contract".

Re: Multiple assets with options [Re: GreenBoat] #466443
06/14/17 12:48
06/14/17 12:48
Joined: Nov 2016
Posts: 66
GreenBoat Offline OP
Junior Member
GreenBoat  Offline OP
Junior Member

Joined: Nov 2016
Posts: 66
The script is as simple as possible:
Code:
void run() {
	set(PRELOAD|LOGFILE);
	BarPeriod = 1440;
	BarZone = ET;
	BarOffset = 15*60;
	StartDate = 20130101;
	EndDate = 20151231;
	PlotWidth = 1000;
	PlotHeight1 = 400;
	Multiplier = 100;

	assetList("Assets");

	if(is(FIRSTINITRUN)) {
		asset("SPY");
		dataLoad(1,"SPY_Options.t8",9);
		asset("YHOO");
		dataLoad(2,"YHOO_OptionsSim.t8",9);
	}

  	string assetName;
  	while (assetName = loop(Assets)) {
		asset(assetName);
		if (assetName == "SPY")	contractUpdate(assetName,1,CALL|PUT);
		else if (assetName == "YHOO")	contractUpdate(assetName,2,CALL|PUT);
		var CurrentPrice = ifelse(is(TRADEMODE),priceClose(),Contracts->fUnl); // the current underlying price (unadjusted)
		CONTRACT* c = contract(PUT|ONLYW3,30,CurrentPrice);
		if(contractDays(c) == 31 /*&& assetName == "YHOO"*/) enterShort();
  	}
  	
}


Re: Multiple assets with options [Re: GreenBoat] #466447
06/14/17 16:45
06/14/17 16:45
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
You can have as many assets as you want. The selected asset does not matter for contractUpdate, since you give the underlying name explicitely in the call. This is because the underlying name is sometimes different to the asset name.

Check how many contracts are in the chain and if the selected contract really exists.

Re: Multiple assets with options [Re: jcl] #466483
06/16/17 14:43
06/16/17 14:43
Joined: Nov 2016
Posts: 66
GreenBoat Offline OP
Junior Member
GreenBoat  Offline OP
Junior Member

Joined: Nov 2016
Posts: 66
The script is working! Your answer helped me, thank you.

Another thing is, that I was getting "Crash in the script error", only once, at the first day after the lookback period.

After debugging, I found that:
- the error is there only when I use SPY data (from IVolatility)
- the error is not there when I use artificial historical data generated by financial-hacker script
- the error is caused by Contracts->fUnl
- the error is there when the code looks like this:
Code:
while (assetName = loop(Assets)) {
		if (assetName == "SPY") contractUpdate(assetName,1,CALL|PUT);
		else if (assetName == "YHOO") contractUpdate(assetName,2,CALL|PUT);
		asset(assetName);
		var CurrentPrice = ifelse(is(TRADEMODE),priceClose(),Contracts->fUnl);
......


when I select the asset before contractUpdate, there is no Crash in the script. My code without errors is:
Code:
while (assetName = loop(Assets)) {
		asset(assetName);
		if (assetName == "SPY") contractUpdate(assetName,1,CALL|PUT);
		else if (assetName == "YHOO") contractUpdate(assetName,2,CALL|PUT);
		var CurrentPrice = ifelse(is(TRADEMODE),priceClose(),Contracts->fUnl);


Re: Multiple assets with options [Re: GreenBoat] #466484
06/16/17 15:15
06/16/17 15:15
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
This code crashes when "Contracts" is zero. Which happens on all assets except SPY and YHOO. So don't use the Contracts pointer except when contractUpdate was called before and didn't fail.

Re: Multiple assets with options [Re: jcl] #466486
06/16/17 15:50
06/16/17 15:50
Joined: Nov 2016
Posts: 66
GreenBoat Offline OP
Junior Member
GreenBoat  Offline OP
Junior Member

Joined: Nov 2016
Posts: 66
I forget to mention, that I have only two assets in the assets file:

Name,Price,Spread,RollLong,RollShort,PIP,PIPCost,MarginCost,Leverage,LotAmount,Commission,Symbol
SPY,215,0.02,0,0,0.01,0.01,0,4,1,0.02,
YHOO,215,0.02,0,0,0.01,0.01,0,4,1,0.02,

The second version of the code doesn't crash. Only the first version of the code causes crash, which is the version where asset(assetName) is after contractUpdate. And it crashes only once, one day after lookback period.

Re: Multiple assets with options [Re: GreenBoat] #466512
06/19/17 07:55
06/19/17 07:55
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
I've just checked it, and found that what I said above is wrong - the underlying must be in fact selected with asset() before and not after contractUpdate(). This will be added to the manual. Reason is that the option chain is individually stored per asset. So the second version of your script is the right one. When only two assets are in the assets file, it won't crash.

Re: Multiple assets with options [Re: jcl] #466513
06/19/17 07:59
06/19/17 07:59
Joined: Nov 2016
Posts: 66
GreenBoat Offline OP
Junior Member
GreenBoat  Offline OP
Junior Member

Joined: Nov 2016
Posts: 66
Glad to hear that laugh


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1