Gamestudio Links
Zorro Links
Newest Posts
EntryDelay Clarification
by Ger1
Yesterday at 22:11
strf length-limitation
by Grant
Yesterday at 18:49
Deformers struct in MDL7 abspeichern.
by tagimbul
Yesterday at 17:41
Compiling Trading Strategies with C++
by pascalx
Yesterday at 12:18
global breakeven of a portfolio inside tmf function
by kmerlo
08/19/17 12:21
AUM Magazine
Latest Screens
AckCon'17: Lotter vs The World
Triton Wing
ZeaL
Computer Repair Simulator
Collider (working title)
Who's Online
11 registered (3dgamelight, Grant, alibaba, Iglarion, jrath, JoFo, jyd, tagimbul, mk_1, 1 invisible), 447 Guests and 4 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
mqo, Aimak, Grant, Marce, pascalx
17719 Registered Users
Page 1 of 2 1 2 >
Topic Options
Rate This Topic
#465968 - 05/18/17 22:24 Trading options with Zorro: How to calculate Delta
GreenBoat Offline
Junior Member

Registered: 11/06/16
Posts: 51
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).

Top
#465974 - 05/19/17 08:50 Re: Trading options with Zorro: How to calculate Delta [Re: GreenBoat]
jcl Offline

Chief Engineer

Registered: 07/22/00
Posts: 25661
Loc: Frankfurt
Yes, you can calculate it from the premium price difference divided by the spot price difference.

Top
#465980 - 05/19/17 10:33 Re: Trading options with Zorro: How to calculate Delta [Re: jcl]
GreenBoat Offline
Junior Member

Registered: 11/06/16
Posts: 51
So easy, why didn't I think of that!

Thank you jcl

Top
#466000 - 05/19/17 14:40 Re: Trading options with Zorro: How to calculate Delta [Re: GreenBoat]
GreenBoat Offline
Junior Member

Registered: 11/06/16
Posts: 51
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.

Top
#466001 - 05/19/17 15:04 Re: Trading options with Zorro: How to calculate Delta [Re: GreenBoat]
jcl Offline

Chief Engineer

Registered: 07/22/00
Posts: 25661
Loc: 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.

Top
#466003 - 05/19/17 15:50 Re: Trading options with Zorro: How to calculate Delta [Re: jcl]
GreenBoat Offline
Junior Member

Registered: 11/06/16
Posts: 51
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.

Top
#466492 - 06/16/17 21:43 Re: Trading options with Zorro: How to calculate Delta [Re: GreenBoat]
GreenBoat Offline
Junior Member

Registered: 11/06/16
Posts: 51
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

Top
#466586 - 06/22/17 10:34 Re: Trading options with Zorro: How to calculate Delta [Re: GreenBoat]
GreenBoat Offline
Junior Member

Registered: 11/06/16
Posts: 51
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?

Top
#466589 - 06/22/17 12:15 Re: Trading options with Zorro: How to calculate Delta [Re: GreenBoat]
jcl Offline

Chief Engineer

Registered: 07/22/00
Posts: 25661
Loc: Frankfurt
I think they are computed numerically for American options and with Black-Scholes for European options.

Top
#466686 - 06/27/17 15:21 Re: Trading options with Zorro: How to calculate Delta [Re: jcl]
GreenBoat Offline
Junior Member

Registered: 11/06/16
Posts: 51
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?

Top
Page 1 of 2 1 2 >



Gamestudio download | chip programmers | Zorro platform | shop | resources | magazine | manual | support faq | bugs | beta features

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) 3dgamestudio.net