Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Imhotep, opm), 785 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
findContract not finding a contract #482553
02/23/21 10:33
02/23/21 10:33
Joined: Jan 2021
Posts: 22
Singapore
S
strimp099 Offline OP
Newbie
strimp099  Offline OP
Newbie
S

Joined: Jan 2021
Posts: 22
Singapore
Greetings,

I'm finding some interesting behavior when using contractPrint() and findContract(). My goal is to find a contract that is near the money and close to TRADE_ENTRY_DTE days from expiration.

Consider the following simple script which loads options chains, iterates through the contracts and prints the contract records to a CSV file.

Code
void run() 
{

	StartDate = 20120101;
	EndDate = 20181231;
	BarPeriod = 1440;

	// optimized parameters
	var TRADE_ENTRY_DTE = 6*7; // days to expiration to enter trade

	History = "*.t8";
	assetList("AssetsOptions");
	asset("RUT");
		
	Multiplier = 100;
	
	// get the underlying closing price
	var p = priceClose();
	
	// load today's contract chain
	if(!contractUpdate(Asset,0,CALL|PUT)) return;
	printf("\n%s Asset=%s, contractsFound=%i",strdate(YMD,ldate(ET,0)),Asset,NumContracts);
	
	int i;
	for (i=0; i < NumContracts; i++)
	{
		CONTRACT* C = &Contracts[i];
		contract(C);
		print(TO_CSV,"\nRecord=%i; Time=%s, Type=%i; Expiry=%i; Strike=%f; Bid=%f; Ask=%f; Vol=%f; Unl=%f; Delta=%f;",i,strdate(YMD,ldate(ET,0)),ContractType,ContractExpiry,ContractStrike,ContractBid,ContractAsk,ContractVol,ContractUnl,ContractVal);
	}

	CONTRACT* initCall = contractFind(CALL,TRADE_ENTRY_DTE,p,6);
	
}


In the output CSV, I filter on 2011-09-08 trading day, call option strike=700 (near the underlying) and expiration 2011-10-21 (43 days to expiration). This contract is highlighted in the screenshot 1.PNG.

When I replace the print statement with contractPrint(C, TO_WINDOW), there is a slight variation in what is being printed. For example the fVal is not printed but otherwise the data is populated which should allow me to select the contract. See screenshot 2.PNG.

When I call contractFind as such

Code
CONTRACT* initCall = contractFind(CALL,TRADE_ENTRY_DTE,p,6);


No contract is ever found even though given 6*7=42 is sufficiently close to the minimum life in days (ie 43) and the strike is within 5.10 of the strike.

Why is contractFind not finding my contract?

Attached Files 1.PNG2.PNG
Re: findContract not finding a contract [Re: strimp099] #482558
02/24/21 07:33
02/24/21 07:33
Joined: Jan 2021
Posts: 22
Singapore
S
strimp099 Offline OP
Newbie
strimp099  Offline OP
Newbie
S

Joined: Jan 2021
Posts: 22
Singapore
I figured out why contractPrint is printing a zero for fVal. In my data, fVal represents delta which is bound -1.0 ... 1.0. In my dataset, only 4725 records out of 9613258 have delta either -1.0 or 1.0.

The contractPrint code (found in contract.c) casts the fVal variable to an int thereby rounding down (up) to 0 when -1.0<delta<1.0 which is the vast majority of my cases.

Code
void contractPrint(CONTRACT* c,int To)
{
	if(!c) return; 
	print(To,"\n%s,%s%s%s,%i,%.4f,%.4f,%.4f,%.4f,%i,%i,%s",
		ifelse(is(TRADEMODE),(char *)c,strdate("%Y-%m-%d",c->time)),
		ifelse(c->Type&FUTURE,"Future",""),
		ifelse(c->Type&PUT,"Put",""),
		ifelse(c->Type&CALL,"Call",""),
		c->Expiry,(var)c->fStrike,(var)c->fUnl,(var)c->fAsk,(var)c->fBid,(int)c->fVal,(int)c->fVol, // <--- (int)c->fVal
		ifelse(is(TRADEMODE),strcon(c),""));
}


This of course does not solve my contractFind issue...

Re: findContract not finding a contract [Re: strimp099] #482560
02/25/21 07:47
02/25/21 07:47
Joined: Jan 2021
Posts: 22
Singapore
S
strimp099 Offline OP
Newbie
strimp099  Offline OP
Newbie
S

Joined: Jan 2021
Posts: 22
Singapore
I figured it out! CALL is defined as 1, PUT is defined as 2.

A European option is defined as 1<<2.

My data source includes the exercise type, European (E) or American (A).

In my data parsing script, contract type is defined as such:

Code
O->Type = ifelse(*PC == 'P',PUT,CALL) + ifelse(*EA == 'E',EUROPEAN,0);


This means for a European call option, type is 1 + 1 * 2^2 = 5 and a European put option type is 2 + 1 * 2^2 = 6.

When redfine CALL as 5 and PUT as 6, my contract is found!

Last edited by strimp099; 02/25/21 08:41.
Re: findContract not finding a contract [Re: strimp099] #482561
02/25/21 11:53
02/25/21 11:53
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Or you could search for PUT|EUROPEAN and CALL|EUROPEAN. Probably best not to redefine standard Zorro macros.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1