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

productsCreation.cpp

Go to the documentation of this file.
00001 #include ".\productscreation.h"
00002 
00003 
00004 bool productsCreationMenu(marketData data)
00005 {
00006         cout<<"\n**************************************"<<endl;
00007         cout<<"****** Products Creation Module ******"<<endl;
00008         cout<<"**************************************\n"<<endl;
00009 
00010         bool replay=true;
00011         while (replay){
00012                 cout<<"\nThe available products are (type their number to use them, or another key to get back) :"<<endl;
00013                 cout<<"1 - Black Scholes Call/Put"<<endl;
00014                 cout<<"2 - Strategies combining Calls and Puts"<<endl;
00015                 cout<<"3 - Exotics options on single underlying"<<endl;
00016                 cout<<"4 - Treasury/Risky bond"<<endl;
00017                 cout<<"5 - Vanilla interest rate swap"<<endl;
00018                 cout<<"6 - Rainbow Options"<<endl;
00019                 cout<<"7 - Convertible bond"<<endl;
00020                 Natural choice=0;
00021                 cin>>choice;
00022                 switch(choice){
00023                         case 1:
00024                                 inputBSOption(data);
00025                                 break;
00026                         case 2:
00027                                 inputOptionStrategy(data);
00028                                 break;
00029                         case 3:
00030                                 inputExoticOptionOnSingleAsset(data);
00031                                 break;
00032                         case 4:
00033                                 inputBond(data);
00034                                 break;
00035                         case 5:
00036                                 inputVanillaSwap(data);
00037                                 break;
00038                         case 6:
00039                                 inputRainbowOption(data);
00040                                 break;
00041                         case 7:
00042                                 inputConvertibleBond(data);
00043                                 break;
00044                         default:
00045                                 replay=false;
00046                                 break;
00047                 }
00048         }
00049 }
00050 
00051 
00052 BlackScholes * inputBSOption(marketData data)
00053 {
00054         bool useData;
00055         Natural useMarketData;
00056         cout<<"\n**************************************"<<endl;
00057         cout<<"*** Input one Black Scholes option ***"<<endl;
00058         cout<<"**************************************\n"<<endl;
00059         cout<<"\nWould you like to use the market data?\nType 1 if yes, else any other key"<<endl;
00060         cin>>useMarketData;
00061         useData=(useMarketData==1);
00062         TypeOptionBS type;
00063         Real spot,rate,vol,K,T;
00064         bool isnotCorP=true;
00065         char callOrPut;
00066         while(isnotCorP){
00067                 cout<<"\nDo you want to add a call or a put ? Type c or C for a call, and p or P"<<endl;
00068                 cin>>callOrPut;
00069                 isnotCorP=!(callOrPut=='c'||callOrPut=='C'||callOrPut=='p'||callOrPut=='P');
00070                 if(isnotCorP)
00071                         cout<<"Your entry did not seem valid"<<endl;
00072         }
00073         if(callOrPut=='c'||callOrPut=='C')
00074                 type=Call;
00075         else // as we are sure he entered c, C, p or P
00076                 type=Put;
00077         cout<<"What is the spot level of your underlying?"<<endl;
00078         cin>>spot;
00079         cout<<"What is the strike of your option?"<<endl;
00080         cin>>K;
00081         cout<<"What is the maturity in years of your option?"<<endl;
00082         cin>>T;
00083         if(useData){
00084                 Date d;
00085                 d.setDateToToday ();
00086                 rate=data.yieldcurve.spotRate(T);
00087                 vol=data.vols.volatility(K,d.plusDays((Integer)(365*T)));
00088         }
00089         else{
00090                 cout<<"What is the rate to maturity you want to use? (in absolute value)"<<endl;
00091                 cin>>rate;
00092                 cout<<"What is the volatility to maturity you want to use? (in absolute value)"<<endl;
00093                 cin>>vol;
00094         }
00095         BlackScholes* res=new BlackScholes(spot,vol,true,rate,K,T,type);
00096         cout<<"You have succesfully created a "<<K<<" "<<outputCallPut(callOrPut)<<" with maturity "<<T<<", vol "<<vol<<", rate "<<rate<<"; while the spot is at "<<spot<<endl;
00097         cout<<"Its characteristics are as follows:"<<endl;
00098         cout<<"- Price: "<<res->getPrice()<<endl;
00099         cout<<"- Delta: "<<res->getDelta()<<endl;
00100         cout<<"- Gamma: "<<res->getGamma()<<endl;
00101         cout<<"- Vega:  "<<res->getVega()<<endl;
00102         cout<<"- Theta: "<<res->getTheta()<<endl;
00103         cout<<"- Rho:   "<<res->getRho()<<"\n"<<endl;
00104 
00105         return res;
00106 }
00107 
00108 string outputCallPut(char c){
00109         string res;
00110         if(c=='c' || c=='C')
00111                 res="Call";
00112         else if(c=='p' || c=='P')
00113                         res="Put";
00114         else
00115                 res = "";
00116         return res;
00117 }
00118 
00119 OptionStrategy inputOptionStrategy(marketData data)
00120 {
00121         OptionStrategy strategy;
00122         cout<<"\n**************************************"<<endl;
00123         cout<<"****** Input an Option Strategy ******"<<endl;
00124         cout<<"**************************************\n"<<endl;
00125         cout<<"\nAn option strategy is a set of Black Sholes options, you will create them separately"<<endl;
00126         bool replay=true,addOneMoreOption,addBS;
00127         Natural addOption,addABS,replayInput;
00128         Real amount;
00129         Natural count =1;
00130         while(replay){
00131                 addOneMoreOption=true;
00132                 while(addOneMoreOption){
00133                         cout<<"Add the option number "<<count<<":"<<endl;
00134                         cout<<"Do you want add a single Call/Put or somehting else? Type 1 for Call/Put or another key for something else"<<endl;
00135                         cin>>addABS;
00136                         addBS=(addABS==1);
00137                         if(addBS){
00138                                 BlackScholes* toAdd=inputBSOption(data);
00139                                 cout<<"How many of these would you like to add?"<<endl;
00140                                 cin>>amount;
00141                                 strategy.addOneBlackScholesObject(toAdd,amount);
00142                         }
00143                         else
00144                                 inputSpecificOptionStrategy(data,strategy);
00145                         cout<<"\n**************************************"<<endl;
00146                         cout<<"****** Input an Option Strategy ******"<<endl;
00147                         cout<<"**************************************\n"<<endl;
00148                         cout<<"\nWould you like to add one more? Type 1 for yes, else another key"<<endl;
00149                         cin>>addOption;
00150                         addOneMoreOption=(addOption==1);
00151                         count++;
00152                 }
00153                 cout<<"The creation process is now over. Given what you added, the charateristics of the strategy are:"<<endl;
00154                 cout<<"- Price: "<<strategy.returnPrice()<<endl;
00155                 cout<<"- Delta: "<<strategy.getGlobalDelta()<<endl;
00156                 cout<<"- Gamma: "<<strategy.getGlobalGamma()<<endl;
00157                 cout<<"- Vega:  "<<strategy.getGlobalVega()<<endl;
00158                 cout<<"- Theta: "<<strategy.getGlobalTheta()<<endl;
00159                 cout<<"- Rho:   "<<strategy.getGlobalRho()<<"\n"<<endl;
00160                 cout<<"Your strategy is now made of:\n"<<strategy<<endl;
00161                 cout<<"Are you satisfied with your risk or would you like to add more options (adding negative is deleting)? Type 1 to add more or another key to stop here"<<endl;
00162                 cin>>replayInput;
00163                 replay=(replayInput==1);
00164         }
00165 
00166         return strategy;
00167 }
00168 
00169 void inputSpecificOptionStrategy(marketData data,OptionStrategy& strategy)
00170 {
00171         bool incorrectChoice=true,useMarketData;
00172         Natural choice=0,useData;
00173         cout<<"\n**************************************"<<endl;
00174         cout<<" Add a specific option for a strategy "<<endl;
00175         cout<<"**************************************\n"<<endl;
00176         cout<<"\nWould you like to use the market data?\nType 1 if yes, else any other key"<<endl;
00177         cin>>useData;
00178         useMarketData=(useData==1);
00179         while(incorrectChoice){
00180                 cout<<"What sort of option do you want to add? Press:"<<endl;
00181                 cout<<"1 - for a ButterflySpread"<<endl;
00182                 cout<<"2 - for a CallSpread"<<endl;
00183                 cout<<"3 - for a PutSpread"<<endl;
00184                 cout<<"4 - for a RatioCallSpread"<<endl;
00185                 cout<<"5 - for a Straddle"<<endl;
00186                 cout<<"6 - for a Strangle"<<endl;
00187                 cin>>choice;
00188                 incorrectChoice=((choice<=0)||(choice>6));
00189                 if(incorrectChoice)
00190                         cout<<"Your entry did not seem valid"<<endl;
00191         }
00192         switch (choice){
00193                 case 1:
00194                         inputButterflySpread(data,strategy,useMarketData);
00195                         break;
00196                 case 2:
00197                         inputCallSpread(data,strategy,useMarketData);
00198                         break;
00199                 case 3:
00200                         inputPutSpread(data,strategy,useMarketData);
00201                         break;
00202                 case 4:
00203                         inputRatioCallSpread(data,strategy,useMarketData);
00204                         break;
00205                 case 5:
00206                         inputStraddle(data,strategy,useMarketData);
00207                         break;
00208                 case 6:
00209                         inputStrangle(data,strategy,useMarketData);
00210                         break;
00211         }
00212 }
00213 
00214 void inputButterflySpread(marketData data,OptionStrategy& strategy,bool useMarketData){
00215         cout<<"\n**************************************"<<endl;
00216         cout<<" Add a Butterfly Spread to a strategy "<<endl;
00217         cout<<"**************************************\n"<<endl;
00218         Real spot,K1,K2,K3,T,rate,vol1,vol2,vol3,amount;
00219         Natural symetric;
00220         cout<<"Do you want a symetric butterfly? Type 1 for yes, else another key"<<endl;
00221         cin>>symetric;
00222         cout<<"What is the spot level of your underlying?"<<endl;
00223         cin>>spot;
00224         cout<<"What is the lowest strike of your option?"<<endl;
00225         cin>>K1;
00226         cout<<"What is the highest strike of your option?"<<endl;
00227         cin>>K2;
00228         if(symetric==1)
00229                 K3=(K1+K2)/2.0;
00230         else{
00231                 cout<<"What is the mid strike of the option ?"<<endl;
00232                 cin>>K3;
00233                 while(K3>K2 ||K3<K1){
00234                         cout<<"The mid strike should be between K1 and K2 - can you please re enter it?"<<endl;
00235                         cin>>K3;
00236                 }
00237         }
00238         cout<<"What is the maturity in years of your option?"<<endl;
00239         cin>>T;
00240         if(useMarketData){
00241                 Date d;
00242                 d.setDateToToday ();
00243                 rate=data.yieldcurve.spotRate(T);
00244                 vol1=data.vols.volatility(K1,d.plusDays((Integer)(365*T)));
00245                 vol2=data.vols.volatility(K2,d.plusDays((Integer)(365*T)));
00246                 vol3=data.vols.volatility(K3,d.plusDays((Integer)(365*T)));
00247         }
00248         else{
00249                 cout<<"What is the rate to maturity you want to use? (in absolute value)"<<endl;
00250                 cin>>rate;
00251                 cout<<"At strike K_low, what is the volatility to maturity you want to use? (in absolute value)"<<endl;
00252                 cin>>vol1;
00253                 cout<<"At strike K_high, what is the volatility to maturity you want to use? (in absolute value)"<<endl;
00254                 cin>>vol2;
00255                 cout<<"At strike K_mid, what is the volatility to maturity you want to use? (in absolute value)"<<endl;
00256                 cin>>vol3;
00257         }
00258         cout<<"How many of these would you like to add?"<<endl;
00259         cin>>amount;
00260         strategy.addLongButterflySpread(spot,vol1,true,vol2,true,vol3,true,rate,K1,K2,K3,T,amount);
00261 }
00262 
00263 void inputCallSpread(marketData data,OptionStrategy& strategy,bool useMarketData){
00264         cout<<"\n**************************************"<<endl;
00265         cout<<"*** Add a CallSpread to a strategy ***"<<endl;
00266         cout<<"**************************************\n"<<endl;
00267         Real spot,K1,K2,T,rate,vol1,vol2,amount;
00268         cout<<"What is the spot level of your underlying?"<<endl;
00269         cin>>spot;
00270         cout<<"What is the lowest strike of your option?"<<endl;
00271         cin>>K1;
00272         cout<<"What is the highest strike of your option?"<<endl;
00273         cin>>K2;
00274         cout<<"What is the maturity in years of your option?"<<endl;
00275         cin>>T;
00276         if(useMarketData){
00277                 Date d;
00278                 d.setDateToToday ();
00279                 rate=data.yieldcurve.spotRate(T);
00280                 vol1=data.vols.volatility(K1,d.plusDays((Integer)(365*T)));
00281                 vol2=data.vols.volatility(K2,d.plusDays((Integer)(365*T)));
00282         }
00283         else{
00284                 cout<<"What is the rate to maturity you want to use? (in absolute value)"<<endl;
00285                 cin>>rate;
00286                 cout<<"At strike K_low, what is the volatility to maturity you want to use? (in absolute value)"<<endl;
00287                 cin>>vol1;
00288                 cout<<"At strike K_high, what is the volatility to maturity you want to use? (in absolute value)"<<endl;
00289                 cin>>vol2;
00290         }
00291         cout<<"How many of these would you like to add?"<<endl;
00292         cin>>amount;
00293         strategy.addLongCallSpread(spot,vol1,true,vol2,true,rate,K1,K2,T,amount);
00294 }
00295 
00296 void inputPutSpread(marketData data,OptionStrategy& strategy,bool useMarketData){
00297         cout<<"\n**************************************"<<endl;
00298         cout<<"*** Add a Put Spread to a strategy ***"<<endl;
00299         cout<<"**************************************\n"<<endl;
00300         Real spot,K1,K2,T,rate,vol1,vol2,amount;
00301         cout<<"What is the spot level of your underlying?"<<endl;
00302         cin>>spot;
00303         cout<<"What is the lowest strike of your option?"<<endl;
00304         cin>>K1;
00305         cout<<"What is the highest strike of your option?"<<endl;
00306         cin>>K2;
00307         cout<<"What is the maturity in years of your option?"<<endl;
00308         cin>>T;
00309         if(useMarketData){
00310                 Date d;
00311                 d.setDateToToday ();
00312                 rate=data.yieldcurve.spotRate(T);
00313                 vol1=data.vols.volatility(K1,d.plusDays((Integer)(365*T)));
00314                 vol2=data.vols.volatility(K2,d.plusDays((Integer)(365*T)));
00315         }
00316         else{
00317                 cout<<"What is the rate to maturity you want to use? (in absolute value)"<<endl;
00318                 cin>>rate;
00319                 cout<<"At strike K_low, what is the volatility to maturity you want to use? (in absolute value)"<<endl;
00320                 cin>>vol1;
00321                 cout<<"At strike K_high, what is the volatility to maturity you want to use? (in absolute value)"<<endl;
00322                 cin>>vol2;
00323         }
00324         cout<<"How many of these would you like to add?"<<endl;
00325         cin>>amount;
00326         strategy.addLongPutSpread(spot,vol1,true,vol2,true,rate,K1,K2,T,amount);
00327 }
00328 
00329 void inputRatioCallSpread(marketData data,OptionStrategy& strategy,bool useMarketData){
00330         cout<<"\n**************************************"<<endl;
00331         cout<<" Add a Ratio CallSpread to a strategy "<<endl;
00332         cout<<"**************************************\n"<<endl;
00333         Real spot,K1,K2,T,rate,vol1,vol2,amount;
00334         cout<<"What is the spot level of your underlying?"<<endl;
00335         cin>>spot;
00336         cout<<"What is the lowest strike of your option?"<<endl;
00337         cin>>K1;
00338         cout<<"What is the highest strike of your option?"<<endl;
00339         cin>>K2;
00340         cout<<"What is the maturity in years of your option?"<<endl;
00341         cin>>T;
00342         if(useMarketData){
00343                 Date d;
00344                 d.setDateToToday ();
00345                 rate=data.yieldcurve.spotRate(T);
00346                 vol1=data.vols.volatility(K1,d.plusDays((Integer)(365*T)));
00347                 vol2=data.vols.volatility(K2,d.plusDays((Integer)(365*T)));
00348         }
00349         else{
00350                 cout<<"What is the rate to maturity you want to use? (in absolute value)"<<endl;
00351                 cin>>rate;
00352                 cout<<"At strike K_low, what is the volatility to maturity you want to use? (in absolute value)"<<endl;
00353                 cin>>vol1;
00354                 cout<<"At strike K_high, what is the volatility to maturity you want to use? (in absolute value)"<<endl;
00355                 cin>>vol2;
00356         }
00357         cout<<"How many of these would you like to add?"<<endl;
00358         cin>>amount;
00359         strategy.addLongRatioCallSpread(spot,vol1,true,vol2,true,rate,K1,K2,T,amount);
00360 }
00361 
00362 void inputStraddle(marketData data,OptionStrategy& strategy,bool useMarketData){
00363         cout<<"\n**************************************"<<endl;
00364         cout<<"**** Add a Straddle to a strategy ****"<<endl;
00365         cout<<"**************************************\n"<<endl;
00366         Real spot,K1,T,rate,vol1,amount;
00367         cout<<"What is the spot level of your underlying?"<<endl;
00368         cin>>spot;
00369         cout<<"What is the strike of your option?"<<endl;
00370         cin>>K1;
00371         cout<<"What is the maturity in years of your option?"<<endl;
00372         cin>>T;
00373         if(useMarketData){
00374                 Date d;
00375                 d.setDateToToday ();
00376                 rate=data.yieldcurve.spotRate(T);
00377                 vol1=data.vols.volatility(K1,d.plusDays((Integer)(365*T)));
00378         }
00379         else{
00380                 cout<<"What is the rate to maturity you want to use? (in absolute value)"<<endl;
00381                 cin>>rate;
00382                 cout<<"What is the volatility to maturity you want to use? (in absolute value)"<<endl;
00383                 cin>>vol1;
00384         }
00385         cout<<"How many of these would you like to add?"<<endl;
00386         cin>>amount;
00387         strategy.addLongStraddle(spot,vol1,true,rate,K1,T,amount);
00388 }
00389 
00390 void inputStrangle(marketData data,OptionStrategy& strategy,bool useMarketData){
00391         cout<<"\n**************************************"<<endl;
00392         cout<<"**** Add a Strangle to a strategy ****"<<endl;
00393         cout<<"**************************************\n"<<endl;
00394         Real spot,K1,K2,T,rate,vol1,vol2,amount;
00395         cout<<"What is the spot level of your underlying?"<<endl;
00396         cin>>spot;
00397         cout<<"What is the lowest strike of your option?"<<endl;
00398         cin>>K1;
00399         cout<<"What is the highest strike of your option?"<<endl;
00400         cin>>K2;
00401         cout<<"What is the maturity in years of your option?"<<endl;
00402         cin>>T;
00403         if(useMarketData){
00404                 Date d;
00405                 d.setDateToToday ();
00406                 rate=data.yieldcurve.spotRate(T);
00407                 vol1=data.vols.volatility(K1,d.plusDays((Integer)(365*T)));
00408                 vol2=data.vols.volatility(K2,d.plusDays((Integer)(365*T)));
00409         }
00410         else{
00411                 cout<<"What is the rate to maturity you want to use? (in absolute value)"<<endl;
00412                 cin>>rate;
00413                 cout<<"At strike K_low, what is the volatility to maturity you want to use? (in absolute value)"<<endl;
00414                 cin>>vol1;
00415                 cout<<"At strike K_high, what is the volatility to maturity you want to use? (in absolute value)"<<endl;
00416                 cin>>vol2;
00417         }
00418         cout<<"How many of these would you like to add?"<<endl;
00419         cin>>amount;
00420         strategy.addLongStrangle(spot,vol1,true,vol2,true,rate,K1,K2,T,amount);
00421 }
00422 
00423 
00424 Exotics* inputExoticOptionOnSingleAsset(marketData& data){
00425         bool import,flatData;
00426         Real spot,K,T,vol,rate,K2;
00427         LongNatural asianDates;
00428         yieldCurve* yc;
00429         volsurface* vs;
00430 
00431         cout<<"\n**************************************"<<endl;
00432         cout<<"**** Input an Exotic option (M-C) ****"<<endl;
00433         cout<<"**************************************\n"<<endl;
00434 
00435         cout<<"\nWhat is the spot level of your underlying?"<<endl;
00436         cin>>spot;
00437         cout<<"What is the maturity in years of your option?"<<endl;
00438         cin>>T;
00439 
00440         cout<<"These options are often path dependant: would you like to re-import some data?\nType 1 to re-import, else any other key"<<endl;
00441         cin>>import;
00442         if(import){
00443                 importData tempImport;
00444                 tempImport.runUserDefinedInterface();
00445                 data=tempImport.getData ();
00446         }
00447         else{
00448                 cout<<"The data was not changed, would you like to input flat volatility and yield curves?\nType 1 if yes, else the program will use the data imported earlier."<<endl;
00449                 cin>>flatData;
00450                 if(flatData){
00451                         cout<<"What is the flat rate you want to use? (in absolute value)"<<endl;
00452                         cin>>rate;
00453                         cout<<"What is the flat volatility you want to use? (in absolute value)"<<endl;
00454                         cin>>vol;
00455                 }
00456         }
00457         Natural choice;
00458         bool incorrectChoice=true;
00459         exoticsType type;
00460         while(incorrectChoice){
00461                 cout<<"\nWhat sort of option do you want to add? Press:"<<endl;
00462                 cout<<"1 - for an AsianCall (computation can be long)"<<endl;
00463                 cout<<"2 - for a AsianPut (computation can be long)"<<endl;
00464                 cout<<"3 - for a RevLookbackCall"<<endl;
00465                 cout<<"4 - for a RevLookbackPut"<<endl;
00466                 cout<<"5 - for a FlooredCliquet"<<endl;
00467                 cout<<"6 - for a CappedCliquet"<<endl;
00468                 cout<<"7 - for a CollaredCliquet"<<endl;
00469                 cout<<"8 - for a BarrierCall"<<endl;
00470                 cout<<"9 - for a BarrierPut"<<endl;
00471                 cin>>choice;
00472                 incorrectChoice=((choice<=0)||(choice>9));
00473                 if(incorrectChoice)
00474                         cout<<"Your entry did not seem valid"<<endl;
00475         }
00476         type=choiceToType(choice);
00477         if (type==CollaredCliquet){ //collared are capped and floored
00478                 cout<<"What is the first strike?"<<endl;
00479                 cin>>K;
00480                 cout<<"What is the second strike?"<<endl;
00481                 cin>>K2;
00482         }
00483         else{
00484                 cout<<"What is the strike of the option?"<<endl;
00485                 cin>>K; 
00486         }
00487         cout<<"The Monte-Carlo Price on several dates can take several minutes...\nHow many dates should be looked at in the payoff?"<<endl;
00488         cin>>asianDates;
00489         asianDates=max(asianDates,(LongNatural)1);
00490 
00491         Exotics * res;
00492         if(flatData){
00493                 yc=new yieldCurve(rate);
00494                 vs=new volsurface(vol);
00495                 res = new Exotics(type,yc,vs,spot,K,T,asianDates,K2);
00496         }
00497         else{
00498                 yc=new yieldCurve(data.yieldcurve);
00499                 vs=new volsurface(data.vols);
00500                 res = new Exotics(type,yc,vs,spot,K,T,asianDates,K2);
00501         }
00502         
00503         cout<<"Its price is: ... being computed ...\n"<<res->getPrice()<<endl;
00504         bool replay=true;
00505         while (replay){
00506                 cout<<"Would you like to see its greeks? Given the time it took to get a price, up to you!\nPress the corresponding number to see it, else another key"<<endl;
00507                 cout<<"1 - Delta "<<endl;
00508                 cout<<"2 - Vega"<<endl;
00509                 cout<<"3 - Theta"<<endl;
00510                 cout<<"4 - Rho"<<"\n"<<endl;
00511                 cin>>choice;
00512                 switch (choice){
00513                         case 1:
00514                                 cout<<"Delta is "<<res->getDelta()<<endl;
00515                                 break;
00516                         case 2:
00517                                 cout<<"Vega is "<<res->getVega()<<endl;
00518                                 break;
00519                         case 3:
00520                                 cout<<"Theta is "<<res->getTheta()<<endl;
00521                                 break;
00522                         case 4:
00523                                 cout<<"Rho is "<<res->getRho()<<endl;
00524                                 break;
00525                         default:
00526                                 replay=false;
00527                                 break;
00528                 }
00529         }
00530         return res;
00531 }
00532 
00533 convertiblebond * inputConvertibleBond(marketData& data) 
00534 {
00535         cout<<"*****************************"<<endl;
00536         cout<<"*** Input one convertible ***"<<endl;
00537         cout<<"*****************************\n"<<endl;
00538 
00539         cout<<"First create an underlying risky bond"<<endl;
00540 
00541         // maturity in years
00542         Real theMaturity;
00543         cout << "\nWhat is the maturity of the bond in years? e.g. 20"<<endl;
00544         cin >> theMaturity;
00545 
00546         // face amount
00547         Real theFace;
00548         cout << "\nWhat is the  face amount? e.g. 1000"<<endl;
00549         cin >> theFace;
00550 
00551         // yield curve
00552         yieldCurve yc(data.yieldcurve);
00553         Natural yield;
00554         bool testyield=true;
00555         while (testyield){
00556                 cout << "Would you like to use market data for the yield curve? "<<endl;
00557                 cout << " 1- yes"<<endl;
00558                 cout << " 2- no"<<endl;
00559                 cin >> yield;
00560                 if (yield==1)
00561                         testyield=false;
00562                 else if (yield==2){
00563                         Real rate;
00564                         cout << "What is the flat rate (in percentage) you want to use? e.g. 5"<<endl;
00565                         cin >> rate;
00566                         yc = yieldCurve(rate/100);
00567                         testyield=false;
00568                 }
00569         }
00570 
00571         // credit curve
00572         creditCurve cc(data.creditcurve);
00573         Natural credit;
00574         bool testcredit=true;
00575         while (testcredit){
00576                 cout << "Would you like to use market data for the credit curve? "<<endl;
00577                 cout << " 1- yes"<<endl;
00578                 cout << " 2- no"<<endl;
00579                 cin >> credit;
00580                 if (credit==1)
00581                         testcredit=false;
00582                 else if (credit==2){
00583                         Real spread;
00584                         cout << "What is the credit spread (in percentage) you want to use? e.g. 2"<<endl;
00585                         cin >> spread;
00586                         spread/=100;
00587                         cc = creditCurve(yc, spread);
00588                         testcredit=false;
00589                 }
00590         }
00591 
00592         // asset current price
00593         Real thePrice;
00594         cout << "What is the spot level of your underlying? e.g. 2.23" <<endl;
00595         cin >> thePrice;
00596 
00597         // asset volatility
00598         Real theVol;
00599         cout << "What is the volatility of the underlying - e.g. 0.44" << endl;
00600         cin >> theVol;
00601 
00602         // conversion ratio
00603         Real theConversionRatio;
00604         cout << "What is the conversion ratio for the face amount - e.g. 55.932" << endl;
00605         cin >> theConversionRatio;
00606 
00607         // call price
00608         Real theCallPrice;
00609         cout << "What is the call price for the bond - input 9999 if not callable" << endl;
00610         cin >> theCallPrice;
00611 
00612         // put price
00613         Real thePutPrice;
00614         cout << "What is the put price for the bond - input 0 if not puttable" << endl;
00615         cin >> thePutPrice;
00616 
00617         // number of steps
00618         Natural theSteps;
00619         cout << "How many steps to use in binomial tree - e.g. 10" << endl;
00620         cin >> theSteps;
00621 
00622         Date today;
00623         today.setDateToToday();
00624         Date todayPlusMaturity = today.plusDays((Integer)(365 * theMaturity));
00625 
00626         asset *theStock =
00627                 new asset(thePrice, theVol);
00628         riskybond *theRiskyBond =
00629                 new riskybond(today, todayPlusMaturity, theFace, ACT_365, yc, cc);
00630         convertiblebond *theConvertible =
00631                 new convertiblebond(*theStock, *theRiskyBond, theConversionRatio, theSteps, theCallPrice, thePutPrice);
00632 
00633         cout << "characteristics of this convertible:" << endl
00634                 << theConvertible << endl;
00635 
00636         return theConvertible;
00637 }
00638 
00639 bond * inputBond(marketData& data)
00640 {
00641         Natural typeofbond;
00642         cout<<"**********************"<<endl;
00643         cout<<"*** Input one bond ***"<<endl;
00644         cout<<"***********************\n"<<endl;
00645         bool test=true;
00646         while(test){
00647                 cout << " 1- To create a treasury bond"<<endl;
00648                 cout << " 2- To create a risky bond"<<endl;
00649                 cin>>typeofbond;
00650                 if((typeofbond==1)||(typeofbond==2))
00651                         test = false;
00652         }
00653 
00654         Real dateofirstcoupon;
00655         cout << "\nWhat is the time of the first coupon in years? "<<endl;
00656         cin >> dateofirstcoupon;
00657 
00658 
00659         Real dateofmaturity;
00660         cout << "\nWhat is the maturity of the bond in years? "<<endl;
00661         cin >> dateofmaturity;
00662 
00663         Real coupon;
00664         cout << "\nWhat is the yearly coupon (in percentage of the faceamount)? "<<endl;
00665         cin >> coupon;
00666         coupon /= 100;
00667 
00668         Natural freq;
00669         bool testfreq=true;
00670         Frequency fr;
00671         while(testfreq){
00672                 cout << "\nWhat is the frequency of coupon deliveries? "<<endl;
00673                 cout << " 0- No frequency"<<endl;
00674                 cout << " 1- Once (ZeroCoupon)"<<endl;
00675                 cout << " 2- Annual"<<endl;
00676                 cout << " 3- Semiannual"<<endl;
00677                 cout << " 4- Every Four Months"<<endl;
00678                 cout << " 5- Quaterly"<<endl;
00679                 cout << " 6- Bimonthly"<<endl;
00680                 cout << " 7- Monthly"<<endl;
00681                 cin >> freq;
00682 
00683                 switch (freq) {
00684                         case 0:
00685                                 fr = NoFrequency;
00686                                 testfreq = false;
00687                                 break;
00688                         case 1:
00689                                 fr = Once;
00690                                 testfreq = false;
00691                                 break;
00692                         case 2:
00693                                 fr = Annual;
00694                                 testfreq = false;
00695                                 break;
00696                         case 3:
00697                                 fr = Semiannual;
00698                                 testfreq = false;
00699                                 break;
00700                         case 4:
00701                                 fr = EveryFourthMonth;
00702                                 testfreq = false;
00703                                 break;
00704                         case 5:
00705                                 fr = Quarterly;
00706                                 testfreq = false;
00707                                 break;
00708                         case 6:
00709                                 fr = Bimonthly;
00710                                 testfreq = false;
00711                                 break;
00712                         case 7:
00713                                 fr = Monthly;
00714                                 testfreq = false;
00715                                 break;
00716                         default:
00717                                 break;
00718                 }
00719         }
00720         
00721         Real faceamount;
00722         cout << "\nWhat is the  face amount? "<<endl;
00723         cin >> faceamount;
00724         
00725 
00726         Natural dcount;
00727         bool testdcount=true;
00728         DayCountConvention daycount;
00729         while(testdcount){
00730                 cout << "\nWhat is the Day Count Convention? "<<endl;
00731                 cout << " 0- ACT/365"<<endl;
00732                 cout << " 1- ACT/360"<<endl;
00733                 cout << " 2- Day30/365"<<endl;
00734                 cout << " 3- Day30/360"<<endl;
00735                 cin >> dcount;
00736 
00737                 switch (dcount) {
00738                         case 0:
00739                                 daycount = ACT_365;
00740                                 testdcount = false;
00741                                 break;
00742                         case 1:
00743                                 daycount = ACT_360;
00744                                 testdcount = false;
00745                                 break;
00746                         case 2:
00747                                 daycount = Day30_365;
00748                                 testdcount = false;
00749                                 break;
00750                         case 3:
00751                                 daycount = Day30_360;
00752                                 testdcount = false;
00753                                 break;
00754                         default:
00755                                 break;
00756                 }
00757         }
00758 
00759         Date today, maturity, firstcoupondate;
00760         today.setDateToToday ();
00761         firstcoupondate=today.plusDays((Integer)(365*dateofirstcoupon)); 
00762         maturity=today.plusDays((Integer)(365*dateofmaturity)); 
00763 
00764         bond* res;
00765 
00766         yieldCurve yc(data.yieldcurve);
00767         Natural yield;
00768         bool testyield=true;
00769         while (testyield){
00770                 cout << "Would you like to use market data for the yield curve? "<<endl;
00771                 cout << " 1- yes"<<endl;
00772                 cout << " 2- no"<<endl;
00773                 cin >> yield;
00774                 if (yield==1)
00775                         testyield=false;
00776                 else if (yield==2){
00777                         Real rate;
00778                         cout << "What is the flat rate (in percentage) you want to use? "<<endl;
00779                         cin >> rate;
00780                         yc = yieldCurve(rate/100);
00781                         testyield=false;
00782                 }
00783         }
00784         
00785         creditCurve cc(data.creditcurve);
00786         if(typeofbond==2){              
00787                 Natural credit;
00788                 bool testcredit=true;
00789                 while (testcredit){
00790                         cout << "Would you like to use market data for the credit curve? "<<endl;
00791                         cout << " 1- yes"<<endl;
00792                         cout << " 2- no"<<endl;
00793                         cin >> credit;
00794                         if (credit==1)
00795                                 testcredit=false;
00796                         else if (credit==2){
00797                                 Real spread;
00798                                 cout << "What is the credit spread (in percentage) you want to use? "<<endl;
00799                                 cin >> spread;
00800                                 spread/=100;
00801                                 cc = creditCurve(yc, spread);
00802                                 testcredit=false;
00803                         }
00804                 }
00805         }
00806 
00807 
00808         switch (typeofbond){
00809                 case 1:
00810                         res = new treasurybond(today, maturity, firstcoupondate, coupon, fr, faceamount, daycount, yc);
00811                         break;
00812                 case 2:
00813                         res = new riskybond(today, maturity, firstcoupondate, coupon, fr, faceamount, daycount, yc, cc);
00814                         break;
00815                 default:
00816                         break;
00817         }
00818 
00819         cout <<"*** characteristic of your bond ***"<<endl;
00820         cout << "fairvalue  " << res->fairvalue()  << endl;
00821         cout << "yield to maturity " << res->yieldToMaturity()  << endl;
00822         cout << "convexity  " << res->convexity()  << endl;
00823         cout << "duration  " << res->duration()  << endl;
00824         cout << endl;
00825 
00826 
00827         return res;
00828 
00829 }
00830 
00831 
00832 exoticsType choiceToType(Natural choice){
00833         exoticsType type;
00834         switch (choice){
00835                 case 1:
00836                         type=AsianCall;
00837                         break;
00838                 case 2:
00839                         type=AsianPut;
00840                         break;
00841                 case 3:
00842                         type=RevLookbackCall ;
00843                         break;
00844                 case 4:
00845                         type=RevLookbackPut;
00846                         break;
00847                 case 5:
00848                         type=FlooredCliquet;
00849                         break;
00850                 case 6:
00851                         type=CappedCliquet;
00852                         break;
00853                 case 7:
00854                         type=CollaredCliquet;
00855                         break;
00856                 case 8:
00857                         type=BarrierCall;
00858                         break;
00859                 case 9:
00860                         type=BarrierPut ;
00861                         break;
00862         }
00863         return type;
00864 }
00865 
00866 VanillaSwap* inputVanillaSwap(marketData data) {
00867         VanillaSwap* res;
00868         Date startDate=Date();
00869         Date endDate=Date();
00870         Real frequency,notional,amortizing,maturity,fixedRate;
00871         Natural payOrReceive,inputTodayDate,yield;
00872         bool payFixed,useTodayStart;
00873 
00874         cout<<"******************************"<<endl;
00875         cout<<"*** Input one vanilla swap ***"<<endl;
00876         cout<<"******************************\n"<<endl;
00877 
00878         cout<<"What is the notional of your contract?"<<endl;
00879         cin>>notional;
00880         cout<<"What is the amortizing size of your contract (0 if not)?"<<endl;
00881         cin>>amortizing;
00882         cout<<"What is the maturity of the contract in years (you can enter a floating number)?"<<endl;
00883         cin>>maturity;
00884         cout<<"What is the frequency of the contract (floating number, enter 2 for semi annual for example)?"<<endl;
00885         cin>>frequency;
00886         cout<<"What is the fixed rate of your contract?"<<endl;
00887         cin>>fixedRate;
00888         cout<<"Enter 1 if you receive the fixed rate or anything else if you pay it."<<endl;
00889         cin>>payOrReceive;
00890         payFixed=(payOrReceive!=1);
00891         cout<<"Enter 1 if you want to use today's date as start date or anything else if you want to enter it."<<endl;
00892         cin>>inputTodayDate;
00893         useTodayStart=(inputTodayDate==1);
00894         if (useTodayStart)
00895                 startDate.setDateToToday();
00896         else {
00897                 Natural daystart,monthstart,yearstart;
00898                 cout<<"Enter start month as a number between 1 and 12 :"<<endl;
00899                 cin>>monthstart;
00900                 cout<<"Enter start day as a number between 1 and 31 :"<<endl;
00901                 cin>>daystart;
00902                 cout<<"Enter start year as a number between 1900 and 2100 :"<<endl;
00903                 cin>>yearstart;
00904                 startDate=Date(daystart,monthstart,yearstart);
00905         }
00906 
00907         endDate=startDate.plusDays((Integer)(365.25*maturity));
00908 
00909         yieldCurve* yc=new yieldCurve();
00910         bool testyield=true;
00911         while (testyield){
00912                 cout << "Would you like to use market data for the yield curve? "<<endl;
00913                 cout << " 1- yes"<<endl;
00914                 cout << " 2- no"<<endl;
00915                 cin >> yield;
00916                 if (yield==1) {
00917                         testyield=false;
00918                         yc=&(data.yieldcurve);
00919                 }
00920                 else if (yield==2){
00921                         Real rate;
00922                         cout << "What is the flat rate you want to use (enter 0.05 for 5 percent)? "<<endl;
00923                         cin >> rate;
00924                         yc = new yieldCurve(rate);
00925                         testyield=false;
00926                 }
00927         }
00928 
00929 
00930         //Create cashflows
00931         SwapLeg swapLegReceived=SwapLeg(startDate,frequency,endDate,notional,amortizing,Following);
00932         SwapLeg swapLegPaid=SwapLeg(startDate,frequency,endDate,notional,amortizing,Following);
00933         CashFlow cashFlowFloat=CashFlow(swapLegReceived,data.yieldcurve);
00934         CashFlow cashFlowFixed=CashFlow(swapLegReceived,fixedRate);
00935 
00936         char* name1=new char[MAX_LETTERS];
00937         char* name2=new char[MAX_LETTERS];
00938         cout<<"Enter name of counterpart 1 :"<<endl;
00939         cin>>name1;
00940         cout<<"Enter name of counterpart 2 :"<<endl;
00941         cin>>name2;
00942         if (payFixed)
00943                 res=new VanillaSwap(cashFlowFloat,cashFlowFixed,name1,name2,yc);
00944         else
00945                 res=new VanillaSwap(cashFlowFixed,cashFlowFloat,name1,name2,yc);
00946 
00947         cout<<"\nThe value of the first leg is : "<<res->getFairValue1()<<endl;
00948         cout<<"\nThe value of the second leg is : "<<res->getFairValue2()<<endl;
00949         cout<<"\nThe price of your swap is then : "<<res->returnPrice()<<endl;
00950         cout<<"\nThe sensibility of your swap to interest rate is : "<<res->getRho()<<endl;
00951         cout<<"\nThe sensibility of your swap to time is : "<<res->getTheta()<<endl;
00952         cout<<"\n"<<endl;
00953         return res;
00954 }
00955 
00956 
00957 rainbowType chooseRainbowType(){
00958         rainbowType type;
00959         Natural choice;
00960         bool testInput=true;
00961         while(testInput){
00962                 cout<<"The available Rainbow OptionTypes are as follows, which one do you want?"<<endl;
00963                 cout<<"1 - SpreadOptionMax"<<endl;
00964                 cout<<"2 - AssetsBasketMax"<<endl;
00965                 cout<<"3 - BestOf2AssetsCash"<<endl;
00966                 cout<<"4 - WorstOf2AssetsCash"<<endl;
00967                 cout<<"5 - BetterOf2Assets"<<endl;
00968                 cout<<"6 - WorseOf2Assets"<<endl;
00969                 cout<<"7 - Max2AssetsCall"<<endl;
00970                 cout<<"8 - Min2AssetsCall"<<endl;
00971                 cout<<"9 - Max2AssetsPut"<<endl;
00972                 cout<<"10 - Min2AssetsPut"<<endl;
00973                 cin>>choice;
00974                 testInput=(choice<=0)||(choice>10);             
00975         }
00976         switch (choice){
00977                 case 1:
00978                         type=SpreadOptionMax;
00979                         break;
00980                 case 2:
00981                         type=AssetsBasketMax;
00982                         break;
00983                 case 3:
00984                         type=BestOf2AssetsCash;
00985                         break;
00986                 case 4:
00987                         type=WorstOf2AssetsCash;
00988                         break;
00989                 case 5:
00990                         type=BetterOf2Assets;
00991                         break;
00992                 case 6:
00993                         type=WorseOf2Assets;
00994                         break;
00995                 case 7:
00996                         type=Max2AssetsCall;
00997                         break;
00998                 case 8:
00999                         type=Min2AssetsCall;
01000                         break;
01001                 case 9:
01002                         type=Max2AssetsPut;
01003                         break;
01004                 case 10:
01005                         type=Min2AssetsPut;
01006                         break;
01007                 default:
01008                         type=BestOf2AssetsCash;
01009                         break;
01010         }
01011         return type;
01012 }
01013 
01014 priceType choosePricingType(){
01015         priceType type;
01016         Natural choice;
01017         bool testInput=true;
01018         while(testInput){
01019                 cout<<"Which pricing method do you want? Note that obviously MC is slow, but for Spread/Asset/WOCash it is the only way"<<endl;
01020                 cout<<"1 - Monte Carlo"<<endl;
01021                 cout<<"2 - Closed Form"<<endl;  
01022                 cin>>choice;
01023                 testInput=testInput=(choice!=1)&&(choice!=2);   
01024         }
01025         switch (choice){
01026                 case 1:
01027                         type=MonteCarlo;
01028                         break;
01029                 case 2:
01030                         type=ClosedForm;
01031                         break;
01032                 default:
01033                         type=ClosedForm;
01034                         break;                  
01035         }
01036         return type;
01037 }
01038 
01039 RainbowOption* inputRainbowOption(marketData data){
01040         cout<<"\n*********************************"<<endl;
01041         cout<<"*** Input one Rainbow option ***"<<endl;
01042         cout<<"********************************\n"<<endl;
01043         
01044         cout<<"What type of option would you like to add? \n[Only 2 assets type available in the menu -- see code]"<<endl;
01045         rainbowType type=chooseRainbowType();
01046         
01047         Date d;
01048         d.setDateToToday ();
01049         Real exp=0.0;
01050         while(exp<=0.0){
01051                 cout<<"What is the maturity of your option in years?"<<endl;
01052                 cin>>exp;
01053         }
01054         exp=max(exp,0.01);
01055         
01056         bool testData=true;
01057         Natural choice;
01058         cout<<"Do you want to use the market data (both vol curves will be indexed on SP at 2994...? Type 1 for Yes, else something else."<<endl;
01059         cin>>choice;
01060         
01061         yieldCurve yc=yieldCurve(data.yieldcurve);
01062         volsurface vs1=volsurface(data.vols);
01063         volsurface vs2=volsurface(data.vols);
01064         if(choice!=1){
01065                 Real rate,vol1,vol2;
01066                 cout<<"What flat rate do you want to use? In absolute value"<<endl;
01067                 cin>>rate;
01068                 yc=yieldCurve(max(rate,0));
01069                 cout<<"What 1st flat vol do you want to use? In absolute value"<<endl;
01070                 cin>>vol1;
01071                 vs1=volsurface(max(vol1,0));    
01072                 cout<<"What 2nd flat vol do you want to use? In absolute value"<<endl;
01073                 cin>>vol2;
01074                 vs1=volsurface(max(vol2,0));
01075         }
01076         valarray<volsurface> vols(2);
01077         vols[0]=vs1;
01078         vols[1]=vs2;
01079 //      RainbowOption(rainbowType type,Date start,Real exp,Real Strike,yieldCurve yc,valarray<volsurface> vols,Real Spot1,Real Spot2,Real Mult=RO_DEFAULT_MULTIPLIER,Real Correl12=0,Real weight1=0.5,Real weight2=0.5,bool outputMsgs=false);
01080         Real Strike,spot1,spot2,weight1,weight2;
01081         Real rho=-2,mult=1;
01082         cout<<"What is the strike of your option?"<<endl;
01083         cin>>Strike;
01084         cout<<"What is the spot of your 1st underlying?"<<endl;
01085         cin>>spot1;
01086         cout<<"What is the spot of your 2nd underlying?"<<endl;
01087         cin>>spot2;
01088         while (rho>1 ||rho<-1){
01089                 cout<<"What is the correlation between the assets?"<<endl;
01090                 cin>>rho;
01091         }
01092         cout<<"What is the weight you want to assign to your 1st underlying?"<<endl;
01093         cin>>weight1;
01094         cout<<"What is the weight you want to assign to your 2nd underlying?"<<endl;
01095         cin>>weight2;   
01096 
01097         RainbowOption * rb=new RainbowOption(type,d,exp,Strike,yc,vols,spot1,spot2,mult,rho,weight1,weight2,false);
01098         
01099         priceType pType=choosePricingType();
01100 
01101 
01102         cout<<"Its price is: "<<rb->getPrice(pType)<<endl;
01103 
01104         cout<<"Would you like to see its greeks? Type 1 if yes, else something else.\n[Note: If you chose Monte Carlo, it will take a few seconds]"<<endl;
01105         cin>>choice;
01106         if(choice==1){
01107                 cout<<"Delta 1: "<<rb->getPartialDelta(1,pType)<<endl;
01108                 cout<<"Delta 2: "<<rb->getPartialDelta(2,pType)<<endl;
01109                 cout<<"Gamma 1: "<<rb->getPartialGamma(1,pType)<<endl;
01110                 cout<<"Gamma 2: "<<rb->getPartialGamma(2,pType)<<endl;
01111                 cout<<"Vega 1: "<<rb->getPartialVega(1,pType)<<endl;
01112                 cout<<"Vega 2: "<<rb->getPartialVega(2,pType)<<endl;
01113                 cout<<"Correl risk : "<<rb->getCorrelRisk(pType)<<endl;
01114                 cout<<"Rho : "<<rb->getRho(pType)<<endl;
01115         }
01116         cout<<"\n"<<endl;
01117 
01118         return rb;
01119 }

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