diff options
| author | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2016-04-13 11:34:19 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2016-04-13 11:34:19 -0400 |
| commit | 28fe184f2fea5031f352cf73fc30b99b5cde8f6f (patch) | |
| tree | 5b5e40c800c5648da44f6cf70ebde8ecb6110723 /src | |
| parent | 4e5104a0186bd705b5ed1f57f73375ace60587f6 (diff) | |
| download | projet_C++-28fe184f2fea5031f352cf73fc30b99b5cde8f6f.tar.gz | |
replace unary_function by function
Diffstat (limited to 'src')
| -rw-r--r-- | src/option.hpp | 12 | ||||
| -rw-r--r-- | src/projet.cpp | 8 | ||||
| -rw-r--r-- | src/stratified_sampling.hpp | 3 |
3 files changed, 10 insertions, 13 deletions
diff --git a/src/option.hpp b/src/option.hpp index 4d9ee13..c969071 100644 --- a/src/option.hpp +++ b/src/option.hpp @@ -1,12 +1,12 @@ -#include "rqmc.hpp" +#include <functional> double pos (double x); -struct asian_option : public std::unary_function<std::vector<double>, double> +struct asian_option : public std::function<double(std::vector<double>)> { asian_option(double r, double T, double S0, double V, int d, double K) : r(r), T(T), S0(S0), V(V), d(d), K(K) {}; - + double operator()(std::vector<double> X) const { std::vector<double> S(d); S[0]= S0*exp((r-V*V/2)*(T/d)+V*sqrt(T/d)*X[0]); @@ -15,8 +15,8 @@ struct asian_option : public std::unary_function<std::vector<double>, double> } double temp = std::accumulate(S.begin(), S.end(), 0.)/d; return exp(-r*T)*pos(temp-K); - }; - + }; + private: double r; double T; @@ -25,5 +25,3 @@ struct asian_option : public std::unary_function<std::vector<double>, double> int d; double K; }; - - diff --git a/src/projet.cpp b/src/projet.cpp index c4bd6d8..e5405e0 100644 --- a/src/projet.cpp +++ b/src/projet.cpp @@ -85,15 +85,13 @@ void exemple2_rqmc() { } }; -struct first:public std::unary_function<std::vector<double>, double> -{ double operator()(std::vector<double> X){return X[0];} -}; void exemple1_rqmc(){ int N = 100; - first f; //comme quasi_gaussian retourne un vecteur, on doit composer avec f pour avoir le double QG()[0] + //comme quasi_gaussian retourne un vecteur, on doit composer avec f pour avoir le double QG()[0] + std::function<double(std::vector<double>)> f = [](std::vector<double> x){return x[0];}; std::vector<double> result(3); - result = monte_carlo (100,quasi_mean<struct first, sobol> (N, 1, f)); + result = monte_carlo (100, quasi_mean<decltype(f), sobol> (N, 1, f)); for(int i =0; i<3; i++){ std::cout<<result[i]<<std::endl; } diff --git a/src/stratified_sampling.hpp b/src/stratified_sampling.hpp index 9175f75..1ab1126 100644 --- a/src/stratified_sampling.hpp +++ b/src/stratified_sampling.hpp @@ -3,6 +3,7 @@ #include <iostream> #include "var_alea.hpp" #include <gsl/gsl_cdf.h> +#include <functional> using namespace std; @@ -180,7 +181,7 @@ pair<double,double> stratified_sampling<L>::estimator() const { } template <typename Fct> -struct exponential_tilt : public std::unary_function<std::vector<double>, double> +struct exponential_tilt : public std::function<double(std::vector<double>)> { exponential_tilt(std::vector<double> mu, Fct f) : mu(mu), f(f){ norm_mu = 0; |
