C# 蒙特卡洛模拟
请问我的for循环是哪里出现问题了呀,出来的结果sum_CT一直是矩阵某一行最右列数值的100倍,但sum_CT应该是矩阵最右列所有数之和。double sum_CT, sum_CT2, call_value, SD, SE;
double[,] matrix = new double[(int) m, (int) N+1];
double[] arr = new double[(int)m];
sum_CT = 0;
sum_CT2 = 0;
for (i = 0; i <= m - 1; i++)
{
matrix[i, 0] = S0;
for (j = 0; j <= N-1; j++)
{
matrix[i, j+1] = matrix[i, j] * Math.Exp(nudt + sigsdt * epsilon); //epsilon is a normally distributed randomvariable
}
matrix[i, (int)N] = Math.Max(0, matrix[i, (int)N] - K);
sum_CT = sum_CT + matrix[i, (int)N];
sum_CT2 += matrix[x, (int)N] * matrix[x, (int)N];
}
call_value = (sum_CT * Math.Exp(-miu * T))/m;
SD = Math.Sqrt((sum_CT2 - sum_CT * sum_CT / m) * Math.Exp(-2 * miu * T) / (m - 1));
SE = SD / Math.Sqrt(m);
var result = Tuple.Create<double, double>(sum_CT, matrix[2, (int)N]);
return result;
}
结果:(1868.33678, 18.6833678)
[此贴子已经被作者于2021-2-14 13:52编辑过]