Attribute VB_Name = "Module2" Public Function hedging(s, k, u, r, sg, t, n) Dim st() ReDim st(n) st(0) = s dt = t / n d11 = (Log(st(0) / k) + (r + sg ^ 2) * t) / Sqr(t) / sg nd11 = Application.WorksheetFunction.NormSDist(d11) cost = nd11 * st(0) For i = 1 To n - 1 randn = Application.WorksheetFunction.NormInv(Rnd(), 0, 1) st(i) = st(i - 1) * Exp((u - sg ^ 2 / 2) * dt + sg * Sqr(dt) * randn) d12 = (Log(st(i) / k) + (r + sg ^ 2) * (t - i * dt)) / Sqr(t - i * dt) / sg nd12 = Application.WorksheetFunction.NormSDist(d12) cost = cost * Exp(r * dt) + (nd12 - nd11) * st(i) nd11 = nd12 Next st(n) = st(n - 1) * Exp((u - sg ^ 2 / 2) * dt + sg * Sqr(dt) * randn) If st(n) >= k Then nd12 = 1 cost = cost * Exp(r * dt) + (nd12 - nd11) * st(n) - k Else nd12 = 0 cost = cost * Exp(r * dt) + (nd12 - nd11) * st(n) End If hedging = cost * Exp(-r * t) End Function Public Function participation(a0, rg, r, sg, t) d1 = (Log(a0 / (a0 + Exp(rg * t) - 1)) + (r + sg ^ 2 / 2) * t) / (sg * Sqr(t)) d2 = d1 - sg * Sqr(t) v = Exp((rg - r) * t) + a0 * Application.WorksheetFunction.NormSDist(d1) - Exp(-r * t) * (a0 + Exp(rg * t) - 1) * Application.WorksheetFunction.NormSDist(d2) If v < 1 Then a0 = a0 + 1 d1 = (Log(a0 / (a0 + Exp(rg * t) - 1)) + (r + sg ^ 2 / 2) * t) / (sg * Sqr(t)) d2 = d1 - sg * Sqr(t) v = Exp((rg - r) * t) + a0 * Application.WorksheetFunction.NormSDist(d1) - Exp(-r * t) * (a0 + Exp(rg * t) - 1) * Application.WorksheetFunction.NormSDist(d2) End If a = a0 Do While Abs(v - 1) > 0.001 i = i + 1 If v > 1 Then a = a - a0 / 2 ^ i Else a = a + a0 / 2 ^ i End If d1 = (Log(a / (a + Exp(rg * t) - 1)) + (r + sg ^ 2 / 2) * t) / (sg * Sqr(t)) d2 = d1 - sg * Sqr(t) v = Exp((rg - r) * t) + a * Application.WorksheetFunction.NormSDist(d1) - Exp(-r * t) * (a + Exp(rg * t) - 1) * Application.WorksheetFunction.NormSDist(d2) Loop participation = a End Function