aboutsummaryrefslogtreecommitdiffstats
path: root/src/opti.cpp
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@serenitascapital.com>2016-04-13 13:40:48 -0400
committerGuillaume Horel <guillaume.horel@serenitascapital.com>2016-04-13 13:40:48 -0400
commit16e1de7cbeaf4d62d8d008d6c3bc0eab2b1d6c5f (patch)
tree20a084fc74475f32b465cbec04ca592e60f2fa37 /src/opti.cpp
parent28fe184f2fea5031f352cf73fc30b99b5cde8f6f (diff)
downloadprojet_C++-functional.tar.gz
simplify opti.cppfunctional
Diffstat (limited to 'src/opti.cpp')
-rw-r--r--src/opti.cpp29
1 files changed, 5 insertions, 24 deletions
diff --git a/src/opti.cpp b/src/opti.cpp
index 6b05ecd..211a7e3 100644
--- a/src/opti.cpp
+++ b/src/opti.cpp
@@ -1,8 +1,5 @@
#include "opti.hpp"
-
-double pos (double x){
- return x>0?x:0;
-};
+#include "option.hpp"
double f (const std::vector<double> &X, std::vector<double> &grad, void *params) {
int d = X.size();
@@ -13,23 +10,15 @@ 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;
};
-
-
std::vector<double> argmax(double r, double T, double S0, double V, double K, int d){
-
+
double params[5] = {r, T, S0, V, K};
-
+
nlopt::opt opt(nlopt::LN_COBYLA, d);
opt.set_max_objective(f, &params);
@@ -44,11 +33,3 @@ std::vector<double> argmax(double r, double T, double S0, double V, double K, in
return x;
}
-
-
-
-
-
-
-
-