aboutsummaryrefslogtreecommitdiffstats
path: root/option.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'option.cpp')
-rw-r--r--option.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/option.cpp b/option.cpp
new file mode 100644
index 0000000..5caf23f
--- /dev/null
+++ b/option.cpp
@@ -0,0 +1,61 @@
+#include <vector>
+#include <gsl/gsl_cdf.h>
+#include "var_alea.hpp"
+#include <algorithm>
+#include <iostream>
+
+double r;
+double T;
+double S0;
+double V;
+int d;
+
+std::vector<double> path_gen(std::vector<double> X){
+ d=X.size();
+ std::vector<double> S(d);
+ S[0]= S0;
+ 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]);
+ }
+ return S;
+}
+
+double mean_monte_carl(double r, double T, double S0, double V, int N, int d){
+ double moyenne=0;
+ gaussian G;
+ std::vector<double> S(d);
+ std::vector<double> X(d);
+ for(int i=1; i<N; i++){
+ for(int j=1;j<d;i++){
+ X[i]=G();
+ }
+ S=path_gen(X);
+ moyenne+=std::accumulate(S.begin(), S.end(), 0 );
+ }
+ return moyenne/N;
+}
+
+int main(){
+ init_alea(0);
+ double r=0.05;
+ double T=1.0;
+ double S0=50.0;
+ double V=0.1;
+ int d=16;
+ int N=1000000;
+
+
+ double moyenne = mean_monte_carl(r, T, S0, V, N, d);
+ std::cout<<moyenne<<std::endl;
+
+
+ return 0;
+}
+
+
+
+
+
+
+
+