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.
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?
Re: findContract not finding a contract
[Re: strimp099]
#482558 02/24/2107:3302/24/2107:33
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.