Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #pragma once
  2. #include <iostream>
  3. #include <vector>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. typedef vector<double> samplePath;
  9. const double pi = 3.141592;
  10.  
  11. class cMonteCarlo {
  12. public:
  13.     cMonteCarlo(double S0, double r, double sigma){
  14.         this->S0 = S0_;
  15.         this->r = r_;
  16.         this->sigma = sigma_;
  17.         srand(time(NULL));
  18.     }
  19.    
  20.     double generatePath(double r, int N, double T){
  21.         double value = 0;
  22.         double lim = exp(-e*T)*1/N;
  23.        
  24.         for (int i=0;i<N;i++)
  25.             value +=
  26.     }
  27.    
  28.    
  29. private:
  30.     double S0; double r; double sigma;
  31.    
  32.     samplePath createPath(double t, int m, double drt){
  33.        vector <double> path(m+1, 0.0);
  34.         double St = S0;
  35.        
  36.         for (int k=0; k<m; k++){
  37.             S[k] = St*exp((r-(sigma*sigma)/2)*(T/m)+sigma*sqrt(T/m)*normal());
  38.             St = S[k];
  39.         }
  40.     }
  41.    
  42.     double normal(){
  43.         double x = (rand()+1.0)/(RAND_MAX+1.0);
  44.         double y = (rand()+1.0)/(RAND_MAX+1.0);
  45.         return sqrt(-2.0*log(x)) * cos(2.0*pi*y)
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement