I have to make an excel file for financial options in excel, where it can tell me if the optimal policy for the option is to keep it or exercise it. I have developed how the sockprice and optionprice develops in module1 and module2, but i can't get the formula in module3 to work - it has to tell me "Keep" or "Exercise" due to the equation in "Policygrid(i, time)". I think the problem is that module3 gets data from both module1 and module2 or just that i can't get the "application.if" formula to work.
S = stockprice
X = Exercise price
T = Time
rf = risk free rate
Sigma = volatility
n = number of periods
If you would like to see how module 1 and 2 works try to use the following data:
Mark 6 cells and 6 rows. Use S=100, X=100, T=5, rf=0.05, Sigma=0.2, n=5 in the formula (stockgridVarPeriod and optiongridvarPeriodAmrPut and press ctrl,shift,enter.
I have added an excelfile with the relevant data, where i in the sheet "traditional" shows the exercise policy i would like to make in VBA. Hope one of you can figure it out, and please c/p the modules from below if you would like to help me out.
Module1:
Option Base 1
Function stockgridVarPeriod(S, X, T, rf, sigma, n)
Dim delta_t, u, d
delta_t = T / n
u = Exp(sigma * Sqr(delta_t))
d = Exp(-sigma * Sqr(delta_t))
Dim stockgrid()
ReDim stockgrid(n + 1, n + 1)
stockgrid(1, 1) = S
Dim time, i
For time = 2 To n + 1
i = time
stockgrid(i, time) = d * stockgrid(i - 1, time - 1)
Next time
For time = 2 To n + 1
For i = 1 To time - 1
stockgrid(i, time) = u * stockgrid(i, time - 1)
Next i
Next time
stockgridVarPeriod = stockgrid
End Function
Module2:
Option Base 1
Function optiongridVarPeriodAmrPut(S, X, T, rf, sigma, n)
Dim delta_t, u, d, R, qu, qd, time, i
Dim stockgrid()
ReDim stockgrid(n + 1, n + 1)
stockgrid = stockgridVarPeriod(S, X, T, rf, sigma, n)
delta_t = T / n
u = Exp(sigma * Sqr(delta_t))
d = Exp(-sigma * Sqr(delta_t))
R = Exp(rf * delta_t)
qu = (R - d) / (R * (u - d))
qd = (u - R) / (R * (u - d))
Dim optiongrid()
ReDim optiongrid(n + 1, n + 1)
For i = 1 To n + 1
time = n + 1
optiongrid(i, time) = Application.Max(X - stockgrid(i, time), 0)
Next i
For time = n To 1 Step -1
For i = 1 To time
optiongrid(i, time) = Application.Max(X - stockgrid(i, time), qu * optiongrid(i, time + 1) + qd * optiongrid(i + 1, time + 1))
Next i
Next time
optiongridVarPeriodAmrPut = optiongrid
End Function
Module3:
Option Base 1
Function PolicyAmrPut(S, X, T, rf, sigma, n)
Dim delta_t, u, d, R, qu, qd, time, i
delta_t = T / n
u = Exp(sigma * Sqr(delta_t))
d = Exp(-sigma * Sqr(delta_t))
R = Exp(rf * delta_t)
qu = (R - d) / (R * (u - d))
qd = (u - R) / (R * (u - d))
Dim stockgrid()
ReDim stockgrid(n + 1, n + 1)
stockgrid = stockgridVarPeriod(S, X, T, rf, sigma, n)
Dim optiongrid()
ReDim optiongrid(n + 1, n + 1)
optiongrid = optiongridVarPeriodAmrPut(S, X, T, rf, sigma, n)
Dim Policygrid()
ReDim Policygrid(n + 1, n + 1)
For time = 1 To n + 1 Step 1
For i = 1 To time
Policygrid(i, time) = Application.if(X - stockgrid(i, time) > qu * optiongrid(i, time + 1) + qd * optiongrid(i + 1, time + 1), "Exercise", "Keep")
Next i
Next time
PolicyAmrPut = Policygrid
End Function
Bookmarks