Approximating Variance Swap Exposure with a Static Option Portfolio
Summary
The document explores how to represent variance swap exposure using options. It starts from the risk neutral replication identity linking expected squared returns to a log contract and a continuum of calls and puts weighted by inverse strike squared. The example R program instead constructs a finite strike grid and solves for option weights that match the log payoff at selected terminal prices, then compares the portfolio payoff with the target across a wider range of prices.
The author asks how to adapt this discrete setup to the integral formula and why a proposed change to the payoff calculation produces crossing lines. The code and plotted comparison illustrate the setup, but the document provides no accepted solution or explanation of the matrix construction. Its example is therefore a starting point rather than a validated hedge; finite strike spacing, strike coverage, and implementation details matter when approximating the continuum replication.
Key ideas
- Variance swap replication connects realized squared returns with a log contract under risk neutral expectations.
- A continuum of calls and puts weighted by inverse strike squared represents the log contract payoff.
- The example solves a linear system for option weights on a finite strike grid.
- A finite grid only approximates the continuous replication and may not match payoffs between calibration points.
- The document poses a coding question but does not provide a verified fix or full explanation of the matrix.
Tags
Full text
# Implementing a Variance Swap Hedging in R
# Implementing a Variance Swap Hedging in R
I am trying to compute a hedge for a variance swap, in a simulation. Fo that I am using the following equation:\begin{align*} E^Q\bigg(\sum_{i=1}^n \bigg(\frac{S_{t_{i}}-S_{t_{i-1}}}{S_{t_{i-1}}}\bigg)^2\bigg) &\approx -2E^Q\bigg(\ln\frac{S_T}{S_0} \bigg)\\ &=2E^Q\bigg[\int_{S_0}^{\infty} \frac{(S_T-K)^+}{K^2} dK + \int_0^{S_0} \frac{(K-S_T)^+}{K^2} dK\bigg], \end{align*}
I have a piece of code that instead of using the formula above uses:
$$ \sum_{j=-(m-1)}^{-1}(K_j-K_l)^+-\sum_{j=-(m-1)}^{-1}(K_j-K_0)^+=2\ln(S_0/K_l) $$
That code is:
```
S0<-100
dK<-0.05*S0
nK<-3
K<-S0+dK*c(((-(nK-1)):(nK-1))) # strikes used for static portfolio
# puts for K<=S0, calls for K >= S0
x<-S0+dK*c((-nK):(-1),1:nK) # S(T)-values at which the option portfolio
# matches 2ln(S(0)/S(T)) exacty
RHS<-2*log(S0/x)
A<-matrix(0,nrow=2*nK,ncol=(2*nK))
for (i in 1:nK){
A[i,1:i]<-dK*i:1; A[2*nK-(i-1),(2*nK-(i-1)):(2*nK)]<-rev(A[i,1:i])
}
print(A)
print(rev(A))
w<-solve(t(A),RHS)
y<-50:150
capT<-1/12
n=20
dt=capT/n; dt05<-sqrt(dt)
time<-seq(0,capT,by=dt)
S<-rep(S0,(n+1))
sigma<-0.15
price<-0
largeLHS<-largeRHS<-2*log(S0/y)
for (i in 1:length(y)){
largeLHS[i]<-sum(w[1:nK]*pmax(K[1:nK]-y[i],0))+sum(w[(nK+1):(2*nK)]*pmax(y[i]-K[nK:(2*nK-1)],0))
}
plot(y,largeRHS,type='l',xlab='S(T)',ylab='Payoff @ T', main="Variance swap hedging: \n Matching the log-contract")
text(55,1.25,"2*ln(S(0)/S(T))",adj=0)
text(140,-0.75,"Option portfolio",adj=1,col="blue")
text(145,1.25,paste("dK =",dK),adj=1)
text(145,1.05,paste("#calls = #puts =",nK),adj=1)
points(x,RHS,col='blue')
points(y,largeLHS,col='blue',type='l')
```
Since I am a beginner at programming, I am trying to adapt the code to the formula above.
I tried to alter the second for loop in the following way:
```
for (i in 1:length(y)){
largeLHS[i]<-sum((2/(K[1:nK])^2)*pmax(K[1:nK]-y[i],0))+sum((2/(K[nK:(2*nK-1)])^2)*pmax(y[i]-K[nK:(2*nK-1)],0))
}
```
But the plot is a mess, the two lines are not meeting but crossing each other.
Question:
Can someone help me solve this problem? And give me some insight into the matrix part of the code I provided?
Thanks in advance!Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.