Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- #include <vector>
- #include <cmath>
- using namespace std;
- typedef vector<double> samplePath;
- const double pi = 3.141592;
- class cMonteCarlo {
- public:
- cMonteCarlo(double S0, double r, double sigma){
- this->S0 = S0_;
- this->r = r_;
- this->sigma = sigma_;
- srand(time(NULL));
- }
- double generatePath(double r, int N, double T){
- double value = 0;
- double lim = exp(-e*T)*1/N;
- for (int i=0;i<N;i++)
- value +=
- }
- private:
- double S0; double r; double sigma;
- samplePath createPath(double t, int m, double drt){
- vector <double> path(m+1, 0.0);
- double St = S0;
- for (int k=0; k<m; k++){
- S[k] = St*exp((r-(sigma*sigma)/2)*(T/m)+sigma*sqrt(T/m)*normal());
- St = S[k];
- }
- }
- double normal(){
- double x = (rand()+1.0)/(RAND_MAX+1.0);
- double y = (rand()+1.0)/(RAND_MAX+1.0);
- return sqrt(-2.0*log(x)) * cos(2.0*pi*y)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement