First, get Math.NET Library (Open source).
F# code:
\\ begin
#light
open MathNet.Numerics.FSharp
open MathNet.Numerics.Distributions
let d12 (S0,r,y,sigma,K,T,d1_d2) = (log (S0/K)+(r-y+(if d1_d2 = 1.0 then 1.0 else -1.0))*(sigma*sigma / 2.0)*(T))/(sigma * (sqrt(T)))
let normal = new Normal(0.0, 1.0)
let bsPrice (S0, r, y, sigma, K, T) = exp (-y*T) * S0 * normal.CumulativeDistribution(d12 (S0,r,y,sigma,K,T,1.0))-exp (-r*T) *K * normal.CumulativeDistribution(d12 (S0,r,y,sigma,K,T,2.0))
printfn "Price = %F" (bsPrice (1.0, 0.0, 0.0, 0.2, 1.0, 1.0))
open System
Console.ReadKey(true)
\\ end
No comments:
Post a Comment