diff options
| author | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2016-04-12 12:23:13 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2016-04-12 12:23:13 -0400 |
| commit | 4e5104a0186bd705b5ed1f57f73375ace60587f6 (patch) | |
| tree | 7e0f0315631d243ea273080cbca0c4d681bb1d38 /src/stratified_sampling.hpp | |
| parent | bcafe5e41698c44b6aa77b8ef150f4224613c38f (diff) | |
| download | projet_C++-4e5104a0186bd705b5ed1f57f73375ace60587f6.tar.gz | |
Rename f_mu as exponential_tilt
and template it instead of having it depend on asian_option
Diffstat (limited to 'src/stratified_sampling.hpp')
| -rw-r--r-- | src/stratified_sampling.hpp | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/stratified_sampling.hpp b/src/stratified_sampling.hpp index 9099e38..9175f75 100644 --- a/src/stratified_sampling.hpp +++ b/src/stratified_sampling.hpp @@ -3,7 +3,6 @@ #include <iostream> #include "var_alea.hpp" #include <gsl/gsl_cdf.h> -#include "option.hpp" using namespace std; @@ -14,14 +13,14 @@ struct gaussian_truncated : var_alea<double> { gaussian_truncated(double a, double b, double mu = 0, double sigma = 1) :a(a), b(b), V(gsl_cdf_ugaussian_P(a), gsl_cdf_ugaussian_P(b)), mu(mu), sigma(sigma) {}; - + double operator()() { double v = V(); return mu + gsl_cdf_gaussian_Pinv(v,sigma); } - + private: - double a, b; + double a, b; uniform V; double mu; double sigma; @@ -31,7 +30,7 @@ struct multi_gaussian_truncated : public var_alea<std::vector<double> > { multi_gaussian_truncated(double a, double b, const std::vector<double> u) :a(a), b(b), V(gsl_cdf_ugaussian_P(a), gsl_cdf_ugaussian_P(b)), G(0,1), u(u), d(u.size()) {}; - + std::vector<double> operator()() { double v = V(); double Z = gsl_cdf_gaussian_Pinv(v,1); @@ -49,9 +48,9 @@ struct multi_gaussian_truncated : public var_alea<std::vector<double> > } return X; } - + private: - double a, b; + double a, b; uniform V; gaussian G; std::vector<double> u; @@ -180,15 +179,16 @@ pair<double,double> stratified_sampling<L>::estimator() const { return {est_mean, est_std}; } -struct f_mu : public std::unary_function<std::vector<double>, double> +template <typename Fct> +struct exponential_tilt : public std::unary_function<std::vector<double>, double> { - f_mu(std::vector<double> mu, asian_option A) : mu(mu), A(A){ + exponential_tilt(std::vector<double> mu, Fct f) : mu(mu), f(f){ norm_mu = 0; for(unsigned int i=0; i<mu.size(); i++) { norm_mu += mu[i]*mu[i]; } }; - + double operator()(std::vector<double> X) { std::vector<double> Y(X.size()); double scal = 0; @@ -196,12 +196,11 @@ struct f_mu : public std::unary_function<std::vector<double>, double> Y[i] = X[i] + mu[i]; scal+=X[i]*mu[i]; } - return A(Y)*exp(-scal-0.5*norm_mu); + return f(Y) * exp(-scal-0.5*norm_mu); }; - - private : + + private: std::vector<double> mu; - asian_option A; + Fct f; double norm_mu; }; - |
