Gamestudio Links
Zorro Links
Newest Posts
Trading Community Project
by danatrader. 05/30/20 20:28
Out of Sample
by danatrader. 05/30/20 20:02
MT4/5 - wrong M1 time
by Grat. 05/30/20 19:14
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 05/30/20 15:18
Windows 10 file_write error
by AndrewAMD. 05/30/20 13:57
stencil blur does not work - SOLVED
by NicolaB. 05/30/20 12:13
Question about Pattern - Workshop7
by danatrader. 05/30/20 09:09
Test - watch noncomplete data
by Grat. 05/30/20 05:38
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
11 registered members (3run, Dooley, danatrader, kvm, Grat, onoff, Sniv, Jerome8911, happysun, 1 invisible), 531 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
PBSeven, Hardi01, Giuseppe, AdamWu, gariki
18460 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Error 016: Date range for Algorithmic Options Trading 3 examples #479539
04/05/20 06:36
04/05/20 06:36
Joined: Apr 2020
Posts: 7
B
beo Offline OP
Newbie
beo  Offline OP
Newbie
B

Joined: Apr 2020
Posts: 7
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?

Re: Error 016: Date range for Algorithmic Options Trading 3 examples [Re: beo] #479541
04/05/20 07:42
04/05/20 07:42
Joined: Apr 2008
Posts: 299
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 299
Austria
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".

Re: Error 016: Date range for Algorithmic Options Trading 3 examples [Re: beo] #479546
04/05/20 14:46
04/05/20 14:46
Joined: Apr 2020
Posts: 7
B
beo Offline OP
Newbie
beo  Offline OP
Newbie
B

Joined: Apr 2020
Posts: 7
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.

Re: Error 016: Date range for Algorithmic Options Trading 3 examples [Re: Petra] #479551
04/05/20 22:05
04/05/20 22:05
Joined: Apr 2020
Posts: 7
B
beo Offline OP
Newbie
beo  Offline OP
Newbie
B

Joined: Apr 2020
Posts: 7
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);
	}
}

Re: Error 016: Date range for Algorithmic Options Trading 3 examples [Re: beo] #479558
04/06/20 08:40
04/06/20 08:40
Joined: Jul 2000
Posts: 27,212
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,212
Frankfurt
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.

Re: Error 016: Date range for Algorithmic Options Trading 3 examples [Re: jcl] #479566
04/06/20 13:05
04/06/20 13:05
Joined: Apr 2020
Posts: 7
B
beo Offline OP
Newbie
beo  Offline OP
Newbie
B

Joined: Apr 2020
Posts: 7
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.

Re: Error 016: Date range for Algorithmic Options Trading 3 examples [Re: beo] #479618
04/12/20 10:33
04/12/20 10:33
Joined: Apr 2008
Posts: 299
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 299
Austria
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.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1