Gamestudio Links
Zorro Links
Newest Posts
System with more take profit
by tomna1993. 05/12/21 13:55
Backtest accuracy
by tomna1993. 05/12/21 13:29
How to: plot a frequency spectrum in bars?
by Sempervirens. 05/12/21 12:04
Test one asset with more bar period in one run
by AndrewAMD. 05/12/21 10:12
EXANTE broker
by madpower2000. 05/11/21 17:02
No Trades when Backtesting Period is longer
by TimmiHendrix. 05/11/21 15:47
Last Candle for Testing and Train?
by jcl. 05/11/21 12:14
DataSplit for Advise
by TimmiHendrix. 05/11/21 10:40
AUM Magazine
Latest Screens
Hecknex World
Scheherazade's Journey
Paradox Vector
The Space Between
Who's Online Now
9 registered members (tomna1993, AndrewAMD, 3run, onoff, JeyKey II, Sempervirens, Nomi, 2 invisible), 481 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
ShadowAx, TimmiHendrix, contactmmfx, msupl7, Robert_
18644 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,255
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,255
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