diff options
| author | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2016-04-20 15:57:52 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2016-04-20 16:04:17 -0400 |
| commit | 61d99224c2f5cbf0320bf05aca0d2ce15c2d0482 (patch) | |
| tree | bf90ce1b9a98502e1f810015152b1fcfd286b39e /src/opti.cpp | |
| parent | 4e723ffa229db059601d3a0c47f6c229652ee208 (diff) | |
| download | projet_C++-61d99224c2f5cbf0320bf05aca0d2ce15c2d0482.tar.gz | |
Répare opti.hpp
Diffstat (limited to 'src/opti.cpp')
| -rw-r--r-- | src/opti.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/opti.cpp b/src/opti.cpp index 8a9b34e..7f838e9 100644 --- a/src/opti.cpp +++ b/src/opti.cpp @@ -1,27 +1,33 @@ #include "opti.hpp" #include "option.hpp" +typedef struct option_params { + double r; + double T; + double S0; + double V; + double K; + bool call; +} option_params; double f (const std::vector<double> &X, std::vector<double> &grad, void *params) { int d = X.size(); - double *p =(double *)params; - double r=p[0] ; double T=p[1]; double S0=p[2]; - double V=p[3]; double K=p[4]; + option_params *p = (option_params *)params; double norm = 0; for(int i=0; i<d; i++){ norm+=X[i]*X[i]; } - asian_option A(r, T, S0, V, K); + asian_option A(p->r, p->T, p->S0, p->V, p->K, p->call); return log(A(X)) - 0.5*norm; }; -std::vector<double> argmax(double r, double T, double S0, double V, double K, int d){ - - double params[5] = {r, T, S0, V, K}; - +std::vector<double> argmax(double r, double T, double S0, double V, double K, int d, bool call){ + + option_params params = {.r = r, .T = T, .S0 = S0, .V=V, .K=K, .call=call}; + nlopt::opt opt(nlopt::LN_COBYLA, d); opt.set_max_objective(f, ¶ms); @@ -36,11 +42,3 @@ std::vector<double> argmax(double r, double T, double S0, double V, double K, in return x; } - - - - - - - - |
