diff options
| author | Bertrand <bertrand.horel@gmail.com> | 2016-04-15 14:21:04 +0200 |
|---|---|---|
| committer | Bertrand <bertrand.horel@gmail.com> | 2016-04-15 14:21:04 +0200 |
| commit | 745160f29da6ec55fa48863768bcc1305edd9314 (patch) | |
| tree | ef6c04329d23b91e87ca41afbc159a3d827fdd37 | |
| parent | b2ef5772372a85717f0eb5d79576fd035bf15adb (diff) | |
| download | projet_C++-745160f29da6ec55fa48863768bcc1305edd9314.tar.gz | |
encore un peu de nettoyage
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | src/opti.cpp | 14 | ||||
| -rw-r--r-- | src/opti.hpp | 3 | ||||
| -rw-r--r-- | src/option.hpp | 5 | ||||
| -rw-r--r-- | src/projet.cpp | 1 |
5 files changed, 8 insertions, 17 deletions
@@ -17,7 +17,7 @@ table.tex: make_table make_table: make_table.o mt19937.o $(CXX) $^ -o $@ -projet: projet.o stratified_sampling.o mt19937.o var_alea.o opti.o rqmc.o p_adic.o +projet: projet.o stratified_sampling.o mt19937.o var_alea.o opti.o rqmc.o p_adic.o option.o $(CXX) $^ -o $@ $(GSL_FLAGS) $(NLOPT_FLAGS) stratified_sampling.o: stratified_sampling.hpp diff --git a/src/opti.cpp b/src/opti.cpp index 6b05ecd..18759cf 100644 --- a/src/opti.cpp +++ b/src/opti.cpp @@ -1,8 +1,6 @@ #include "opti.hpp" +#include "option.hpp" -double pos (double x){ - return x>0?x:0; -}; double f (const std::vector<double> &X, std::vector<double> &grad, void *params) { int d = X.size(); @@ -13,14 +11,8 @@ double f (const std::vector<double> &X, std::vector<double> &grad, void *params) for(int i=0; i<d; i++){ norm+=X[i]*X[i]; } - std::vector<double> S(d); - S[0]= S0*exp((r-V*V/2)*(T/d)+V*sqrt(T/d)*X[0]); - for(int i=1;i<d;i++){ - S[i]=S[i-1]*exp((r-V*V/2)*(T/d)+V*sqrt(T/d)*X[i]); - } - double temp = std::accumulate(S.begin(), S.end(), 0.)/d; - double value = exp(-r*T)*pos(temp-K); - return log(value) - 0.5*norm; + asian_option A(r, T, S0, V, d, K); + return log(A(X)) - 0.5*norm; }; diff --git a/src/opti.hpp b/src/opti.hpp index e12d544..5be65b3 100644 --- a/src/opti.hpp +++ b/src/opti.hpp @@ -1,11 +1,8 @@ #include <vector> #include <nlopt.hpp> #include <cmath> -#include <algorithm> #include <iostream> -double pos (double x); - double f (const std::vector<double> &X, std::vector<double> &grad, void *params); std::vector<double> argmax(double r, double T, double S0, double V, double K, int d); diff --git a/src/option.hpp b/src/option.hpp index 4d9ee13..49d1900 100644 --- a/src/option.hpp +++ b/src/option.hpp @@ -1,4 +1,5 @@ -#include "rqmc.hpp" +#include <vector> +#include <algorithm> double pos (double x); @@ -24,6 +25,6 @@ struct asian_option : public std::unary_function<std::vector<double>, double> double V; int d; double K; - }; +}; diff --git a/src/projet.cpp b/src/projet.cpp index c4bd6d8..007dd6c 100644 --- a/src/projet.cpp +++ b/src/projet.cpp @@ -7,6 +7,7 @@ #include <algorithm> #include "opti.hpp" #include "option.hpp" +#include "rqmc.hpp" using namespace std; |
