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

Drift.cpp

Go to the documentation of this file.
00001 #include "../../common\types.h"
00002 #include "./drift.h"
00003 #include <math.h>
00004 
00005 Drift::Drift(Date startDate, Real ExpiryInYears,LongNatural& nDates,yieldCurve* pyieldCurve,volsurface* pvolsurface, Real Strike)
00006                                                                         :       m_nDates(nDates)
00007 {
00008         vDates.resize(nDates+1);
00009         Date stepDate=Date();
00010         //Build dates with constant step
00011         for (Natural i=0;i<nDates+1;++i) {
00012                 stepDate=startDate.plusDays((Natural)(365*ExpiryInYears*i/nDates));
00013                 vDates[i]=stepDate.serialNumber();
00014         }
00015         //Memory allocation for vDrift
00016         vDrift.resize(nDates);
00017         //Build drift path according to Ito's formula
00018         Date startStep,endStep;
00019         for (i=0;i<nDates;++i) {
00020                 startStep=Date(vDates[i]);
00021                 endStep=Date(vDates[i+1]);
00022                 vDrift[i]=(pyieldCurve->forwardRate(startStep,endStep)-0.5*pow(pvolsurface->forwardVolatility(Strike,startStep,endStep),2))*(vDates[i+1]-vDates[i])/365;
00023         }
00024 }
00025 
00026 Drift::Drift(void)
00027 {
00028 }
00029 
00030 Drift::Drift(Date startDate, Real ExpiryInYears,Real rateToMaturity,Real volToMaturity)
00031 {
00032         m_nDates=1;
00033         vDates.resize(m_nDates+1);
00034         Date stepDate=Date();
00035         //Build dates with constant step -- useless but allocation for the getvDates necessary for Gaussian process.
00036         for (Natural i=0;i<m_nDates+1;++i) {
00037                 stepDate=startDate.plusDays((Natural)(365*ExpiryInYears*i/m_nDates));
00038                 vDates[i]=stepDate.serialNumber();
00039         }
00040 
00041         //Memory allocation for vDrift
00042         vDrift.resize(m_nDates);
00043         //Build drift path according to Ito's formula
00044         vDrift[0]=(rateToMaturity-0.5*pow(volToMaturity,2))*ExpiryInYears;
00045 }
00046 
00047 Drift::~Drift()
00048 {
00049 }
00050 
00051 valarray<Real> Drift::GetvDrift(void)
00052 {
00053         valarray<Real> Driftarray;
00054         Driftarray.resize(m_nDates);
00055         for (Natural i=0;i<m_nDates;++i)
00056                 Driftarray[i]=vDrift[i];
00057         return Driftarray;
00058 }
00059 
00060 Real Drift::GetDriftattimei(LongNatural i)
00061 {
00062         if (i<m_nDates)
00063                 return vDrift[i];
00064         else
00065                 return 0.;
00066 }
00067 
00068 valarray<LongInteger> Drift::GetvDates(void)
00069 {
00070         valarray<LongInteger> Datesarray;
00071         Datesarray.resize(m_nDates+1);
00072         for (Natural i=0;i<m_nDates+1;++i){
00073                 Datesarray[i]=vDates[i];
00074         }
00075         return Datesarray;
00076 }
00077 
00078 LongInteger Drift::GetTimeBtwDates(LongNatural i,LongNatural j)
00079 {
00080         if (i<m_nDates && j<m_nDates)
00081                 return vDates[j]-vDates[i];
00082         else
00083                 return 0;
00084 }

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