From 6b07d76c512c5450ce34fd6f2f8483c395a24ea2 Mon Sep 17 00:00:00 2001 From: Bertrand Date: Tue, 16 Feb 2016 22:01:28 +0000 Subject: meilleur encapsulage pour asian quasi_option --- option.cpp | 80 +++++++++++++++++++++++--------------------------------------- 1 file changed, 30 insertions(+), 50 deletions(-) (limited to 'option.cpp') diff --git a/option.cpp b/option.cpp index fb8b9cc..8229730 100644 --- a/option.cpp +++ b/option.cpp @@ -2,6 +2,10 @@ #include #include "rqmc.hpp" +double frac_part(double x){ + return x - floor(x); +} + double pos (double x){ return x>0?x:0; } @@ -32,71 +36,47 @@ struct asian_option : public std::unary_function, double> -struct asian_option_qmc : public var_alea + +template +struct quasi_option : public generator { - asian_option_qmc(double r, double T, double S0, double V, int d, double K) - : r(r), T(T), S0(S0), V(V), d(d), K(K), G(d), U(0,1), seed(d) { - for(int i=0; i S(d); - std::vector sob(d); - sob = G(); - S[0]= S0*exp((r-V*V/2)*(T/d)+V*sqrt(T/d)*gsl_cdf_gaussian_Pinv(frac_part(seed[0]+sob[0]), 1)); - for(int i=1;i X(d); + double sum =0; + X = s(); + for (int i=0; i seed; -}; - + }; int main(){ init_alea(1); asian_option A(0.05, 1.0, 50.0, 0.1, 16, 45); - //~ int M= 1000000; - int N= 10000; - //~ int I= 100; - - //~ std::vector meanvar = monte_carlo(M, A); - //~ std::cout<<"espérance "< temp; - //~ double m = 0; - //~ double s = 0; - //~ for(int i=0;i test(d,1); - std::cout< r = monte_carlo(N, A, G); - for(int i=0; i<3; i++){ - std::cout< (N, d, A))[i]<