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

mainconvertiblebond.cpp

Go to the documentation of this file.
00001 #include "..\PartJ\convertiblebond.h"
00002 #include "..\common\utils.h"
00003 using namespace std;
00004 
00005 bool mainconvertiblebond(void) {
00006         bool result = true;
00007         Date today;
00008         Date todayPlusTwentyYears;
00009 
00010         // using atmel price from 
00011         // http://www.math.nyu.edu/fellows_fin_math/laud/fall2005/project/CVT_DESC.gif
00012         // volatility as of 20-dec-2005 - see
00013         // http://www.ivolatility.com/options.j?ticker=atml
00014         today.setDateToToday();
00015         todayPlusTwentyYears = today.plus(20 * 365, Days);
00016         Real atmelPrice = 2.23;
00017         Real atmelVol = 0.44;
00018         Real atmelFace = 1000;
00019         Real riskfreeRate = 0.05;
00020         Real atmelSpread = 0.02;
00021         Real atmelConversion = 55.932;
00022         Real atmelCallPrice = 50.0;
00023         Real atmelPutPrice = 20.0;
00024         Natural nSteps = 10;
00025 
00026         asset *Atmel = new asset(atmelPrice, atmelVol);
00027         riskybond *AtmelBond = new riskybond(today, 
00028                 todayPlusTwentyYears, 
00029                 atmelFace, 
00030                 ACT_365, 
00031                 yieldCurve(riskfreeRate),
00032                 creditCurve(riskfreeRate, atmelSpread));
00033 
00034         // test: ATMELNOCALLPUT
00035         //  check values in this test and next test verified using
00036         //  CBcalculator.xls
00037         convertiblebond *AtmelConvertible1 = 
00038                 new convertiblebond(*Atmel, *AtmelBond, atmelConversion, nSteps);
00039         cout << "atmel convertible - no call put: " << AtmelConvertible1 << endl;
00040         Real p = AtmelConvertible1->fairvalue();
00041         Real pExp = 42.7113;
00042         if (!realsEqual(p, pExp, 0.0001)) {
00043                 cout << "convertible, non-callable, non-puttable price: " << p << endl;
00044                 cout << "expecting: " << pExp << endl;
00045                 return false;
00046         }
00047 
00048         // test: ATMELCALLONLY
00049         convertiblebond *AtmelConvertible2 =
00050                 new convertiblebond(*Atmel, *AtmelBond, atmelConversion, 
00051                 nSteps, atmelCallPrice);
00052         cout << "atmel convertible - call only: " << AtmelConvertible2 << endl;
00053         p = AtmelConvertible2->fairvalue();
00054         pExp = 25.7722;
00055         if (!realsEqual(p, pExp, 0.0001)) {
00056                 cout << "convertible, callable price: " << p << endl;
00057                 cout << "expecting: " << pExp << endl;
00058                 return false;
00059         }
00060 
00061         cout << "callable @ 50" << endl
00062                 << "So,convertibleprice,paritydelta,irdelta,paritygamma" << endl;
00063         for (Natural i = 0; i <= 100; i++) {
00064                 Real p = 1 + i*.1;
00065                 Atmel->setPrice(p);
00066                 convertiblebond *cb =
00067                         new convertiblebond(*Atmel, *AtmelBond, atmelConversion, 100, atmelCallPrice);
00068                 cout << p << ","
00069                         << cb->fairvalue() << ","
00070                         << cb->parityDelta() << ","
00071                         << cb->rho() << ","
00072                         << cb->parityGamma() << endl;
00073                 delete cb;
00074         }
00075 
00076         cout << "not callable" << endl
00077                 << "So,convertibleprice,paritydelta,irdelta,paritygamma" << endl;
00078         for (Natural i = 0; i <= 100; i++) {
00079                 Real p = 1 + i*.1;
00080                 Atmel->setPrice(p);
00081                 convertiblebond *cb =
00082                         new convertiblebond(*Atmel, *AtmelBond, atmelConversion, 100);
00083                 cout << p << ","
00084                         << cb->fairvalue() << ","
00085                         << cb->parityDelta() << ","
00086                         << cb->rho() << ","
00087                         << cb->parityGamma() << endl;
00088                 delete cb;
00089         }
00090 
00091 
00092         // test: HULLEX21.1
00093         Date todayPlusNineMonths = today.plus(9, Months);
00094         Real XYZFace = 100;
00095         Real XYZPrice = 50;
00096         Real XYZVol = 0.3;
00097         Real XYZConversion = 2;
00098         Real XYZCallPrice = 113;
00099         Real XYZSpread = 0;
00100         nSteps = 3;
00101         asset *XYZ = new asset(XYZPrice, XYZVol);
00102         riskybond *XYZBond = new riskybond(today, 
00103                 todayPlusNineMonths, 
00104                 XYZFace, 
00105                 ACT_365, 
00106                 yieldCurve(riskfreeRate), 
00107                 creditCurve(riskfreeRate, XYZSpread));
00108         convertiblebond *XYZConvertible = 
00109                 new convertiblebond(*XYZ, *XYZBond, XYZConversion, nSteps, XYZCallPrice);
00110         cout << "XYZ convertible - call only: " << XYZConvertible << endl;
00111         
00112         p = XYZConvertible->fairvalue();
00113         // value in Hull is 106.93 but we are not modelling the possibility of
00114         //  default so the price is slightly higher
00115         pExp = 107.578; 
00116         if (!realsEqual(p, pExp, 0.001)) {
00117                 cout << "XYZ convertible, callable price: " << p << endl;
00118                 cout << "expecting: " << pExp << endl;
00119                 return false;
00120         }
00121 
00122         delete Atmel;
00123         delete AtmelBond;
00124         delete XYZ;
00125         delete XYZBond;
00126         delete AtmelConvertible1;
00127         delete AtmelConvertible2;
00128         delete XYZConvertible;
00129         return result;
00130 }

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