diff options
| author | Bertrand <bertrand.horel@gmail.com> | 2016-04-20 21:56:00 +0200 |
|---|---|---|
| committer | Bertrand <bertrand.horel@gmail.com> | 2016-04-20 21:56:00 +0200 |
| commit | 4e723ffa229db059601d3a0c47f6c229652ee208 (patch) | |
| tree | 8fc76ff57fecf16b3d986aa057477abd14a3ed1a /src/option.hpp | |
| parent | d3d2034b35a5fe76f533a4d5ffc9db7ea0f778d9 (diff) | |
| download | projet_C++-4e723ffa229db059601d3a0c47f6c229652ee208.tar.gz | |
modification de la structure asian option
Diffstat (limited to 'src/option.hpp')
| -rw-r--r-- | src/option.hpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/option.hpp b/src/option.hpp index 49d1900..12c1043 100644 --- a/src/option.hpp +++ b/src/option.hpp @@ -5,17 +5,23 @@ double pos (double x); struct asian_option : public std::unary_function<std::vector<double>, 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) {}; + asian_option(double r, double T, double S0, double V, double K, bool call = true) + : r(r), T(T), S0(S0), V(V), K(K) {}; - double operator()(std::vector<double> X) const { + double operator()(std::vector<double> &X) const { + int d= X.size(); 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; - return exp(-r*T)*pos(temp-K); + if (call) { + return exp(-r*T)*pos(temp-K); + } + else { + return exp(-r*T)*pos(K-temp); + } }; private: @@ -23,8 +29,8 @@ struct asian_option : public std::unary_function<std::vector<double>, double> double T; double S0; double V; - int d; double K; + bool call; }; |
