Hedging in ThetaScript
From ThetaWiki
Contents |
Introduction
Hedging is the method for creating a portfolio with a risky financial instrument which is almost risk free. In the following, we are going to set up a hedged portfolio Pi as
Pi = V + d * S
with option V and a position of d in the hedge instrument S. The task of the hedging procedure is to chose d such that the portfolio Pi does not change much even if the underlying S changes.
We start with a simple example where the process S is driven by Geometric Brownian Motion with a drift equal to the risk-free rate of interest. This allows us to apply the Black-Scholes-Merton equation for d and corresponds to Delta-Hedging (see Black-Scholes Option Pricing for details).
Delta Hedging
The Black-Scholes Option Pricing is based on Delta hedging. This defines a portfolio Pi with Pi = V + d * S that can be made completely risk free in the idealized Black-Scholes market. This is unrealistic in the real world mainly since the hedge must be rebalanced continuously in time while a real trader can only buy and sell at discrete times. In this section, we will analyze the error which occurs when one uses discrete instead of continuous hedges.
In this example, we use the option delta d of a European put option V. This value is known as
where N() is the cummulative normal distribution.
With this knowledge, and remembering that ThetaScript can call any regular Matlab function, it is easy to write a corresponding ThetaScript to compute the delta of a European put option.
ThetaScript model for Black-Scholes Delta
%% This model returns the Black-Scholes hedge ratio "delta" for %% European put and call options. model OptionDelta import S "Current stock price" import K "European strike price" import sigma "Volatility of the underlying" import r "Risk-free interest rate" import T "Maturity time of the option" export delta "Black-Scholes delta" if T<=0 delta = S<K; else d1 = ( log(S/K) + (r + (sigma^2)/2)*T ) / (sigma * sqrt(T)); delta = normcdf(d1,0,1)-1; end end
All subsequent examples use the following assumptions:
- Stochastic Model Geometric Brownian Motion,
- Volatility sigma: 0.4 (40% p.a.)
- Risk-free rate r: 0.05 (5% p.a.)
- Current Stock price S: 100
- Numeraire value EUR: 1
- Structural Model
- Strike K: 100
- Maturity time T: 1
ThetaScript model for Black-Scholes Hedge Simulation (forwards)
%% The model European_hedged_BS_forwards simulates the "delta" %% hedge of a European put option. Note that the Black-Scholes %% delta is optimal for the risk-neutral geometric Brownian motion. model European_hedged_BS_forwards import S "Stock" import EUR "Numeraire" import sigma "Volatility" import r "Interest rate" import K "Strike" export Pi "Portfolio Value" export delta "Hedge ratios (Black-Scholes)" export error "Hedging error" T = 1 n = 250*T Pi = E(V) loop n call OptionDelta export K, sigma, r export S/EUR to S export T-@time to T import delta % Portfolio value at the next time-step S_old = S Theta T/n Pi = Pi + delta*(S-S_old) end V = max(K*EUR-S,0) error = Pi - V end
This ThetaScript model computes the hedging error error based on the analytic solution of the option's delta.
The exact value of the European put E(V) is 13.15 with a standard deviation of error about 0.84.
ThetaScript model for Black-Scholes Hedge Simulation (backwards)
%% The model European_hedged_BS simulates the "delta" hedge of %% a European put option. Note that the Black-Scholes delta is %% optimal for the risk-neutral geometric Brownian motion. model European_hedged_BS import S "Stock" import EUR "Numeraire" import sigma "Volatility" import r "Interest rate" import K "Strike" export Pi "Portfolio Value" export error ""Hedging error"" T = 1 n = 250*T error = Pi! - E(V) loop n % Portfolio value at the previous time-step call OptionDelta export K, sigma, r export S/EUR to S export T-@time to T import delta Pi = Pi! - delta*(S!-S) Theta T/n end Pi = V! V = max(K*EUR-S,0) end
This ThetaScript model computes the hedging error error based on the analytic solution of the option's delta. The error is computed in a backwards fashion, such that Pi always contains the exact amount of money required for a perfect replication. It is important to note that this amount Pi is not deterministic and thus it ahs a probability distribution at time 0. This distribution minus the Option value E(V) is the hedging error error which is presented below.
As in the case of the forward hedging, the exact value of the European put E(V) is 13.15 with a standard deviation of the error of about 0.84.
Variance Minimization by Hedging
A single underlying
Even though the axioms that financial markets do not allow arbitrage and that they are complete have lead to various breakthroughs in the previous decades, there is a technology in ThetaScript which lies outside of this line of derivatives research by only assuming that a real-world model for the underlying hedge instrument exists. The optimal hedging strategies are computed by the command Beta(S, V) which computes a variance minimal hedge based on statistical properties of the underlying S! and the instrument to hedge V!. This allows Monte Carlo pricing to many more realistic market scenarios than the ones based on the Black-Scholes assumptions. In a Black-Scholes market, however, Beta() leads to the same result as the Black-Scholes delta.
%% The model American_hedged simulates the optimal hedge of %% an American put option. Note that this hedge is variance %% optimal for any underlying process S. model American_hedged import S "Stock" import EUR "Numeraire" import sigma "Volatility" import r "Interest rate" import K "Strike" export Pi "Portfolio Value" T = 1 n = 250*T loop n % Portfolio value at the previous time-step Pi = Pi! - Beta(S,Pi)*(S!-S) if E(Pi)>K*EUR-S Pi = K*EUR-S end Theta T/n end Pi = V! V = max(K*EUR-S,0) end
Multiple underlyings
%% The model American_hedged_nd simulates the optimal hedge of %% an American basket put option. Note that this hedge is variance %% optimal for any underlying process S. Model American_hedged_nd import S "Stock prices" import K "Strike" import EUR "Numeraire" export delta "position" export Pi_obs "Portfolio" export P "Option price" P = E(Pi) Loop 250 Pi_obs = Pi! loop s,d:S,delta Pi = Pi! - d! * (s!-s) end delta =Beta(S!,Pi!) Theta 1/250 end Pi = V! loop s,k:S,K V = max(V!, k*EUR-s) end V = 0; delta = 0; end
Multi-Dimensional Stochastics
The exact same scripts can be used with other processes for the underlying stock price. Examples for these scripts are Jump Diffusion or GARCH.
Static vs. Dynamic Hedging
Static Hedging
%% The model Static_hedge Model Static_hedge import S "Stock prices" import EUR "Numeraire" export delta "position" export P_obs "Hedged option price" P_obs = P! delta = Beta(V_t,V) loop d, v : delta, V_t P = P! - d * ( v! - E(v) ) end P = V! % barrier option for hedging fork Loop 50 Theta 1/50 if S>120 V = 0 end end V = max(100*EUR-S,0) end % compute hedge instruments index = 1 loop 5 Theta 1/5 V_t[index] = max(100*EUR-S, 0) V_t[index+1] = max(120*EUR-S, 0) V_t[index+2] = max(S-100*EUR, 0) V_t[index+3] = max(S-120*EUR, 0) index = index + 4 end end
Dynamic Hedging
%% The model Static_hedge Model Static_hedge import S "Stock prices" import EUR "Numeraire" export delta "position" export Pi_obs "Dynamic Hedged option price" export V_obs "unhedged option" V_obs = V! Pi_obs = Pi! delta = Beta(V_t,V) index = 0 fork loop 250 Pi = Pi! - Beta(S,Pi)*(S!-S) Theta 1/250 end Pi = max(100*EUR-S,0) end % barrier option for hedging fork Loop 50 Theta 1/50 if S>120 V = 0 Pi = 0 end End V = max(100*EUR-S,0) end end
Transaction Costs
Constant Intervals
model European_t_cost import S "Stock" import EUR "Numeraire" import K "Strike" import T "Maturity time" export Pi "Option Value" export Pi_f "Hedged option" export Error "Hedging error" export delta "Hedge ratios" export delta_old_f "D" n = 250 kappa = 0.00 Pi_f = E(Pi) delta_old = 0 delta_old_f = 0 S_old = S loop n Pi = Pi! - delta!*(S!-S) + kappa * abs( (delta_old!-delta!)*S) delta = min(0, max(-1,Beta(S,Pi))) delta_old = delta! Theta T/n if (abs(delta-delta_old_f) >= 0.0) & @time<T Pi_f = Pi_f + delta * (S-S_old) - kappa * abs( (delta_old_f-delta)*S) S_old = S delta_old_f = delta end end Pi_f = Pi_f - kappa * abs( (delta_old_f-0)*S) delta = 0 Pi = V! V = max(K*EUR-S,0) Error = V-Pi_f end
Constant Position Change
model European_t_cost_step import S "Stock" import EUR "Numeraire" import K "Strike" import T "Maturity time" export Pi "Option Value" export Pi_f "Hedged option" export Error "Hedging error" export delta "Hedge ratios" export delta_old_f "D" n = 250 kappa = 0.00 Pi_f = E(Pi) delta_old = 0 delta_old_f = 0 S_old = S loop n Pi = Pi! - delta!*(S!-S) + kappa * abs( (delta_old!-delta!)*S) delta = min(0, max(-1,Beta(S,Pi))) delta_old = delta! Theta T/n if (abs(delta-delta_old_f) >= 0.05) & @time<T Pi_f = Pi_f + delta * (S-S_old) - kappa * abs( (delta_old_f-delta)*S) S_old = S delta_old_f = delta end end Pi_f = Pi_f - kappa * abs( (delta_old_f-0)*S) delta = 0 Pi = V! V = max(K*EUR-S,0) Error = V-Pi_f end
