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

maincreditcurves.cpp

Go to the documentation of this file.
00001 #include "..\PartF\creditCurve.h"
00002 #include "..\common\filereader.h"
00003 
00004 #include<iostream>
00005 #include<valarray>
00006 #include<time.h>
00007 using namespace std;
00008 
00009 bool maincreditcurve(void) {
00010         string datadir = FileReader::getdatadirasstring();
00011         string yieldCurveData = datadir + "yctest.csv";
00012         string creditSpreadData = datadir + "ccspread.csv";
00013         string creditSpreadMixedData = datadir + "ccspreadmix.csv";
00014         string creditSpreadZeroData = datadir + "cc0spread.csv";
00015         string aigSpreadData = datadir + "cdsw_aig.csv";
00016 
00017         bool result = true;
00018 
00019         // the underlying curve
00020         valarray<yieldPoint> *yieldCurveArray = 
00021                 FileReader::buildYieldPointArray(yieldCurveData);
00022 
00023         // zero (relative) spreads
00024         valarray<CreditSpreadPoint> *creditSpreadZeroArray =
00025                 FileReader::buildCreditSpreadPointArray(creditSpreadZeroData);
00026 
00027         // absolute "spreads"   
00028         valarray<CreditSpreadPoint> *creditSpreadArray =
00029                 FileReader::buildCreditSpreadPointArray(creditSpreadData);
00030 
00031         // mixed absolute and relative spreads (equivalent to absolute
00032         //  when combined with the underlying yield curve)
00033         valarray<CreditSpreadPoint> *creditSpreadMixedArray =
00034                 FileReader::buildCreditSpreadPointArray(creditSpreadMixedData);
00035 
00036         // AIG credit swap spreads from bloomberg
00037         valarray<CreditSpreadPoint> *aigSpreadArray =
00038                 FileReader::buildCreditSpreadPointArray(aigSpreadData);
00039 
00040         if ((yieldCurveArray == NULL) || 
00041                 (creditSpreadArray == NULL) ||
00042                 (creditSpreadZeroArray == NULL) ||
00043                 (creditSpreadMixedArray == NULL)) {
00044                 cout << "error reading in credit curve test files" << endl;
00045                 return false;
00046         }
00047 
00048         // test: NOSPREAD
00049         // construct a credit curve with no spread, verify that
00050         //  it returns the same values as the underlying yieldcurve
00051         creditCurve zeroSpreadCurve(*yieldCurveArray, 
00052                 *creditSpreadZeroArray, 
00053                 "zero-spread");
00054 
00055         // underlying yield curve which we can use for comparisons
00056         yieldCurve underlyingCurve(*yieldCurveArray, "test");
00057 
00058         if (zeroSpreadCurve != underlyingCurve) {
00059                 cout << "error: zero spread spot rates don't match the underlying" << endl;
00060                 return false;
00061         }
00062 
00063         // test: MIXEDSPREAD
00064         // now construct a curve with spreads, one with absolute and
00065         //  one with a mix of absolute and relative, but both are
00066         //  equivalent (given the same underlying yieldCurve)
00067         creditCurve absCurve(*yieldCurveArray, 
00068                 *creditSpreadArray, 
00069                 "abs-spreads");
00070 
00071         creditCurve mixedCurve(*yieldCurveArray, 
00072                 *creditSpreadMixedArray, 
00073                 "mixed-spreads");
00074         
00075         cout << "zeroSpreadCurve:\n" << zeroSpreadCurve << endl;
00076         cout << "absCurve:\n" << absCurve << endl;
00077         cout << "mixedCurve:\n" << mixedCurve << endl;
00078         if (absCurve != mixedCurve) {
00079                 cout << "error: absolute spread spot rates don't match mixed curve" << endl;
00080                 return false;
00081         }
00082 
00083         // test: CTORTEST
00084         creditCurve mixedCurve2(underlyingCurve, 
00085                 *creditSpreadMixedArray,
00086                 "mixed-spreads2");
00087         cout << "mixedCurve2:\n" << mixedCurve2 << endl;
00088         if (mixedCurve != mixedCurve2) {
00089                 cout << "error: constructing with yieldpoints gives different result"
00090                         << " than constructing with yieldcurve" << endl;
00091                 return false;
00092         }
00093 
00094         Real flatRate = 0.04;  Real flatSpread = 0.01;
00095         creditCurve flatCreditCurve(flatRate, 
00096                 flatSpread);
00097         yieldCurve flatYieldCurve(flatRate + flatSpread);
00098         
00099         cout << "flatCreditCurve:\n" << flatCreditCurve << endl;
00100         cout << "flatYieldCurve:\n" << flatYieldCurve << endl;
00101         if (flatYieldCurve != flatCreditCurve) {
00102                 cout << "error: flat 0.04 + 0.01 creditcurve gives different result"
00103                         << " than flat 0.05 yieldcurve" << endl;
00104                 return false;
00105         }
00106 
00107         // test: COPYCTORTEST
00108         creditCurve *pcreditCurve = new creditCurve(*yieldCurveArray, 
00109                 *creditSpreadArray, 
00110                 "abs-spreads");
00111         creditCurve copyCurve(*pcreditCurve);
00112         creditCurve equalCurve = copyCurve;
00113         delete pcreditCurve;
00114         cout << "copycurve: " << copyCurve << endl;
00115         cout << "equalcurve: " << equalCurve << endl;
00116 
00117         // test: HULLS21.3TEST
00118         flatRate = 0.05;  flatSpread = 0.0126;
00119         creditCurve flatCreditCurve2(flatRate, flatSpread);
00120         for (Natural i = 0; i <= 5; i++) {
00121                 cout << "prob of default at time " << i << "," 
00122                         << flatCreditCurve2.defaultProbability(i) << ","
00123                         << "survival prob," 
00124                         << flatCreditCurve2.survivalProbability(i) << endl;
00125         }
00126 
00127         // test: AIGTEST
00128         creditCurve aigCurve(flatYieldCurve, *aigSpreadArray, "aigcurve");
00129         cout << "aigCurve: " << aigCurve << endl;
00130         cout << "\n\n*** table of various values for aig curve" << endl;
00131         cout << "time,creditspread,hazardrate,survivalprob,cumdefaultprob,riskydiscount" << endl;
00132         for (Natural i = 0; i <= 10; i++) {
00133                 cout << i << ","
00134                         << aigCurve.creditSpread(i) << ","
00135                         << aigCurve.hazardRate(i) << ","
00136                         << aigCurve.survivalProbability(i) << ","
00137                         << aigCurve.cumulativeDefaultProbability(i) << ","
00138                         << aigCurve.riskyDiscountFactor(i) << endl;
00139         }
00140 
00141         return result;
00142 }

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