Saturday 29 November 2008

Computing confidence intervals

The function simulPayoffs of our first program generates a list of n simulated payoffs for a given option. Then, to estimate the price of the option, we compute its mean using the following function:

//Compute the mean of a list
let mean list = Seq.fold (+) 0.0 list / float (Seq.length list)

In order to estimate the statistical error of this result, we define a function which computes the standard deviation of a list:

//Compute the estimated standard deviation of a list
let standardDeviation list =
let m = mean list
Seq.sumByFloat(fun x -> (x - m)**2.0) list
/ float (Seq.length list - 1)

And using the central limit theorem we can also define function which computes a confidence interval for our price estimation:

//Compute a 1-p confidence interval for p in (0,1)
let confidenceInterval list p =
let m = mean list
let sigma = standardDeviation list
let quantile = 1.0-(p/2.0) |> NormalCDFInverse
let n = Seq.length list
let size = quantile*sigma/Math.Sqrt(float n)
(m - size, m + size)

Let's test these functions on a simple European option:

let T = 0.3 //maturity
let strike = 102.5 //strike
let S0 = 100.0 //current underlying price
let r = 0.06 //risk free rate
let sigma = 0.19 //volatility
let n = 100000 //number of simulations

let call = SimpleOption(Call, strike, T)

let simul = simulPayoffs call S0 r T sigma n //simulated payoffs

let price = mean simul // estimated price
let sd = standardDeviation simul // standard deviation
let ic95 = confidenceInterval simul 0.05 // 95% CI
let ic99 = confidenceInterval simul 0.01 // 99% CI


Console.WriteLine ("price: " + price.ToString())
Console.WriteLine ("standard deviation: " + sd.ToString())
Console.Write "95% confidence interval: "
print_any ic95
Console.Write "\n99% confidence interval: "
print_any ic99


Output:
price: 3.86677460654713
standard deviation: 39.7853613645219
95% confidence interval: (3.620132697, 4.113416516)
99% confidence interval: (3.542652267, 4.190896946)

No comments: