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
5 registered members (Quad, AndrewAMD, Imhotep, TipmyPip, Edgar_Herrera), 809 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
Page 1 of 2 1 2
Trading options with Zorro: How to calculate Delta #465968
05/18/17 20:24
05/18/17 20:24
Joined: Nov 2016
Posts: 66
GreenBoat Offline OP
Junior Member
GreenBoat  Offline OP
Junior Member

Joined: Nov 2016
Posts: 66
I would like to test Delta hedging / Delta neutral strategies.

Is there some easier way how to calculate Delta, then using contractVal with all the inputs?

I have historical option prices (option chain for every day).

Re: Trading options with Zorro: How to calculate Delta [Re: GreenBoat] #465974
05/19/17 06:50
05/19/17 06:50
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Yes, you can calculate it from the premium price difference divided by the spot price difference.

Re: Trading options with Zorro: How to calculate Delta [Re: jcl] #465980
05/19/17 08:33
05/19/17 08:33
Joined: Nov 2016
Posts: 66
GreenBoat Offline OP
Junior Member
GreenBoat  Offline OP
Junior Member

Joined: Nov 2016
Posts: 66
So easy, why didn't I think of that!

Thank you jcl

Re: Trading options with Zorro: How to calculate Delta [Re: GreenBoat] #466000
05/19/17 12:40
05/19/17 12:40
Joined: Nov 2016
Posts: 66
GreenBoat Offline OP
Junior Member
GreenBoat  Offline OP
Junior Member

Joined: Nov 2016
Posts: 66
I am trying to calculate delta as mentioned, but unfortunately the result is not as expected.

Few examples (from Interactive Brokers platform):

SPY, expiration today, PUTs:

Strike 237, PUT midpoint price 0.835, Delta -0.696
Strike 236, PUT midpoint price 0.44, Delta -0.240
Premium price difference 0.395 is not near the deltas.

SPY, expiration in 28 days, PUTs:

Strike 237, PUT midpoint price 3.48, Delta -0.573
Strike 236, PUT midpoint price 3.08, Delta -0.513
Premium price difference 0.4 is not near the deltas.

DAX, expiration in 28 days, CALLs:

Strike 12650, CALL midpoint price 158.5, Delta 0.474
Strike 12700, CALL midpoint price 133, Delta 0.427
Premium price difference 25.5/50=0.51 is at least near the deltas, but it is not too precise.

I guess that the problem is, that with different strike not only Delta changes, but also Implied Volatility. So the calculation of Delta should be a bit more complex.

I think that I have to use contractVal.

Re: Trading options with Zorro: How to calculate Delta [Re: GreenBoat] #466001
05/19/17 13:04
05/19/17 13:04
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Yes, this cannot work since you used premiums with different strikes. You need of course the same strike and expiry for calculating the delta. And use prices not too far apart - only a hour or so, and with no large volatility change. Otherwise you get no delta, but some mix from delta, theta, and vega.

Re: Trading options with Zorro: How to calculate Delta [Re: jcl] #466003
05/19/17 13:50
05/19/17 13:50
Joined: Nov 2016
Posts: 66
GreenBoat Offline OP
Junior Member
GreenBoat  Offline OP
Junior Member

Joined: Nov 2016
Posts: 66
Makes sense...

I have only End Of Day historical data.

Unfortunately, indeed, it doesn't work with EOD data + actual prices, at all:

Example from IB

DAX:
Strike 12650, expiration in 28 days
- yesterday's option close price 228, underlying close price 12590
- today's option price 195, underlying price 12613
- delta -0.535
Calculation: 33/23=1.43

SPY:
Strike 238, expiration in 28 days
- yesterday's option close price 2.10, underlying close price 236.77
- today's option price 2.29, underlying price 237.6
- delta 0.49
Calculation: 0.19/0.83=0.22

I am going to continue with Zorro's implemented functions.

Re: Trading options with Zorro: How to calculate Delta [Re: GreenBoat] #466492
06/16/17 19:43
06/16/17 19:43
Joined: Nov 2016
Posts: 66
GreenBoat Offline OP
Junior Member
GreenBoat  Offline OP
Junior Member

Joined: Nov 2016
Posts: 66
I finished a simple script for Delta calculation. Feel free to use it:
Code:
#include <contract.c> // needed for options

function run()
{
	BarPeriod = 1440; // 1 bar is 24 hours
	BarZone = ET; // SPY is in New York
	BarOffset = 15*60 + 50; // set the bar end to 15:50, 10 minutes before the market close	
	StartDate = 20161131;
	EndDate = 20161231;
	EndWeek = 52100;
	LookBack = 256; // 256 = 1 year
	set(PRELOAD+LOGFILE);

	assetList("AssetsOnlyFew");
	//assetHistory("SPY",FROM_YAHOO);
	asset("SPY");
	if(is(INITRUN)) {
		initRQL();	// run R
		dataLoad(1,"SPY_Options.t8",9);
	}
	if(is(LOOKBACK)) return;

// load today's contract chain
	int N = contractUpdate(Asset,1,CALL|PUT);
	Multiplier = 100;
	if(!N) {
		printf("#nNo contracts at bar %i",Bar);
		return;
	}
	
// determine the current underlying price (unadjusted)
	var CurrentPrice = ifelse(is(TRADEMODE),priceClose(),Contracts->fUnl);
	
// Select contract and calculate delta and implied volatility
	CONTRACT* CImp = contract(PUT|ONLYW3,1,CurrentPrice-2);
	contractPrint(CImp,TO_LOG); // print contract values to the log file

  	var OptionPrice = contractPrice(CImp); // bid/ask average price
  	var HistVolAnnual = VolatilityOV(20);
	var Delta = 0;
	
	var ImpliedVol = contractVol(CImp,CurrentPrice,HistVolAnnual,OptionPrice,0,0); // calculate Implied volatility
	print(TO_LOG,"nImpliedVol %g",ImpliedVol);
	
	// contractVal (CONTRACT*, var Price, var HistVol, var Dividend, var RiskFree, var* Delta, var* Gamma, var* Vega, var* Theta, var* Rho): var
	var ThValue = contractVal (CImp,CurrentPrice,HistVolAnnual,0.02,0.02,&Delta);
	print(TO_LOG,"nDelta = %g",Delta);
	print(TO_LOG,"nTheoretical value (contractVal) = %g",ThValue);
}


I would like to compare the outputs with some other source(s), so I can be sure that the calculation is correct.

I didn't bother to use the exact dividend and risk free rate for this first test. I believe that it's not that important (I use approximate fixed values).

I have ThinkOrSwim free account (it's probably the nicest platform for options trading and they have historical data with Greeks) and I am trying to compare my values with this source. If you know about any other source, I'll be happy to try it.

Bid and Ask prices are exactly the same from both data sources (I have historical data from IVolatility), so there shouldn't be any problem there. There might be some problem with historical volatility, because I can see that ThinkOrSwim doesn't have exactly the same underlying prices as I can see in Zorro log file. However, the differences are very small, like 219.57 (ThinkOrSwim) and 219.73 (Zorro).

It looks that the calculated implied volatility is (most of the time) almost exactly the same like in the ThinkOrSwim platform. Only Deltas are a bit too different in my opinion and I am thinking what might be the reason.

The question is, if it means that I need to improve my script. Maybe that ThinkOrSwim has some specific Delta calculation and I shouldn't use it for comparison at all.

Few examples:

Zorro log file:
2016-12-01,Put,20161216,217.5000,219.7300,1.8700,1.8400,9576
ImpliedVol 0.159051
Delta = -0.310674

ThinkOrSwim:
ImpliedVol 15.33
Delta -0.37


Zorro log file:
2016-12-06,Put,20161216,219.5000,221.5900,1.0500,1.0200,12594
ImpliedVol 0.129566
Delta = -0.283869

ThinkOrSwim:
ImpliedVol 12.82
Delta -0.32


Zorro log file:
2016-12-13,Put,20161216,226.0000,227.8600,0.8800,0.8400,12904
ImpliedVol 0.196424
Delta = -0.243288

ThinkOrSwim:
ImpliedVol 16.83
Delta -0.32


Zorro log file:
2016-12-15,Put,20161216,225.0000,226.8700,0.3600,0.3500,43434
ImpliedVol 0.217107
Delta = -0.130342

ThinkOrSwim:
ImpliedVol 15.23
Delta -0.24


Zorro log file:
2016-07-01,Put,20160715,208.0000,210.0300,1.1600,1.1500,73349
ImpliedVol 0.122174
Delta = -0.426875

ThinkOrSwim:
ImpliedVol 11.79
Delta -0.34


Zorro log file:
2016-07-22,Put,20160819,215.0000,217.0800,1.6700,1.6400,104783
ImpliedVol 0.106583
Delta = -0.394118

ThinkOrSwim:
ImpliedVol 10.76
Delta -0.36


Zorro log file:
2016-08-17,Put,20160819,216.5000,218.4000,0.2000,0.1900,25813
ImpliedVol 0.126256
Delta = -0.156243

ThinkOrSwim:
ImpliedVol 10.33
Delta -0.18

Re: Trading options with Zorro: How to calculate Delta [Re: GreenBoat] #466586
06/22/17 08:34
06/22/17 08:34
Joined: Nov 2016
Posts: 66
GreenBoat Offline OP
Junior Member
GreenBoat  Offline OP
Junior Member

Joined: Nov 2016
Posts: 66
Are the greeks obtained in Zorro using the ContractVal function computed numerically or by some explicit formulas? I tried to compute the greeks inserting the implied volatility (called by the ContractVol function in Zorro) explicitly in the Black-Scholes formula and evaluating the corresponding partial derivatives numerically using a small increment of spot price/time/volatility etc and compared these values to those provided by Zorro. Although the theta, gamma, vega and rho greeks exhibit good mutual agreement, this is not the case with delta, which still does not correspond to the value provided by Zorro. Do you have an explanation for that?

Re: Trading options with Zorro: How to calculate Delta [Re: GreenBoat] #466589
06/22/17 10:15
06/22/17 10:15
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
I think they are computed numerically for American options and with Black-Scholes for European options.

Re: Trading options with Zorro: How to calculate Delta [Re: jcl] #466686
06/27/17 13:21
06/27/17 13:21
Joined: Nov 2016
Posts: 66
GreenBoat Offline OP
Junior Member
GreenBoat  Offline OP
Junior Member

Joined: Nov 2016
Posts: 66
I compared:
- numerically computed Deltas
- ThinkOrSwim (options' platform with historical data) Deltas
- Deltas calculated by Zorro

Both numerically computed Deltas and ThinkOrSwim Deltas are almost the same. But the Deltas from Zorro are different, the difference is sometimes as high as 10 Delta points. The closer to the expiration date, the higher is the difference, which is weird.

Zorro calculates the Delta like this:

Delta = Rd("Option$delta");

Option$delta is RQuantlib function.

I didn't find information about this function frown

Any hint where can I find RQuantLib Delta formula?

Page 1 of 2 1 2

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1