Error 016: Date range for Algorithmic Options Trading 3 examples

Posted By: beo

Error 016: Date range for Algorithmic Options Trading 3 examples - 04/05/20 06:36

Hi,

https://financial-hacker.com/algorithmic-options-trading-part-3/

The scripts from the above example fails. For some reason
Code
StartDate = 20110101;
EndDate = 20161231;

is getting misinterpreted as 2019 to 2017.

Code
Zorro 2.25.7
(c) oP group Germany 2020


aaa_strangle_without_roll compiling....................
Error 016: Date range 2019-12-31 14:30:00 - 2017-01-01 23:58:33
Error 055: No bars generated


I downloaded the SPY.t8 and SPYa.t8, but I suspect it is not finding it.

What's the next step here?
Posted By: Petra

Re: Error 016: Date range for Algorithmic Options Trading 3 examples - 04/05/20 07:42

Maybe you started the wrong script? or downloaded the spy history in a wrong folder?

The name of that script is "OptionsSimple.c", not "aa_strangle_something".
Posted By: beo

Re: Error 016: Date range for Algorithmic Options Trading 3 examples - 04/05/20 14:46

Oh, I copy-pasted to my own script from the webpage.

I found the issue. Apparently the SPY_20XX.t6 files getting downloaded were corrupt, but the SPY.t6 was good. So deleting the SPY_20XX.t6 files resolved the issue and now I can do EOD backtesting with artificial SPY Options data.

Cool. laugh

Next step is to try to find tick (t8) data for SPY 2020. I am going to plot intra-minute histogram of the EOD closing price as the last minute or so elapses.
Posted By: beo

Re: Error 016: Date range for Algorithmic Options Trading 3 examples - 04/05/20 22:05

Okay, when I run this script over 2020 YTD with EOD t6 data, we get some weirdness starting in March. findCall() and findPut() are failing to find a contract. The code may have a bug in how it selects the option.

Code
CONTRACT* findCall(int Expiry,var Premium)
{
	for(i=0; i<50; i++) {
		if(!contract(CALL,Expiry,Price+0.5*i)) return 0;
		if(between(ContractBid,0.1,Premium)) return ThisContract;
	}
	return 0;
}

This call exits when contract(CALL,Expiry,Price+0.5*i) fails instead of searching through the remaining strike prices.

I tried contractFind() though I have a similar issue with not finding contracts after 02-24. Here is the script with my debug printfs.

Code
// OptionsSimple.c

// Quite simple options trading system 
// WITHOUT ROLL 

// https://financial-hacker.com/algorithmic-options-trading-part-3/


// Even simpler options trading system 
#include <contract.c>

#define EXPIRY_DAYS	2		// default 6*7
#define PREMIUM		2.0		// default 2.0

int i;
var Price;

CONTRACT* findCall(int Expiry,var Premium)
{
	for(i=0; i<100; i++) {
		if(!contractFind(CALL,Expiry,Price+1.0*i,2,Price,Price+50))
		{
			printf("\nbeo: !contractFind(CALL,... Strike=%.02f,2,...) Premium %.02f.", Price-1.0*i, Premium);
			return 0;
		}
		if(between(ContractBid,0.1,Premium))
		{
			printf("\nbeo: between(ContractBid %.02f,0.1,Premium %.02f)", ContractBid, Premium);
			return ThisContract;
		}
	}
	return 0;
}

CONTRACT* findPut(int Expiry,var Premium)
{
	for(i=0; i<100; i++) {
		if(!contractFind(PUT,Expiry,Price-1.0*i,2,Price-50, Price)) 
		{
			printf("\nbeo: !contractFind(PUT,... Strike=%.02f,2,...) Premium %.02f.", Price-1.0*i, Premium);
			return 0;
		}
		if(between(ContractBid,0.1,Premium)) 
		{
			printf("\nbeo: between(ContractBid %.02f,0.1,Premium %.02f)", ContractBid, Premium);
			return ThisContract;
		}
	}
	return 0;
}

void run() 
{
	StartDate = 20200101;
	EndDate = 20200403;
	BarPeriod = 1440;
	BarZone = ET;
	BarOffset = 15*60+20; // trade at 15:20 ET
	LookBack = 1;
	set(PLOTNOW);
	set(PRELOAD|LOGFILE);

	assetList("AssetsIB");
	asset("SPY"); // unadjusted!
	Multiplier = 100;

// load today's contract chain
	Price = priceClose();
	contractUpdate("SPY",0,CALL|PUT);

// all expired? enter new options
	if(!NumOpenShort) { 
		CONTRACT *Call = findCall(EXPIRY_DAYS,PREMIUM); 
		CONTRACT *Put = findPut(EXPIRY_DAYS,PREMIUM); 		
		if(Call && Put) {
			MarginCost = 0.5*(0.15*Price-min(Call->fStrike-Price,Price-Put->fStrike));
			contract(Call); enterShort();
			contract(Put); enterShort();
		}
		else if (Call)
		{
			printf("\nbeo: found Call, no Put. %.02fC for %.02f$\n", Call->fStrike, Price);
		}
		else if (Put)
		{
			printf("\nbeo: found Put, no Call. %.02fC for %.02f$\n", Put->fStrike, Price);
		}
		else
		{
			printf("\nbeo: no call or put. Price %.02f$\n", Price);
		}
	}
	else
	{
		// printf("\nbeo: NumOpenShort does not exist. Price %.02f$\n", Price);
	}
}
Posted By: jcl

Re: Error 016: Date range for Algorithmic Options Trading 3 examples - 04/06/20 08:40

The article was from 2017. With the current Zorro you can use contractFind(). If no contracts are found at a certain date, you can see the reason by looking in the historical data. With Zorro S you can use the History script, with the free version convert the data first to CSV. It's not necessarily a gap. It can also be an illiquid market with no contract prices.
Posted By: beo

Re: Error 016: Date range for Algorithmic Options Trading 3 examples - 04/06/20 13:05

jcl, thanks for writing.

I did replace it with contractFind() without success in the region specified. I suspect my data history as well. It had been using SPY.t6, which was EOD unadjusted until it was overwritten by another script accidentally. The history.csv file looks fine, but it's just EOD data.

I do have the SPY.t8 and SPYa.t8 from the website, though they lack the recent history which we are about to need again. I can chart it but otherwise have no idea how to use that data for this.

I think since VIX was going so high, it would be questionable as to the liquidity of the option market at that time. I would expect that it was rather liquid as the open interest was going up.

I am not sure where to go from here.
Posted By: Petra

Re: Error 016: Date range for Algorithmic Options Trading 3 examples - 04/12/20 10:33

If it was overwritten why not download the spy.t8 again from the download page? I think it has no gaps.

If no contract with a certain strike existed at a certain date then either do not trade at that day or select a contract with a strike closer to the spot price.
© 2024 lite-C Forums