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

maintestasset.cpp

Go to the documentation of this file.
00001 #include"..\PartC\asset.h"
00002 #include "../common/filereader.h"
00003 
00004 #include<iostream>
00005 #include<valarray>
00006 #include<time.h>
00007 using namespace std;
00008 
00009 
00014 bool mainasset(void) {
00015         string datadir = FileReader::getdatadirasstring();
00016         string yieldCurveData = datadir + "yctest.csv";
00017         bool result=true;
00018         Real test=0.0;
00019         // the underlying curve
00020         valarray<yieldPoint> *rates = 
00021                 FileReader::buildYieldPointArray(yieldCurveData);
00022 
00023         yieldCurve testcurve=yieldCurve(*rates,"test");
00024 
00025         Date d= Date();
00026         d.setDateToToday();
00027         d=d.plusYears (1);
00028         flowSchedule flow1=flowSchedule(d,0.05); //5% after 1Y
00029         d.setDateToToday();
00030         d=d.plusYears (2);
00031         flowSchedule flow2=flowSchedule(d,0.05); //5% after 2Y
00032         valarray<flowSchedule> divSched(2);
00033         divSched [0]=flow1;
00034         divSched [1]=flow2;
00035         asset a=asset(100,testcurve,false,0,divSched);
00036         d.setDateToToday();
00037         d=d.plusYears (1);
00038         d=d.plusDays (-1);
00039         
00040         test=a.forwardPrice(d);
00041         result&=(test==100);
00042         cout<<"Div Sched - fwd 1yr minus 1day of payment: "<<test<<endl;
00043         
00044         d=d.plusDays (+1);
00045         test=a.forwardPrice(d);
00046         result&=(test>95.2387)&&(test<95.2389);
00047         cout<<"Div Sched - fwd 1yr of payment: "<<test<<endl;
00048         
00049         d.setDateToToday();
00050         d=d.plusYears (2);
00051         test=a.forwardPrice(d);
00052         result&=(test>90.6942)&&(test<90.6944);
00053         cout<<"Div Sched - fwd 2yrs of payment: "<<test<<endl;
00054 
00055         a.setDivAsRate(0.05);
00056         d.setDateToToday();
00057         d=d.plusYears (1);
00058         test=a.forwardPrice(d);
00059         result&=(test>94.7273)&&(test<94.7275);
00060         cout<<"Fixed div Rate - fwd 1yr of payment: "<<test<<endl;
00061         
00062         // For output file
00063         valarray<flowSchedule> testFlows(10);
00064         d.setDateToToday();
00065         Real rate;
00066         for (Natural i=0;i<10;i++){
00067                 d=d.plusYears (1);
00068                 if (i % 2 == 0)
00069                         rate =0.05;
00070                 else
00071                         rate =0.10;
00072                 testFlows[i]=flowSchedule(d,rate);
00073         }
00074 
00075         asset b= asset(100,testcurve,false,0,testFlows,EUR);
00076         asset c= asset(100,testcurve,true,0.075);
00077         string filename = FileReader::getdatadirasstring() + "test_Asset.txt"; 
00078         ofstream myfile(filename.c_str()); 
00079         myfile << "Test Forward Price - Div Sched 0.05 even years, 0.10 odd years, for 10 years\n";
00080         d.setDateToToday();
00081         for (Natural i=1;i<=24;i++){
00082                 d=d.plusMonths (6);
00083                 myfile<<d.toString()<<" , "<<b.forwardPrice(d)<<"\n";
00084         }       
00085         myfile << "\nTest Forward Price - Fixed Rate at 0.075, for 10 years\n";
00086         d.setDateToToday();
00087         for (Natural i=1;i<=24;i++){
00088                 d=d.plusMonths (6);
00089                 myfile<<d.toString()<<" , "<<c.forwardPrice(d)<<"\n";
00090         }       
00091         myfile.close();
00092 
00093         return result;
00094 }

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