00001 #include ".\importData.h"
00002
00003 importData::importData(void)
00004 {
00005 }
00006
00007 importData::importData(char *argv)
00008 {
00009 FileReader::setdatadir (argv);
00010 runInterface();
00011 }
00012
00013 void importData::importYieldCurve(string path){
00014 string yieldCurveData = _datadir + "/"+path;
00015
00016 valarray<yieldPoint> *rates =
00017 FileReader::buildYieldPointArray(yieldCurveData);
00018
00019 _yc =yieldCurve(*rates,"test yc");
00020 cout<<"- Yield curve imported"<<endl;
00021 }
00022
00023 void importData::importVolSurface(string path,Real spot)
00024 {
00025 Date t0=Date();
00026 t0.setDateToToday ();
00027 string volSurfaceData=_datadir+"/"+path;
00028 volsurfaceparams *params =
00029 FileReader::buildVolSurfaceParams(volSurfaceData);
00030
00031 _vs= volsurface(spot, t0, _yc, *params);
00032 _vs.setvolsurface();
00033 cout<<"- Volatility surface imported"<<endl;
00034 }
00035
00036 void importData::importCreditCurve(string path){
00037 string creditSpreadsData= _datadir+"/"+path;
00038 valarray<CreditSpreadPoint> *creditSpreadArray =
00039 FileReader::buildCreditSpreadPointArray(creditSpreadsData);
00040 _cc=creditCurve(_yc,*creditSpreadArray,"test cc");
00041 cout<<"- Credit spreads imported"<<endl;
00042 }
00043
00044
00045 bool importData::runInterface(){
00046 cout<<"\n**************************************"<<endl;
00047 cout<<"********* Data import Module *********"<<endl;
00048 cout<<"**************************************\n"<<endl;
00049 cout<<"As it is a financial products module, you first need to import market data."<<endl;
00050 cout<<"Would you like to import your own data or use the stale one provided ? "<<endl;
00051 cout<<"[The yield points come from the US swap market from Oct 5th, 2005]"<<endl;
00052 cout<<"[The options are on -- (spot 2994) from July 16th, 2005]"<<endl;
00053 cout<<"[The credit spreads are on -- from -- ]"<<endl;
00054 cout<<"Type 1 to input your data files location, 2 to see the files format,\n Else another key to get default inputs:"<<endl;
00055 string userWantsToImport;
00056 cin>>userWantsToImport;
00057 Natural importNAt=atoi(userWantsToImport.c_str());
00058 if(importNAt==2)
00059 importNAt=displayFileFormatsMenu();
00060 cout<<((importNAt==1) ? "\nYou will now choose your data:" : "\nThe program will get its own data:" )<<endl;
00061 if(importNAt!=1){
00062 _datadir=FileReader::getdatadirasstring();
00063 importYieldCurve();
00064 importVolSurface();
00065 importCreditCurve();
00066 cout<<"--> Default data imported\n"<<endl;
00067 setMarketData();
00068 return true;
00069 }
00070 else{
00071 return runUserDefinedInterface();
00072 }
00073 }
00074 void importData::setMarketData(){
00075 _marketData.yieldcurve=_yc;
00076 _marketData.vols=_vs;
00077 _marketData.creditcurve=_cc;
00078 }
00079
00080 bool importData::runUserDefinedInterface(){
00081 bool failure=true;
00082 bool input;
00083 bool yc,vs,cs;
00084 string dataDir;
00085 cout<<"We need a spot for the call/put prices to calibrate the volatility surface, please input one"<<endl;
00086 Real spot;
00087 cin>>spot;
00088
00089 while (failure){
00090 cout<<"\nNOTE:\n- Your own data should be in the SAME directory "<<endl;
00091 cout<<"- The yield curve name shoud be "<<YCNAME<<endl;
00092 cout<<"- The volatility suface name shoud be "<<VSNAME<<endl;
00093 cout<<"- The credit spreads name shoud be "<<CSNAME<<endl;
00094 cout<<"Please input the path where your data is located, ALL 3 files"<<endl;
00095 cin>>dataDir;
00096 cout<<"\n"<<endl;
00097 yc=FileReader::fileexists(dataDir+"/"+YCNAME);
00098 vs=FileReader::fileexists(dataDir+"/"+VSNAME);
00099 cs=FileReader::fileexists(dataDir+"/"+CSNAME);
00100 failure=!(yc&&vs&&cs);
00101 if(failure){
00102 if(!yc)
00103 cout<<"- "<<YCNAME<<" not found"<<endl;
00104 if(!vs)
00105 cout<<"- "<<VSNAME<<" not found"<<endl;
00106 if(!cs)
00107 cout<<"- "<<CSNAME<<" not found"<<endl;
00108 cout<<"Some data are not located where you speficied - do you want to re-input ?\nType 1 if yes, else another key "<<endl;
00109 cin>>input;
00110 if(!input){
00111 cout<<"Default import launched:"<<endl;
00112 _datadir=FileReader::getdatadirasstring();
00113 importYieldCurve();
00114 importVolSurface();
00115 importCreditCurve();
00116 cout<<"--> Default data imported\n"<<endl;
00117 setMarketData();
00118 return true;
00119 }
00120 }
00121 }
00122 _datadir=dataDir;
00123 importYieldCurve(YCNAME);
00124 importVolSurface(VSNAME,spot);
00125 importCreditCurve(CSNAME);
00126 cout<<"--> Personal data imported\n"<<endl;
00127 setMarketData();
00128 return true;
00129 }
00130
00131
00132 Natural importData::displayFileFormatsMenu(){
00133 cout<<"\nHELP ON FILE FORMATS\n"<<endl;
00134 cout<<"YIELD CURVE\nA csv file as follows, with on each line a rate,a maturity in years,and a rate type (Cash or Swap)."<<endl;
00135 cout<<"For example a possible first line could be:\n"<<endl;
00136 cout<<"0.041,0.25,Cash <-- Meaning the Cash rate of maturity 3 months is 4.1 percent\n\n"<<endl;
00137
00138 cout<<"VOLATILITIES\nAs csv file as follows:"<<endl;
00139 cout<<"- The first 2 lines specify the number of maturities quoted and the number of strikes at these:\n"<<endl;
00140 cout<<"maturities , 1\nstrikes , 2\n"<<endl;
00141 cout<<"- Then a matrix of which the first column has the maturities in DD-MM-YYYY, "<<endl;
00142 cout<<"and then alternatively prices at the given strike and the option type (c/p). For example:\n"<<endl;
00143 cout<<"maturities / strikes , 2395.95 , type, 2545.69 , type"<<endl;
00144 cout<<"17-3-2006 , 693.1431 , c , 561.4132 , c\n"<<endl;
00145 cout<<"<-- Meaning that for maturity 17-3-2006, the 2395.95 call is quoted 693.1431, and the 2545.69 is 561.4132\n\n"<<endl;
00146
00147 cout<<"CREDIT SPREADS\nA csv file as follows, with on each line a spread,a maturity in years,and a spread type (Abs or Rel)."<<endl;
00148 cout<<"For example a possible first line could be:\n"<<endl;
00149 cout<<"0.0014,2,Rel <-- Meaning the realtive credit spread rate of maturity 2 years is 14 bps\n\n"<<endl;
00150
00151 cout<<"Now that you know, would you like to import your own data or use the stale one provided ? "<<endl;
00152 cout<<"Type 1 to input your data files location, else another key to get the default inputs:"<<endl;
00153 Natural userWantsToImport;
00154 cin>>userWantsToImport;
00155 return userWantsToImport;
00156 }
00157