blob: 87aeca61105fe3d756c33630ce50ba2177de31bc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include <vector>
#include <gsl/gsl_cdf.h>
#include "var_alea.hpp"
#include <algorithm>
#include <iostream>
struct option_param {
double r;
double T;
double S0;
double V;
int d;
};
std::vector<double> path_gen(std::vector<double> X, option_param *p){
std::vector<double> S(p->d);
S[0]= p->S0;
for(int i=1;i<p->d;i++){
S[i]=S[i-1]*exp((p->r-p->V*p->V/2)*(p->T/p->d)+p->V*sqrt(p->T/p->d)*X[i]);
}
return S;
}
double mean_monte_carl(option_param* p, int N){
double moyenne=0;
gaussian G;
std::vector<double> S(p->d);
std::vector<double> X(p->d);
for(int i=1; i<N; i++){
for(int j=1;j<p->d;i++){
X[i]=G();
}
S=path_gen(X, p);
moyenne+=std::accumulate(S.begin(), S.end(), 0 );
}
return moyenne/N;
}
int main(){
init_alea(0);
option_param* p = {.r=0.05, .T=1.0, .S0=50.0, .V=0.1, .d=16};
int N=1000000;
double moyenne = mean_monte_carl(p, N);
std::cout<<moyenne<<std::endl;
return 0;
}
|