aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp34
-rw-r--r--src/opti.cpp3
-rw-r--r--src/stratified_sampling.hpp9
3 files changed, 29 insertions, 17 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 561b8c2..fb6df08 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -45,22 +45,36 @@ x = 1.64*S.estimator().second;
void exemple2 (){
- std::vector<double> mu(16);
- mu = argmax(0.05, 1.0, 50, 0.1, 45, 16);
+ int d= 16;
+ std::vector<double> mu(d);
+ mu = argmax(0.05, 1.0, 50, 0.1, 45, d);
double norm_mu = 0;
- std::vector<double> u(16);
- for(int i=0; i<16; i++) {
+ std::vector<double> u(d);
+ for(int i=0; i<d; i++) {
norm_mu += mu[i]*mu[i];
- u[i] = mu[i]/norm_mu;
+ }
+ for(int i=0; i<d; i++) {
+ u[i] = mu[i]/sqrt(norm_mu);
}
vector<double> q = quantile_norm(100, 1);
vector<double> p(100, 0.01);
- asian_option A(0.05, 1.0, 50, 0.1, 45, 16);
+ asian_option A(0.05, 1.0, 50, 0.1, d, 45);
f_mu G(mu,A);
- multi_gaussian_truncated MG(q[50],q[51], u);
- for(int i=0; i<10; i++){
- std::cout<<G(MG())<<std::endl;
- }
+ std::vector<compose_t <f_mu, multi_gaussian_truncated> > X;
+ X.push_back(compose(G, multi_gaussian_truncated(GSL_NEGINF,q[0], u)));
+ for(int i=1; i<100; i++) {
+ X.push_back(compose(G, multi_gaussian_truncated(q[i-1],q[i], u)));
+ }
+ for(int i=0; i<100; i=i+10){
+ std::cout<<X[i]()<<endl;
+ }
+ stratified_sampling<compose_t <f_mu, multi_gaussian_truncated> > S(p, X);
+ S.draw(1000);
+ cout<<"l'estimateur de la moyenne est :"<<S.estimator().first<<endl;
+ //~ compose_t <f_mu, multi_gaussian_truncated> X = compose(G,MG);
+ //~ for(int i=0; i<10; i++){
+ //~ std::cout<<X()<<std::endl;
+ //~ }
}
diff --git a/src/opti.cpp b/src/opti.cpp
index 23ddff3..6b05ecd 100644
--- a/src/opti.cpp
+++ b/src/opti.cpp
@@ -39,9 +39,6 @@ std::vector<double> argmax(double r, double T, double S0, double V, double K, in
std::vector<double> x(d,0);
std::vector<double> g(0);
-
- std::cout<<"valeur au début : "<<f(x, g, &params)<<std::endl;
-
double maxf;
nlopt::result result = opt.optimize(x, maxf);
diff --git a/src/stratified_sampling.hpp b/src/stratified_sampling.hpp
index 7573ef2..c04369e 100644
--- a/src/stratified_sampling.hpp
+++ b/src/stratified_sampling.hpp
@@ -141,8 +141,9 @@ void stratified_sampling<L>::draw(int N) {
m=0;
s=0;
for(int j=0;j<M[i];j++){
- m=m+X[i]();
- s=s+X[i].current()*X[i].current();
+ double temp = X[i]();
+ m=m+temp;
+ s=s+temp*temp;
}
oldmean=mean[i];
mean[i]=(mean[i]*cumM[i]+m)/(cumM[i]+M[i]);
@@ -192,8 +193,8 @@ pair<double,double> stratified_sampling<L>::estimator() const {
struct f_mu : public std::unary_function<std::vector<double>, double>
{
f_mu(std::vector<double> mu, asian_option A) : mu(mu), A(A){
- double norm_mu = 0;
- for(int i=0; i<16; i++) {
+ norm_mu = 0;
+ for(unsigned int i=0; i<mu.size(); i++) {
norm_mu += mu[i]*mu[i];
}
};