Financial Hacking -- Hedge to Market or to Model?
Author
Philip Maymin
Title
Financial Hacking -- Hedge to Market or to Model?
Description
What happens if we hedge an option to the model volatility as opposed to the market volatility?
Category
Books & Supplements
Keywords
Black-Scholes, options pricing, finance, simulation
URL
http://www.notebookarchive.org/2018-10-53zx5pc/
DOI
https://notebookarchive.org/2018-10-53zx5pc
Date Added
2018-10-11
Date Last Modified
2018-10-11
File Size
3.54 megabytes
Supplements
Rights
CC BY-SA 4.0



Description
Description
This is part of the code used for producing the book Financial Hacking by Philip Z. Maymin. More info at financialhacking.com.
Specifically, this is the code for producing the beautiful and unique heart-shaped figure of Figure 6.5 in Section 6.4.3 of Chapter 6 on page 109 of the textbook.
Note it uses the standard Black-Scholes functions for delta, etc.; those were put together by Michael Kelly for a Wolfram Demonstrations Project (see below).
Specifically, this is the code for producing the beautiful and unique heart-shaped figure of Figure 6.5 in Section 6.4.3 of Chapter 6 on page 109 of the textbook.
Note it uses the standard Black-Scholes functions for delta, etc.; those were put together by Michael Kelly for a Wolfram Demonstrations Project (see below).
Simulation
Simulation
In[]:=
Simulate[payoff_,n_:10000,μ_:0,σ_:.2,dt_:1/252,S0_:100,maturity_:1]:=payoff[FoldList[Times,S0,#]]&/@RandomRealLogNormalDistributionμ-2dt,σSqrt@dt,{n,Ceiling[maturity/dt]}
2
σ
European Option Greeks
European Option Greeks
THESE EUROPEAN OPTION GREEKS FUNCTIONS ARE FROM THE SOURCE CODE FROM"European Option Greeks" from The Wolfram Demonstrations Project http://demonstrations.wolfram.com/EuropeanOptionGreeks/ Contributed by: Michael Kelly (Stuart GSB, Illinois Institute of Technology)
In[]:=
d1[S_,k_,r_,δ_,σ_,T_]=(Log[S/k]+(r-δ+/2)T)σ/2)T)σ[d1[S,k,r,δ,σ,T]]-k[d2[S,k,r,δ,σ,T]];BSPut[S_,k_,r_,δ_,σ_,T_]:=k[-d2[S,k,r,δ,σ,T]]-S[-d1[S,k,r,δ,σ,T]];BSCallDelta[S_,k_,r_,δ_,σ_,T_]=D[BSCall[S,k,r,δ,σ,T],S];BSPutDelta[S_,k_,r_,δ_,σ_,T_]=D[BSPut[S,k,r,δ,σ,T],S];BSCallGamma[S_,k_,r_,δ_,σ_,T_]=D[BSCall[S,k,r,δ,σ,T],{S,2}];BSPutGamma[S_,k_,r_,δ_,σ_,T_]=D[BSPut[S,k,r,δ,σ,T],{S,2}];BSCallTheta[S_,k_,r_,δ_,σ_,T_]=-D[BSCall[S,k,r,δ,σ,T],T];BSPutTheta[S_,k_,r_,δ_,σ_,T_]=-D[BSPut[S,k,r,δ,σ,T],T];BSCallRho[S_,k_,r_,δ_,σ_,T_]=D[BSCall[S,k,r,δ,σ,T],r];BSPutRho[S_,k_,r_,δ_,σ_,T_]=D[BSPut[S,k,r,δ,σ,T],r];BSCallVega[S_,k_,r_,δ_,σ_,T_]=D[BSCall[S,k,r,δ,σ,T],σ];BSPutVega[S_,k_,r_,δ_,σ_,T_]=D[BSPut[S,k,r,δ,σ,T],σ];
2
σ
T
;d2[S_,k_,r_,δ_,σ_,T_]=(Log[S/k]+(r-δ-2
σ
T
;[z_]=1+Erfz2
2;BSCall[S_,k_,r_,δ_,σ_,T_]:=S-δT
-rT
-rT
-δT
In[]:=
Quiet@Plot[BSCallDelta[S,100,0,0,.2,1]-BSCallDelta[S,100,0,0,.1,1],{S,0,200},FillingAxis,PlotRangeAll]
Out[]=
Option Path Simuations
Option Path Simuations
In[]:=
ϵ=1.*^-7
Out[]=
1.×
-7
10
In[]:=
modelVmarket[σhedge_,σsimul_,n_:1000,dt_:1./(252*4),S0_:100,K_:100,r_:0,q_:0,T_:1]:=Module[{initpx=BSCall[S0,K,r,q,σsimul,T],Ts=ReplacePart[Range[T,0,-dt],-1ϵ]},Simulate[{Last@#,StandardDeviation@Differences@Log@#/Sqrt@dt,(BSCall[Last@#,K,r,q,σsimul,ϵ]-initpx-Dot[Most[BSCallDelta[#,K,r,q,σhedge,Ts]],Differences[#]])/initpx}&,n,r-q,σsimul,dt,S0,T]];
In[]:=
GraphicsGrid[Join[{Style[#,FontSize22]&/@{"Hedge","Simul","Histogram of P&L","P&L vs. Last Price","P&L vs. Realized Vol"}},Flatten[Table[With[{vals=modelVmarket[σhedge,σsimul,10000,1./252]},Join[Style[#,FontSize22]&/@{σhedge,σsimul},{Histogram[vals〚All,3〛,Automatic,"Probability",PlotRangeAll],ListPlot[vals〚All,{1,3}〛,PlotRangeAll(*,AxesOrigin{75,0}*)],ListPlot[vals〚All,{2,3}〛,PlotRangeAll]}]],{σhedge,{.1,.2}},{σsimul,{.1,.2}}],1]],ImageSize700]
Out[]=
In[]:=
GraphicsGrid[Join[{Style[#,FontSize22]&/@{"Hedge","Simul","Histogram of P&L","P&L vs. Last Price","P&L vs. Realized Vol"}},Flatten[Table[With[{vals=modelVmarket[σhedge,σsimul,10000,1./252]},Join[Style[#,FontSize22]&/@{σhedge,σsimul},{Histogram[vals〚All,3〛,Automatic,"Probability",PlotRangeAll],ListPlot[vals〚All,{1,3}〛,PlotRangeAll(*,AxesOrigin{75,0}*)],ListPlot[vals〚All,{2,3}〛,PlotRangeAll]}]],{σhedge,{.2,.3}},{σsimul,{.2,.3}}],1]],ImageSize700]
Out[]=


Cite this as: Philip Maymin, "Financial Hacking -- Hedge to Market or to Model?" from the Notebook Archive (2019), https://notebookarchive.org/2018-10-53zx5pc

Download

