diff options
| author | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2016-04-21 17:37:40 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2016-04-21 17:37:40 -0400 |
| commit | e3694fb5e5b6b2b307dd31399b242e01977ed19f (patch) | |
| tree | 96c9831c14ce89c03e2b2191daeb7397a5db8c6e /src/opti.cpp | |
| parent | 8c9f217887de0802d6b8dfa1f872ec3cf8797d45 (diff) | |
| download | projet_C++-e3694fb5e5b6b2b307dd31399b242e01977ed19f.tar.gz | |
use lambda functionslambda_fun
Diffstat (limited to 'src/opti.cpp')
| -rw-r--r-- | src/opti.cpp | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/src/opti.cpp b/src/opti.cpp index 2824a69..71577c1 100644 --- a/src/opti.cpp +++ b/src/opti.cpp @@ -1,5 +1,6 @@ #include "opti.hpp" #include "option.hpp" +#include <algorithm> typedef struct option_params { double r; @@ -11,12 +12,8 @@ typedef struct option_params { } option_params; double f (const std::vector<double> &X, std::vector<double> &grad, void *params) { - int d = X.size(); option_params *p = (option_params *)params; - double norm = 0; - for(int i=0; i<d; i++){ - norm+=X[i]*X[i]; - } + double norm = std::accumulate(X.begin(), X.end(), 0., [](double x, double y){ return x + y*y;}); asian_option A(p->r, p->T, p->S0, p->V, p->K, p->call); return log(A(X)+1e-10) - 0.5*norm;//on rajoute 1e-10 pour être sur que le log soit défini }; |
