diff options
| author | Bertrand <bertrand.horel@gmail.com> | 2016-02-21 16:35:30 +0000 |
|---|---|---|
| committer | Bertrand <bertrand.horel@gmail.com> | 2016-02-21 16:35:30 +0000 |
| commit | 906c2dee383a7eb72632bfbdf61916a576a5460d (patch) | |
| tree | e86bbaadc241b71b302591b64762f671d1e30940 /src/stratified_sampling.hpp | |
| parent | 5ed1989db081c60c7be820a5ce58a170fd5f1f9c (diff) | |
| download | projet_C++-906c2dee383a7eb72632bfbdf61916a576a5460d.tar.gz | |
création de la struct f_mu
Diffstat (limited to 'src/stratified_sampling.hpp')
| -rw-r--r-- | src/stratified_sampling.hpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/stratified_sampling.hpp b/src/stratified_sampling.hpp index cebee8d..7573ef2 100644 --- a/src/stratified_sampling.hpp +++ b/src/stratified_sampling.hpp @@ -5,6 +5,7 @@ #include "rtnorm.hpp" #include "var_alea.hpp" #include <gsl/gsl_cdf.h> +#include "option.hpp" using namespace std; @@ -45,14 +46,14 @@ struct multi_gaussian_truncated : public var_alea<std::vector<double> > double v = V(); double Z = gsl_cdf_gaussian_Pinv(v,1); std::vector<double> Y(d); - double scal = 0; for(int i=0; i<d; i++){ Y[i] = G(); } - std::vector<double> X(d); + double scal = 0; for(int j=0; j<d; j++){ scal += Y[j]*u[j]; } + std::vector<double> X(d); for(int i=0; i<d; i++){ X[i] = u[i]*Z + Y[i] - u[i]*scal; } @@ -78,7 +79,7 @@ struct stratified_sampling { void print_sigma() const; pair<double,double> estimator() const; private: - void update(int N); + void update(int N); vector<double> p; vector<L> X; vector<int> M; @@ -187,3 +188,29 @@ pair<double,double> stratified_sampling<L>::estimator() const { } return {est_mean, est_std}; } + +struct f_mu : public std::unary_function<std::vector<double>, double> +{ + f_mu(std::vector<double> mu, asian_option A) : mu(mu), A(A){ + double norm_mu = 0; + for(int i=0; i<16; i++) { + norm_mu += mu[i]*mu[i]; + } + }; + + double operator()(std::vector<double> X) { + std::vector<double> Y(X.size()); + double scal = 0; + for (unsigned int i=0; i<X.size(); i++){ + Y[i] = X[i] + mu[i]; + scal+=X[i]*mu[i]; + } + return A(Y)*exp(-scal-0.5*norm_mu); + }; + + private : + std::vector<double> mu; + asian_option A; + double norm_mu; + }; + |
