Attribute VB_Name = "Module2" Public Function mccall(s, k, r, sg, t, m) temp = 0 For i = 1 To m randn = Application.WorksheetFunction.NormInv(Rnd(), 0, 1) st = s * Exp((r - sg ^ 2 / 2) * t + sg * Sqr(t) * randn) temp = temp + max(st - k, 0) Next mccall = Exp(-r * t) * temp / m End Function Public Function max(x, y) If x >= y Then max = x Else max = y End If End Function Public Function mcasiancall(s, k, r, sg, t, n, m) Dim st() ReDim st(n) st(0) = s dt = t / n temp2 = 0 For i = 1 To m temp1 = 0 For j = 1 To n randn = Application.WorksheetFunction.NormInv(Rnd(), 0, 1) st(j) = st(j - 1) * Exp((r - sg ^ 2 / 2) * dt + sg * Sqr(dt) * randn) temp1 = temp1 + st(j) Next temp2 = temp2 + max(temp1 / n - k, 0) Next mcasiancall = Exp(-r * t) * temp2 / m End Function Public Function jrcall(s, k, r, sg, t, n) dt = t / n u = Exp((r - sg ^ 2 / 2) * dt + sg * Sqr(dt)) d = Exp((r - sg ^ 2 / 2) * dt - sg * Sqr(dt)) p = 0.5 For j = 0 To n cum = cum + max(s * u ^ (n - j) * d ^ j - k, 0) * p ^ (n - j) * (1 - p) ^ j * Application.WorksheetFunction.Fact(n) / Application.WorksheetFunction.Fact(j) _ / Application.WorksheetFunction.Fact(n - j) Next jrcall = cum * Exp(-r * t) End Function Public Function crraput(s, k, r, sg, t, n) Dim ft() ReDim ft(n) dt = t / n u = Exp(sg * Sqr(dt)) d = 1 / u df = Exp(-r * dt) p = (Exp(r * dt) - d) / (u - d) For j = 0 To n ft(j) = max(k - s * u ^ (n - j) * d ^ j, 0) Next For i = n - 1 To 0 Step -1 For j = 0 To i ft(j) = max(k - s * u ^ (i - j) * d ^ j, (ft(j) * p + ft(j + 1) * (1 - p)) * df) Next Next crraput = ft(0) End Function