the error show after i entered the value

System.IndexOutOfRangeException: Index was outside the bounds of the array.

at Service.asianprice(Double S, Double K, Double T, Double r, Double sigma, Int32 NSimulations, Int32 NStep) in c:\Users\nickhun07\Documents\Visual Studio 2010\WebSites\MonteCarlo\App_Code\Service.cs:line 87

in line 87 is

callpayoffvec[i, 1] = (Math.Max(AverageSVec - K, 0));

I dont know that something wrong about my Array. I need your guy help me to solve

Thank you

public void asianprice(double S,double K,double T,double r,double sigma,int NSimulations,int NStep) { double dt, vsqrdt, drift; double str_S = S; //spot price double str_K = K; //strike double str_T = T; //maturity double str_r = r; //interest rate double str_sigma = sigma; //volatility double str_NSim = NSimulations; //no of monte carlo simulations double str_NSt = NStep; //no of time steps int i = 0, j; dt = T / (NStep - 1); vsqrdt = sigma * (Math.Pow(0.5, dt)); drift = (r - (Math.Pow(2, sigma)) / 2) * dt; double[,] callpayoffvec = new double[i, 1]; double[,] putpayoffvec = new double[i, 1]; int simtost = NSimulations * NStep; Random nsmlnsi = new Random(); int randvec = nsmlnsi.Next(simtost); // find the result of sizeof of (S) and float /* for (i = 0; i < sizeof(int); i++) { Smat[i, 0] = S; // find the number of each S */ for (i = 0; i <= NSimulations-1; i++) { double st = S; double curtime = 0; double tmpsum = 0; for (j = 0; j <= NStep-1; j++) { curtime = curtime + dt; st = st * Math.Exp(drift + vsqrdt + randvec); tmpsum = tmpsum + st; } double AverageSVec = tmpsum / NStep; callpayoffvec[i, 1] = (Math.Max(AverageSVec - K, 0)); putpayoffvec[i, 1] = (Math.Max(K - AverageSVec, 0)); } double MC_callprice = Math.Exp(-r * T) * Mean(callpayoffvec); double MC_putprice = Math.Exp(-r * T) * Mean(putpayoffvec); } double Mean(double[,] dblArray) { double dblResult = 0; foreach (double dblValue in dblArray) dblResult += dblValue; return dblResult / dblArray.Length; }