diff options
Diffstat (limited to 'src')
| -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 |
4 files changed, 7 insertions, 16 deletions
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; |
