有没有人做simulation的啊
楼主 · 1 楼
我想找一个normally distribution和uniformly
distribution的c++或java的程序,我网上找到的好像都不对,谁有能给我发个吗?谢谢,我的信箱是birch2002@gmail.com
2 楼
| 引用 (birch2002 @ 2005年07月09日 04时52分) |
| 我想找一个normally distribution和uniformly distribution的c++或java的程序,我网上找到的好像都不对,谁有能给我发个吗?谢谢,我的信箱是birch2002@gmail.com |
这个是normal distribution的程序
double N(double x)
{
double a = 0.4361836;
double b = −0.120
1676;
double c = 0.9372980;
double d = 1.0/(1.0 + (0.33267 * x));
if (x >= 0.0)
{
return 1.0 − n(x)* (a*d + (b*d*d) + (c*d*d*d));
}
else
{
return 1.0 − N(−x);
}
}
其中a,b,c根据Haug的结果 The Complete Guide to Option Pricing Formulas. McGraw-Hill, New York
Uniform distribution
template <class R>
class Uniform : public ContinuousDistribution<R,R>
{ private:
R a;
R b;
public:
Uniform();
Uniform(const R& left, const R& right);
R epe(const Uniform<R>& u);
R var(const Uniform<R>& u);
R pdf(const R& x) const;
R cdf(const R& x) const;
R pro(const R& upper, const R& lower) const;
};
这个template有几个参数如下
epe就是return(a + b) * 0.5;
var就是double t = a - b; return((t*t)/12.0);
pdf就是return (1.0/(b − a));
cdf就是return (x − a) / (b − a);
pro就是return (xUpp − xLow) / (b − a);
自己加进去吧 我懒得写了。