Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

mainmontecarlo.cpp

Go to the documentation of this file.
00001 #include "../Interface/main.h"
00002 #include"../PartA/MonteCarlo1/ParkMiller.h"
00003 #include"../PartA/MonteCarlo1/MersenneTwister.h"
00004 #include"../PartA/MonteCarlo1/RandC.h"
00005 #include"../PartA/MonteCarlo1/Sobol.h"
00006 #include"../PartA/MonteCarlo1/GaussianProcess.h"
00007 #include"../common/Normals.h"
00008 #include"../PartA/MonteCarlo1/PayOff.h"
00009 #include"../PartA/MonteCarlo1/Random.h"
00010 #include"../PartB/YieldCurve.h"
00011 #include"../PartA/MonteCarlo1/Drift.h"
00012 #include"../PartA/MonteCarlo1/MCEngine.h"
00013 #include "time.h"
00014 
00015 #include<iostream>
00016 #include<valarray>
00017 using namespace std;
00018 
00019 bool mainmontecarlo(void) {
00020     Real spot=100, strike=110, vol=0.2, mat=1.,rate=0.02;
00021         LongNatural nPaths=100000,nDates=1;
00022         volsurface* myvol=new volsurface(vol);
00023         yieldCurve* mycurve=new yieldCurve(rate);
00024         //Set time
00025         Real tme;
00026         tme=clock();
00027         Real mcPrice=mainmc(mat,strike,spot,myvol,mycurve,nPaths,nDates,1);
00028         tme=clock()-tme;
00029         cout<<"MC price"<<endl;
00030         cout<<mcPrice<<endl;
00031         cout<<"MC time"<<endl;
00032         cout<<tme/1000.<<endl;
00033         if (mcPrice>4.96 || mcPrice<4.92) {
00034                 cout <<"did not get expected result for MC pricer - Part A"<<endl;
00035                 return false;
00036         } else return true;
00037 }
00038 
00039 Real 
00040 mainmc(Real Expiry, Real Strike, Real Spot, volsurface* pvolsurface, yieldCurve* pyieldCurve,
00041            LongNatural nPaths, LongNatural nDates, Integer PrdName)
00042 {
00043         Real initialHazardRate,meanReversionSpeed,price=0;
00044         valarray <Real> vStepIncrements,vDrift;
00045         valarray <Real> vPath;
00046         valarray <Real> vDiscFactors;
00047         valarray<Real> uniformSample;
00048         valarray <Real> gaussianSample;
00049         valarray<LongInteger> vDates;
00050         LongNatural i,seed;
00051         
00052         //seed  
00053         seed = 100000000;
00054 
00055         //initialisation of arrays
00056         vPath.resize(nDates);
00057         vStepIncrements.resize(nDates);
00058         vDiscFactors.resize(nDates);
00059         vDrift.resize(nDates);
00060         vDates.resize(nDates+1);
00061         uniformSample.resize(nDates);
00062         gaussianSample.resize(nDates);
00063 
00064         const Real constRate=r;
00065         initialHazardRate=Spot;
00066         meanReversionSpeed=0.;
00067 
00068         Date Today=Date();
00069         Today.setDateToToday();
00070 
00071         //initialisation of drift
00072         Drift* pDrift = new Drift(Today, Expiry,nDates,pyieldCurve,pvolsurface,Strike);
00073         vDrift=pDrift->GetvDrift();
00074         vDates=pDrift->GetvDates();
00075 
00076         //initialisation of uniform number generator
00077         MersenneTwister* pRandGen = new MersenneTwister(seed);
00078 
00079         //initialisation of random generator
00080         Random* pRandom = new Random(nDates,pRandGen);
00081         
00082         //initialisation of gaussian process
00083         GaussianProcess* pGaussianProcess = new GaussianProcess(vDates,nDates,initialHazardRate,vDrift,meanReversionSpeed,pvolsurface,Strike);
00084         
00085         //initialisation of default jump process 
00086         pGaussianProcess->GetStepIncrements(vStepIncrements);
00087         
00088         //initialisation of payoff function
00089         PayOff thePayOff(Strike);
00090 
00091         //initialisation of yield curve
00092         for (i=0;i<nDates;++i)
00093                 vDiscFactors[i] = pyieldCurve->discountFactor((i+1)*Expiry/nDates);
00094 
00095         MCEngine* pMCEngine = new MCEngine(nPaths,nDates,vDiscFactors);
00096         pMCEngine->RunEngineGeneral(pRandom,pGaussianProcess,thePayOff,gaussianSample,vPath,PrdName);
00097         price=pMCEngine->MCResult();
00098         pRandom->SetSeed(seed);
00099 
00100         delete pyieldCurve;
00101         delete pvolsurface;
00102         delete pDrift;
00103         delete pRandom;
00104         delete pGaussianProcess;
00105 
00106         return price;
00107 
00108 }

Note: Generated nightly - reload for latest version
Generated on Thu Dec 22 23:12:36 2005 for terreneuve by doxygen 1.3.6