QuantLib 0.3.7
Getting started
Reference manual
|
BermudanSwaption.cppThis is an example of using the QuantLib short rate models.
#include <ql/quantlib.hpp>
using namespace QuantLib;
Size numRows = 5;
Size numCols = 5;
Integer swapLenghts[] = {
1, 2, 3, 4, 5};
Volatility swaptionVols[] = {
14.90, 13.40, 12.28, 11.89, 11.48,
12.90, 12.01, 11.46, 11.08, 10.40,
11.49, 11.12, 10.70, 10.10, 9.57,
10.47, 10.21, 9.80, 9.51, 12.70,
10.00, 9.50, 9.00, 12.30, 11.60};
void calibrateModel( const boost::shared_ptr<ShortRateModel>& model,
const std::vector<boost::shared_ptr<CalibrationHelper> >&
helpers,
Real lambda) {
Simplex om(lambda, 1e-9);
om.setEndCriteria(EndCriteria(10000, 1e-7));
model->calibrate(helpers, om);
#if defined(QL_PATCH_DARWIN)
return;
#endif
for ( Size i=0; i<numRows; i++) {
Size j = numCols - i -1;
Size k = i*numCols + j;
Real npv = helpers[i]->modelValue();
Volatility implied = helpers[i]->impliedVolatility(npv, 1e-4,
1000, 0.05, 0.50)*100.0;
Volatility diff = implied - swaptionVols[k];
std::cout << i+1 << "x" << swapLenghts[j]
<< ": model " << DecimalFormatter::toString(implied,2,5)
<< ", market " << DecimalFormatter::toString(swaptionVols[k],2,5)
<< " (" << DecimalFormatter::toString(diff,2,5) << ")\n";
}
}
int main( int, char* [])
{
try {
QL_IO_INIT
Date todaysDate(15, February, 2002);
Calendar calendar = TARGET();
Date settlementDate(19, February, 2002);
boost::shared_ptr<Quote> flatRate( new SimpleQuote(0.04875825));
boost::shared_ptr<FlatForward> myTermStructure( new
FlatForward(todaysDate, settlementDate,
RelinkableHandle<Quote>(flatRate)));
RelinkableHandle<TermStructure> rhTermStructure;
rhTermStructure.linkTo(myTermStructure);
Frequency fixedLegFrequency = Annual;
BusinessDayConvention fixedLegConvention = Unadjusted;
BusinessDayConvention floatingLegConvention = ModifiedFollowing;
DayCounter fixedLegDayCounter = Thirty360(Thirty360::European);
Frequency floatingLegFrequency = Semiannual;
bool payFixedRate = true;
Integer fixingDays = 2;
Rate dummyFixedRate = 0.03;
boost::shared_ptr<Xibor> indexSixMonths( new
Euribor(6, Months, rhTermStructure));
Date startDate = calendar.advance(settlementDate,1,Years,
floatingLegConvention);
Date maturity = calendar.advance(startDate,5,Years,
floatingLegConvention);
Schedule fixedSchedule(calendar,startDate,maturity,
fixedLegFrequency,fixedLegConvention);
Schedule floatSchedule(calendar,startDate,maturity,
floatingLegFrequency,floatingLegConvention);
boost::shared_ptr<SimpleSwap> swap( new SimpleSwap(
payFixedRate, 1000.0,
fixedSchedule, dummyFixedRate, fixedLegDayCounter,
floatSchedule, indexSixMonths, fixingDays, 0.0,
rhTermStructure));
Rate fixedATMRate = swap->fairRate();
Rate fixedOTMRate = fixedATMRate * 1.2;
Rate fixedITMRate = fixedATMRate * 0.8;
boost::shared_ptr<SimpleSwap> atmSwap( new SimpleSwap(
payFixedRate, 1000.0,
fixedSchedule, fixedATMRate, fixedLegDayCounter,
floatSchedule, indexSixMonths, fixingDays, 0.0,
rhTermStructure));
boost::shared_ptr<SimpleSwap> otmSwap( new SimpleSwap(
payFixedRate, 1000.0,
fixedSchedule, fixedOTMRate, fixedLegDayCounter,
floatSchedule, indexSixMonths, fixingDays, 0.0,
rhTermStructure));
boost::shared_ptr<SimpleSwap> itmSwap( new SimpleSwap(
payFixedRate, 1000.0,
fixedSchedule, fixedITMRate, fixedLegDayCounter,
floatSchedule, indexSixMonths, fixingDays, 0.0,
rhTermStructure));
std::vector<Period> swaptionMaturities;
swaptionMaturities.push_back(Period(1, Years));
swaptionMaturities.push_back(Period(2, Years));
swaptionMaturities.push_back(Period(3, Years));
swaptionMaturities.push_back(Period(4, Years));
swaptionMaturities.push_back(Period(5, Years));
std::vector<boost::shared_ptr<CalibrationHelper> > swaptions;
std::list<Time> times;
Size i;
for (i=0; i<numRows; i++) {
Size j = numCols - i -1;
Size k = i*numCols + j;
boost::shared_ptr<Quote> vol( new
SimpleQuote(swaptionVols[k]*0.01));
swaptions.push_back(boost::shared_ptr<CalibrationHelper>( new
SwaptionHelper(swaptionMaturities[i],
Period(swapLenghts[j], Years),
RelinkableHandle<Quote>(vol),
indexSixMonths,
rhTermStructure)));
swaptions.back()->addTimesTo(times);
}
TimeGrid grid(times.begin(), times.end(), 30);
boost::shared_ptr<G2> modelG2( new G2(rhTermStructure));
boost::shared_ptr<HullWhite> modelHW( new HullWhite(rhTermStructure));
#define ALSO_NUMERICAL_MODELS
#ifdef ALSO_NUMERICAL_MODELS
boost::shared_ptr<HullWhite> modelHW2( new HullWhite(rhTermStructure));
boost::shared_ptr<BlackKarasinski> modelBK( new
BlackKarasinski(rhTermStructure));
#endif
std::cout << "G2 (analytic formulae) calibration" << std::endl;
for (i=0; i<swaptions.size(); i++)
swaptions[i]->setPricingEngine(boost::shared_ptr<PricingEngine>(
new G2SwaptionEngine(modelG2, 6.0, 16)));
calibrateModel(modelG2, swaptions, 0.05);
std::cout << "calibrated to:\n"
<< "a = " << modelG2->params()[0] << ", "
<< "sigma = " << modelG2->params()[1] << "\n"
<< "b = " << modelG2->params()[2] << ", "
<< "eta = " << modelG2->params()[3] << "\n"
<< "rho = " << modelG2->params()[4]
<< std::endl << std::endl;
std::cout << "Hull-White (analytic formulae) calibration" << std::endl;
for (i=0; i<swaptions.size(); i++)
swaptions[i]->setPricingEngine(boost::shared_ptr<PricingEngine>(
new JamshidianSwaptionEngine(modelHW)));
calibrateModel(modelHW, swaptions, 0.05);
std::cout << "calibrated to:\n"
<< "a = " << modelHW->params()[0] << ", "
<< "sigma = " << modelHW->params()[1]
<< std::endl << std::endl;
#ifdef ALSO_NUMERICAL_MODELS
std::cout << "Hull-White (numerical) calibration" << std::endl;
for (i=0; i<swaptions.size(); i++)
swaptions[i]->setPricingEngine(boost::shared_ptr<PricingEngine>(
new TreeSwaptionEngine(modelHW2,grid)));
calibrateModel(modelHW2, swaptions, 0.05);
std::cout << "calibrated to:\n"
<< "a = " << modelHW2->params()[0] << ", "
<< "sigma = " << modelHW2->params()[1]
<< std::endl << std::endl;
std::cout << "Black-Karasinski (numerical) calibration" << std::endl;
for (i=0; i<swaptions.size(); i++)
swaptions[i]->setPricingEngine(boost::shared_ptr<PricingEngine>(
new TreeSwaptionEngine(modelBK,grid)));
calibrateModel(modelBK, swaptions, 0.05);
std::cout << "calibrated to:\n"
<< "a = " << modelBK->params()[0] << ", "
<< "sigma = " << modelBK->params()[1]
<< std::endl << std::endl;
#endif
std::cout << "Payer bermudan swaption "
<< "struck at " << RateFormatter::toString(fixedATMRate)
<< " (ATM)" << std::endl;
std::vector<Date> bermudanDates;
const std::vector<boost::shared_ptr<CashFlow> >& leg =
swap->fixedLeg();
for (i=0; i<leg.size(); i++) {
boost::shared_ptr<Coupon> coupon =
boost::dynamic_pointer_cast<Coupon>(leg[i]);
bermudanDates.push_back(coupon->accrualStartDate());
}
boost::shared_ptr<Exercise> bermudaExercise( new
BermudanExercise(bermudanDates));
Swaption bermudanSwaption(atmSwap, bermudaExercise,
rhTermStructure, boost::shared_ptr<PricingEngine>( new
TreeSwaptionEngine(modelHW, 100)));
bermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>( new
G2SwaptionEngine(modelG2, 6.0, 16)));
bermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
new TreeSwaptionEngine(modelHW, 100)));
std::cout << "HW: " << bermudanSwaption.NPV() << std::endl;
#ifdef ALSO_NUMERICAL_MODELS
bermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>( new
TreeSwaptionEngine(modelHW2, 100)));
std::cout << "HW (num): " << bermudanSwaption.NPV() << std::endl;
bermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>( new
TreeSwaptionEngine(modelBK, 100)));
std::cout << "BK: " << bermudanSwaption.NPV() << std::endl;
#endif
std::cout << "Payer bermudan swaption "
<< "struck at " << RateFormatter::toString(fixedOTMRate)
<< " (OTM)" << std::endl;
Swaption otmBermudanSwaption(otmSwap, bermudaExercise, rhTermStructure,
boost::shared_ptr<PricingEngine>( new
TreeSwaptionEngine(modelHW, 100)));
otmBermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
new G2SwaptionEngine(modelG2, 6.0, 16)));
otmBermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
new TreeSwaptionEngine(modelHW, 100)));
std::cout << "HW: " << otmBermudanSwaption.NPV() << std::endl;
#ifdef ALSO_NUMERICAL_MODELS
otmBermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
new TreeSwaptionEngine(modelHW2, 100)));
std::cout << "HW (num): " << otmBermudanSwaption.NPV() << std::endl;
otmBermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
new TreeSwaptionEngine(modelBK, 100)));
std::cout << "BK: " << otmBermudanSwaption.NPV() << std::endl;
#endif
std::cout << "Payer bermudan swaption "
<< "struck at " << RateFormatter::toString(fixedITMRate)
<< " (ITM)" << std::endl;
Swaption itmBermudanSwaption(itmSwap, bermudaExercise, rhTermStructure,
boost::shared_ptr<PricingEngine>( new
TreeSwaptionEngine(modelHW, 100)));
itmBermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
new G2SwaptionEngine(modelG2, 6.0, 16)));
itmBermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
new TreeSwaptionEngine(modelHW, 100)));
std::cout << "HW: " << itmBermudanSwaption.NPV() << std::endl;
#ifdef ALSO_NUMERICAL_MODELS
itmBermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
new TreeSwaptionEngine(modelHW2, 100)));
std::cout << "HW (num): " << itmBermudanSwaption.NPV() << std::endl;
itmBermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
new TreeSwaptionEngine(modelBK, 100)));
std::cout << "BK: " << itmBermudanSwaption.NPV() << std::endl;
#endif
return 0;
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
return 1;
} catch (...) {
std::cout << "unknown error" << std::endl;
return 1;
}
}
00001
00019 #include <ql/quantlib.hpp>
00020
00021 using namespace QuantLib;
00022
00023
00024
00025 Size numRows = 5;
00026 Size numCols = 5;
00027
00028 Integer swapLenghts[] = {
00029 1, 2, 3, 4, 5};
00030 Volatility swaptionVols[] = {
00031 14.90, 13.40, 12.28, 11.89, 11.48,
00032 12.90, 12.01, 11.46, 11.08, 10.40,
00033 11.49, 11.12, 10.70, 10.10, 9.57,
00034 10.47, 10.21, 9.80, 9.51, 12.70,
00035 10.00, 9.50, 9.00, 12.30, 11.60};
00036
00037 void calibrateModel( const boost::shared_ptr<ShortRateModel>& model,
00038 const std::vector<boost::shared_ptr<CalibrationHelper> >&
00039 helpers,
00040 Real lambda) {
00041
00042 Simplex om(lambda, 1e-9);
00043 om.setEndCriteria(EndCriteria(10000, 1e-7));
00044 model->calibrate(helpers, om);
00045
00046 #if defined(QL_PATCH_DARWIN)
00047
00048 return;
00049 #endif
00050
00051
00052 for ( Size i=0; i<numRows; i++) {
00053 Size j = numCols - i -1;
00054 Size k = i*numCols + j;
00055 Real npv = helpers[i]->modelValue();
00056 Volatility implied = helpers[i]->impliedVolatility(npv, 1e-4,
00057 1000, 0.05, 0.50)*100.0;
00058 Volatility diff = implied - swaptionVols[k];
00059
00060 std::cout << i+1 << "x" << swapLenghts[j]
00061 << ": model " << DecimalFormatter::toString(implied,2,5)
00062 << ", market " << DecimalFormatter::toString(swaptionVols[k],2,5)
00063 << " (" << DecimalFormatter::toString(diff,2,5) << ")\n";
00064 }
00065 }
00066
00067 int main( int, char* [])
00068 {
00069 try {
00070 QL_IO_INIT
00071
00072 Date todaysDate(15, February, 2002);
00073 Calendar calendar = TARGET();
00074 Date settlementDate(19, February, 2002);
00075
00076
00077 boost::shared_ptr<Quote> flatRate( new SimpleQuote(0.04875825));
00078 boost::shared_ptr<FlatForward> myTermStructure( new
00079 FlatForward(todaysDate, settlementDate,
00080 RelinkableHandle<Quote>(flatRate)));
00081 RelinkableHandle<TermStructure> rhTermStructure;
00082 rhTermStructure.linkTo(myTermStructure);
00083
00084
00085 Frequency fixedLegFrequency = Annual;
00086 BusinessDayConvention fixedLegConvention = Unadjusted;
00087 BusinessDayConvention floatingLegConvention = ModifiedFollowing;
00088 DayCounter fixedLegDayCounter = Thirty360(Thirty360::European);
00089 Frequency floatingLegFrequency = Semiannual;
00090 bool payFixedRate = true;
00091 Integer fixingDays = 2;
00092 Rate dummyFixedRate = 0.03;
00093 boost::shared_ptr<Xibor> indexSixMonths( new
00094 Euribor(6, Months, rhTermStructure));
00095
00096 Date startDate = calendar.advance(settlementDate,1,Years,
00097 floatingLegConvention);
00098 Date maturity = calendar.advance(startDate,5,Years,
00099 floatingLegConvention);
00100 Schedule fixedSchedule(calendar,startDate,maturity,
00101 fixedLegFrequency,fixedLegConvention);
00102 Schedule floatSchedule(calendar,startDate,maturity,
00103 floatingLegFrequency,floatingLegConvention);
00104 boost::shared_ptr<SimpleSwap> swap( new SimpleSwap(
00105 payFixedRate, 1000.0,
00106 fixedSchedule, dummyFixedRate, fixedLegDayCounter,
00107 floatSchedule, indexSixMonths, fixingDays, 0.0,
00108 rhTermStructure));
00109 Rate fixedATMRate = swap->fairRate();
00110 Rate fixedOTMRate = fixedATMRate * 1.2;
00111 Rate fixedITMRate = fixedATMRate * 0.8;
00112
00113 boost::shared_ptr<SimpleSwap> atmSwap( new SimpleSwap(
00114 payFixedRate, 1000.0,
00115 fixedSchedule, fixedATMRate, fixedLegDayCounter,
00116 floatSchedule, indexSixMonths, fixingDays, 0.0,
00117 rhTermStructure));
00118 boost::shared_ptr<SimpleSwap> otmSwap( new SimpleSwap(
00119 payFixedRate, 1000.0,
00120 fixedSchedule, fixedOTMRate, fixedLegDayCounter,
00121 floatSchedule, indexSixMonths, fixingDays, 0.0,
00122 rhTermStructure));
00123 boost::shared_ptr<SimpleSwap> itmSwap( new SimpleSwap(
00124 payFixedRate, 1000.0,
00125 fixedSchedule, fixedITMRate, fixedLegDayCounter,
00126 floatSchedule, indexSixMonths, fixingDays, 0.0,
00127 rhTermStructure));
00128
00129
00130 std::vector<Period> swaptionMaturities;
00131 swaptionMaturities.push_back(Period(1, Years));
00132 swaptionMaturities.push_back(Period(2, Years));
00133 swaptionMaturities.push_back(Period(3, Years));
00134 swaptionMaturities.push_back(Period(4, Years));
00135 swaptionMaturities.push_back(Period(5, Years));
00136
00137 std::vector<boost::shared_ptr<CalibrationHelper> > swaptions;
00138
00139
00140 std::list<Time> times;
00141
00142 Size i;
00143 for (i=0; i<numRows; i++) {
00144 Size j = numCols - i -1;
00145 Size k = i*numCols + j;
00146 boost::shared_ptr<Quote> vol( new
00147 SimpleQuote(swaptionVols[k]*0.01));
00148 swaptions.push_back(boost::shared_ptr<CalibrationHelper>( new
00149 SwaptionHelper(swaptionMaturities[i],
00150 Period(swapLenghts[j], Years),
00151 RelinkableHandle<Quote>(vol),
00152 indexSixMonths,
00153 rhTermStructure)));
00154 swaptions.back()->addTimesTo(times);
00155 }
00156
00157
00158 TimeGrid grid(times.begin(), times.end(), 30);
00159
00160
00161
00162 boost::shared_ptr<G2> modelG2( new G2(rhTermStructure));
00163 boost::shared_ptr<HullWhite> modelHW( new HullWhite(rhTermStructure));
00164
00165 #define ALSO_NUMERICAL_MODELS
00166
00167 #ifdef ALSO_NUMERICAL_MODELS
00168 boost::shared_ptr<HullWhite> modelHW2( new HullWhite(rhTermStructure));
00169 boost::shared_ptr<BlackKarasinski> modelBK( new
00170 BlackKarasinski(rhTermStructure));
00171 #endif
00172
00173
00174
00175
00176 std::cout << "G2 (analytic formulae) calibration" << std::endl;
00177 for (i=0; i<swaptions.size(); i++)
00178 swaptions[i]->setPricingEngine(boost::shared_ptr<PricingEngine>(
00179 new G2SwaptionEngine(modelG2, 6.0, 16)));
00180
00181 calibrateModel(modelG2, swaptions, 0.05);
00182 std::cout << "calibrated to:\n"
00183 << "a = " << modelG2->params()[0] << ", "
00184 << "sigma = " << modelG2->params()[1] << "\n"
00185 << "b = " << modelG2->params()[2] << ", "
00186 << "eta = " << modelG2->params()[3] << "\n"
00187 << "rho = " << modelG2->params()[4]
00188 << std::endl << std::endl;
00189
00190
00191
00192 std::cout << "Hull-White (analytic formulae) calibration" << std::endl;
00193 for (i=0; i<swaptions.size(); i++)
00194 swaptions[i]->setPricingEngine(boost::shared_ptr<PricingEngine>(
00195 new JamshidianSwaptionEngine(modelHW)));
00196
00197 calibrateModel(modelHW, swaptions, 0.05);
00198 std::cout << "calibrated to:\n"
00199 << "a = " << modelHW->params()[0] << ", "
00200 << "sigma = " << modelHW->params()[1]
00201 << std::endl << std::endl;
00202
00203 #ifdef ALSO_NUMERICAL_MODELS
00204 std::cout << "Hull-White (numerical) calibration" << std::endl;
00205 for (i=0; i<swaptions.size(); i++)
00206 swaptions[i]->setPricingEngine(boost::shared_ptr<PricingEngine>(
00207 new TreeSwaptionEngine(modelHW2,grid)));
00208
00209 calibrateModel(modelHW2, swaptions, 0.05);
00210 std::cout << "calibrated to:\n"
00211 << "a = " << modelHW2->params()[0] << ", "
00212 << "sigma = " << modelHW2->params()[1]
00213 << std::endl << std::endl;
00214
00215
00216 std::cout << "Black-Karasinski (numerical) calibration" << std::endl;
00217 for (i=0; i<swaptions.size(); i++)
00218 swaptions[i]->setPricingEngine(boost::shared_ptr<PricingEngine>(
00219 new TreeSwaptionEngine(modelBK,grid)));
00220
00221 calibrateModel(modelBK, swaptions, 0.05);
00222 std::cout << "calibrated to:\n"
00223 << "a = " << modelBK->params()[0] << ", "
00224 << "sigma = " << modelBK->params()[1]
00225 << std::endl << std::endl;
00226 #endif
00227
00228
00229
00230
00231 std::cout << "Payer bermudan swaption "
00232 << "struck at " << RateFormatter::toString(fixedATMRate)
00233 << " (ATM)" << std::endl;
00234
00235 std::vector<Date> bermudanDates;
00236 const std::vector<boost::shared_ptr<CashFlow> >& leg =
00237 swap->fixedLeg();
00238 for (i=0; i<leg.size(); i++) {
00239 boost::shared_ptr<Coupon> coupon =
00240 boost::dynamic_pointer_cast<Coupon>(leg[i]);
00241 bermudanDates.push_back(coupon->accrualStartDate());
00242 }
00243
00244 boost::shared_ptr<Exercise> bermudaExercise( new
00245 BermudanExercise(bermudanDates));
00246
00247 Swaption bermudanSwaption(atmSwap, bermudaExercise,
00248 rhTermStructure, boost::shared_ptr<PricingEngine>( new
00249 TreeSwaptionEngine(modelHW, 100)));
00250
00251
00252
00253
00254 bermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>( new
00255 G2SwaptionEngine(modelG2, 6.0, 16)));
00256
00257
00258 bermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
00259 new TreeSwaptionEngine(modelHW, 100)));
00260 std::cout << "HW: " << bermudanSwaption.NPV() << std::endl;
00261
00262 #ifdef ALSO_NUMERICAL_MODELS
00263 bermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>( new
00264 TreeSwaptionEngine(modelHW2, 100)));
00265 std::cout << "HW (num): " << bermudanSwaption.NPV() << std::endl;
00266
00267 bermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>( new
00268 TreeSwaptionEngine(modelBK, 100)));
00269 std::cout << "BK: " << bermudanSwaption.NPV() << std::endl;
00270 #endif
00271
00272
00273
00274
00275 std::cout << "Payer bermudan swaption "
00276 << "struck at " << RateFormatter::toString(fixedOTMRate)
00277 << " (OTM)" << std::endl;
00278
00279 Swaption otmBermudanSwaption(otmSwap, bermudaExercise, rhTermStructure,
00280 boost::shared_ptr<PricingEngine>( new
00281 TreeSwaptionEngine(modelHW, 100)));
00282
00283
00284 otmBermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
00285 new G2SwaptionEngine(modelG2, 6.0, 16)));
00286
00287
00288 otmBermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
00289 new TreeSwaptionEngine(modelHW, 100)));
00290 std::cout << "HW: " << otmBermudanSwaption.NPV() << std::endl;
00291
00292 #ifdef ALSO_NUMERICAL_MODELS
00293 otmBermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
00294 new TreeSwaptionEngine(modelHW2, 100)));
00295 std::cout << "HW (num): " << otmBermudanSwaption.NPV() << std::endl;
00296
00297 otmBermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
00298 new TreeSwaptionEngine(modelBK, 100)));
00299 std::cout << "BK: " << otmBermudanSwaption.NPV() << std::endl;
00300 #endif
00301
00302
00303
00304
00305 std::cout << "Payer bermudan swaption "
00306 << "struck at " << RateFormatter::toString(fixedITMRate)
00307 << " (ITM)" << std::endl;
00308
00309 Swaption itmBermudanSwaption(itmSwap, bermudaExercise, rhTermStructure,
00310 boost::shared_ptr<PricingEngine>( new
00311 TreeSwaptionEngine(modelHW, 100)));
00312
00313
00314 itmBermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
00315 new G2SwaptionEngine(modelG2, 6.0, 16)));
00316
00317
00318 itmBermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
00319 new TreeSwaptionEngine(modelHW, 100)));
00320 std::cout << "HW: " << itmBermudanSwaption.NPV() << std::endl;
00321
00322 #ifdef ALSO_NUMERICAL_MODELS
00323 itmBermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
00324 new TreeSwaptionEngine(modelHW2, 100)));
00325 std::cout << "HW (num): " << itmBermudanSwaption.NPV() << std::endl;
00326
00327 itmBermudanSwaption.setPricingEngine(boost::shared_ptr<PricingEngine>(
00328 new TreeSwaptionEngine(modelBK, 100)));
00329 std::cout << "BK: " << itmBermudanSwaption.NPV() << std::endl;
00330 #endif
00331
00332 return 0;
00333 } catch (std::exception& e) {
00334 std::cout << e.what() << std::endl;
00335 return 1;
00336 } catch (...) {
00337 std::cout << "unknown error" << std::endl;
00338 return 1;
00339 }
00340 }
00341
|