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

mainIRVanillaSwap.cpp

Go to the documentation of this file.
00001 #include "../Interface/main.h"
00002 #include "../PartD/VanillaSwap.h"
00003 #include <iostream>
00004 
00005 using namespace std;
00006 
00009 bool mainIRVanillaSwap(void) {
00010         cout<<"Let us create a 5 Years Annual Vanilla Swap - Fixed rate 0.0471"<<endl;
00011         Real priceSwapAn5Y=0.0;
00012         string datadir = FileReader::getdatadirasstring();
00013         string yieldCurveData = datadir + "yctest.csv";
00014         valarray<yieldPoint> *yieldCurveArray = 
00015                 FileReader::buildYieldPointArray(yieldCurveData);
00016         yieldCurve* underlyingCurve=new yieldCurve(*yieldCurveArray, "test");
00017 
00018         Date d=Date();
00019         d.setDateToToday();
00020         
00021         valarray<Date> dates(5);
00022         valarray<Real> Notionals(5);
00023         for (int i=0;i<5;i++){
00024                 dates[i]=d.plusYears(i+1);      
00025                 Notionals[i]=1000000;
00026         }
00027         
00028         SwapLeg legsInformation=SwapLeg(dates,Notionals);
00029 
00030         CashFlow fixLeg=CashFlow(legsInformation,0.0471);
00031         CashFlow varLeg=CashFlow(legsInformation,*underlyingCurve);
00032 
00033         cout<<"Fixed "<<fixLeg.getFairValue(underlyingCurve)<<endl;
00034         cout<<"Float "<<varLeg.getFairValue(underlyingCurve)<<endl;
00035 
00036         VanillaSwap swap5YAnnual=VanillaSwap(fixLeg,varLeg,"fixed","floating",underlyingCurve);
00037         priceSwapAn5Y=swap5YAnnual.returnPrice();
00038         cout<<"Value "<<priceSwapAn5Y<<"\n"<<endl;
00039         // closed to par as we took a mkt swap annual rate !
00040 
00041         cout<<"Let us create a 4 Years Semi-Annual Vanilla Swap - Fixed rate 0.04641"<<endl;
00042         Real priceSwapSemiAn4Y=0.0;
00043         d.setDateToToday();     
00044         dates.resize(8);
00045         Notionals.resize(8);
00046         for (int i=0;i<8;i++){
00047                 dates[i]=d.plusMonths((i+1)*6); 
00048                 Notionals[i]=1000000;
00049         }
00050         
00051         legsInformation=SwapLeg(dates,Notionals);
00052 
00053         fixLeg=CashFlow(legsInformation,0.04641);
00054         varLeg=CashFlow(legsInformation,*underlyingCurve);
00055 
00056         cout<<"Fixed "<<fixLeg.getFairValue(underlyingCurve)<<endl;
00057         cout<<"Float "<<varLeg.getFairValue(underlyingCurve)<<endl;
00058 
00059         VanillaSwap swap4YSemiAnnual=VanillaSwap(fixLeg,varLeg,"fixed","floating",underlyingCurve);
00060         priceSwapSemiAn4Y=swap4YSemiAnnual.returnPrice();
00061         cout<<"Value "<<priceSwapSemiAn4Y<<endl;
00062         
00063         delete underlyingCurve;
00064         
00065         bool res=true;
00066         res&=(priceSwapAn5Y>1,050)&&(priceSwapAn5Y<1,052);
00067         res&=(priceSwapSemiAn4Y>152)&&(priceSwapSemiAn4Y<153);
00068         return res;
00069 }

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