| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1370 人关注过本帖
标题:C# 蒙特卡洛模拟
只看楼主 加入收藏
EEE7
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2021-2-14
收藏
 问题点数:0 回复次数:0 
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编辑过]

搜索更多相关主题的帖子: 模拟 double matrix Math int 
2021-02-14 13:43
快速回复:C# 蒙特卡洛模拟
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012006 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved