You are on page 1of 3

Option Explicit

Sub AsianOpt()
'Subroutine to compute Asian and European option prices by Monte Carlo simulatio
n
Dim acp, app, a, b, S, K, r, vol, T, yld, nprices, nsims, Delt, Sumcalls, Sumput
s, Avgprice, AsianSim, Sumprices, Oldprice, Newprice, noise, SumEcalls, SumEputs
, ec, ep, SumAScall, SumASput, avsc, avsp
Range("Asiancall").Value = " "
Range("Asianput").Value = " "
Range("SimEcall").Value = " "
Range("SimEput").Value = " "
Range("AsianASc").Value = " "
Range("AsianAsp").Value = " "
S = Range("AS").Value
K = Range("AK").Value
r = Range("Ar").Value
vol = Range("Av").Value
T = Range("AT").Value
yld = Range("Ay").Value
nprices = Range("Anp").Value
nsims = Range("Ans").Value
Delt = T / nprices
Sumcalls = 0#
Sumputs = 0#
SumEcalls = 0#
SumEputs = 0#
Application.StatusBar = "Iterating though simulation. Please wait." & a
For a = 1 To nsims
Sumprices = 0#
Oldprice = S
For b = 1 To nprices
noise = Rnd + Rnd + Rnd + Rnd + Rnd + Rnd + Rnd + Rnd + Rnd + Rnd + Rnd
+ Rnd - 6#
Newprice = Oldprice * (1 + (r - yld) * Delt + vol * noise * Sqr(Delt))
Sumprices = Sumprices + Newprice
Oldprice = Newprice
Next b
Avgprice = Sumprices / nprices
Sumcalls = Sumcalls + Application.Max(0, Avgprice - K)
SumAScall = SumAScall + Application.Max(0, Oldprice - Avgprice)
SumEcalls = SumEcalls + Application.Max(0, Oldprice - K)
Sumputs = Sumputs + Application.Max(0, K - Avgprice)
SumASput = SumASput + Application.Max(0, Avgprice - Oldprice)
SumEputs = SumEputs + Application.Max(0, K - Oldprice)
Next a
'definiendo valores de primas de opcion
acp = (Sumcalls / nsims) * Exp(-r * T)
avsc = (SumAScall / nsims) * Exp(-r * T)
app = (Sumputs / nsims) * Exp(-r * T)
avsp = (SumASput / nsims) * Exp(-r * T)
ec = (SumEcalls / nsims) * Exp(-r * T)
ep = (SumEputs / nsims) * Exp(-r * T)
Range("Asiancall").Value = acp
Range("Asianput").Value = app
Range("SimEcall").Value = ec
Range("SimEput").Value = ep
Range("AsianASc").Value = avsc
Range("AsianASp").Value = avsp
Application.StatusBar = False
End Sub
Function ExchOpt(S1, vol1, yld1, S2, vol2, yld2, T, rho, exi)
'Function to compute exchange option prices
'Using William Margrabe, "The Value of an Option to Exchange One Asset for Anoth
er"
'Journal of Finance 33 (March, 1978), pp. 177-186
Dim d1, d2, cvol, d1c, d2c, d1p, d2p
cvol = Sqr(vol1 ^ 2 + vol2 ^ 2 - 2 * rho * vol1 * vol2)
d1c = (Log((S1 * Exp(-yld1 * T)) / (S2 * Exp(-yld2 * T))) + (cvol ^ 2 / 2) * T)
/ (cvol * Sqr(T))
d2c = d1c - cvol * Sqr(T)
d1p = (Log((S2 * Exp(-yld2 * T)) / (S1 * Exp(-yld1 * T))) + (cvol ^ 2 / 2) * T)
/ (cvol * Sqr(T))
d2p = d1p - cvol * Sqr(T)
Select Case exi
Case "call"
ExchOpt = S1 * Exp(-yld1 * T) * Application.NormSDist(d1c) - S2 * Exp(-y
ld2 * T) * Application.NormSDist(d2c)
Case "put"
ExchOpt = S2 * Exp(-yld2 * T) * Application.NormSDist(d1p) - S1 * Exp(-y
ld1 * T) * Application.NormSDist(d2p)
End Select
End Function
Function MMOpt(S1, sig1, divy1, S2, sig2, divy2, K, rho, T, r, mmi)
Dim sigma, rho1, rho2, x1, x2, y1, y2, omax, omaxc, comax, pomax, omin, ominc, c
omin, pomin, sc1, sc2, sc3
'Function to calculate options on maximum and minimum of two risky assets
'Using formulas from Mark Rubinstein, "Two in One," Risk, November, 1991
sigma = Sqr(sig1 ^ 2 + sig2 ^ 2 - 2 * rho * sig1 * sig2)
rho1 = (rho * sig2 - sig1) / sigma
rho2 = (rho * sig1 - sig2) / sigma
x1 = (Log(S1 * Exp(-divy1 * T) / (K * Exp(-r * T))) / (sig1 * Sqr(T))) + sig1 *
Sqr(T) / 2
x2 = (Log(S2 * Exp(-divy2 * T) / (K * Exp(-r * T))) / (sig2 * Sqr(T))) + sig2 *
Sqr(T) / 2
y1 = (Log(S1 * Exp(-divy1 * T) / (S2 * Exp(-divy2 * T))) / (sigma * Sqr(T))) + s
igma * Sqr(T) / 2
y2 = (Log(S2 * Exp(-divy2 * T) / (S1 * Exp(-divy1 * T))) / (sigma * Sqr(T))) + s
igma * Sqr(T) / 2
sc1 = S1 * Exp(-divy1 * T) * Application.NormSDist(x1) - K * Exp(-r * T) * Appli
cation.NormSDist(x1 - sig1 * Sqr(T))
sc2 = S2 * Exp(-divy2 * T) * Application.NormSDist(x2) - K * Exp(-r * T) * Appli
cation.NormSDist(x2 - sig2 * Sqr(T))
omax = S1 * Exp(-divy1 * T) * Application.NormSDist(y1) + S2 * Exp(-divy2 * T) *
Application.NormSDist(y2)
omaxc = S1 * Exp(-divy1 * T) * (Application.NormSDist(y1) - bivar(-x1, y1, rho1)
) + S2 * Exp(-divy2 * T) * (Application.NormSDist(y2) - bivar(-x2, y2, rho2)) +
K * Exp(-r * T) * bivar(-x1 + sig1 * Sqr(T), -x2 + sig2 * Sqr(T), rho)
comax = omaxc - K * Exp(-r * T)
pomax = comax - omax + K * Exp(-r * T)
omin = S1 * Exp(-divy1 * T) * Application.NormSDist(-y1) + S2 * Exp(-divy2 * T)
* Application.NormSDist(-y2)
ominc = S1 * Exp(-divy1 * T) * (Application.NormSDist(-y1) - bivar(x1, -y1, rho1
)) + S2 * Exp(-divy2 * T) * (Application.NormSDist(-y2) - bivar(x2, -y2, rho2))
+ K * Exp(-r * T) * bivar(-x1 + sig1 * Sqr(T), -x2 + sig2 * Sqr(T), rho)
comin = sc1 + sc2 - comax
pomin = comin - omin + K * Exp(-r * T)
Select Case mmi
Case "OMAXRC": 'Option on the maximum of two risky assets and cash
MMOpt = omaxc
Case "COMAX": 'Call on the maximum of two risky assets
MMOpt = comax
Case "POMAX": 'Put on the maximum of two risky assets
MMOpt = pomax
Case "OMINRC": 'Option on the minimum of two risky assets and cash
MMOpt = ominc
Case "COMIN": 'Call on the minimum of two risky assets
MMOpt = comin
Case "POMIN": 'Put on the minimum of two risky assets
MMOpt = pomin
End Select
End Function