Posted by
animesh on
Sep 03, 2010; 10:02pm
URL: http://quantlib.414.s1.nabble.com/Cliquet-Pricing-tp7689.html
I have taken the code from test-suite. Basically some form Cliquet
and some from Heston. I wanted to pricing Cliquet option using
Heston Process. If I simply use CliquetOption and setPricingEngine
to AnalyticHestonEngine then it's giving ABORT SIGNAL. Can anyone
help me with this??
Thanks in advance....
'The important lines for quick look are
boost::shared_ptr<HestonModel> model(new
HestonModel(process));
boost::shared_ptr<PricingEngine> engine(
new
AnalyticHestonEngine(model, 64));
.......
......
....... (Model calibration)......
......
CliquetOption option1(payoff, exercise, reset);
option1.setPricingEngine(engine);
Real ff = option1.NPV()
(error thrown just as NPV is called!)
Code pasted
SavedSettings backup;
Date settlementDate(5, July, 2002);
Settings::instance().evaluationDate() = settlementDate;
DayCounter dayCounter = Actual365Fixed();
Calendar calendar = TARGET();
Integer t[] = { 13, 41, 75, 165, 256, 345, 524, 703 };
Rate r[] = {
0.0357,0.0349,0.0341,0.0355,0.0359,0.0368,0.0386,0.0401 };
std::vector<Date> dates;
std::vector<Rate> rates;
dates.push_back(settlementDate);
rates.push_back(0.0357);
Size i;
for (i = 0; i < 8; ++i) {
dates.push_back(settlementDate + t[i]);
rates.push_back(r[i]);
}
// FLOATING_POINT_EXCEPTION
Handle<YieldTermStructure> riskFreeTS(
boost::shared_ptr<YieldTermStructure>(
new ZeroCurve(dates, rates, dayCounter)));
Handle<YieldTermStructure> dividendTS(
flatRate(settlementDate,
0.0, dayCounter));
Volatility v[] =
{ 0.6625,0.4875,0.4204,0.3667,0.3431,0.3267,0.3121,0.3121,
0.6007,0.4543,0.3967,0.3511,0.3279,0.3154,0.2984,0.2921,
0.5084,0.4221,0.3718,0.3327,0.3155,0.3027,0.2919,0.2889,
0.4541,0.3869,0.3492,0.3149,0.2963,0.2926,0.2819,0.2800,
0.4060,0.3607,0.3330,0.2999,0.2887,0.2811,0.2751,0.2775,
0.3726,0.3396,0.3108,0.2781,0.2788,0.2722,0.2661,0.2686,
0.3550,0.3277,0.3012,0.2781,0.2781,0.2661,0.2661,0.2681,
0.3428,0.3209,0.2958,0.2740,0.2688,0.2627,0.2580,0.2620,
0.3302,0.3062,0.2799,0.2631,0.2573,0.2533,0.2504,0.2544,
0.3343,0.2959,0.2705,0.2540,0.2504,0.2464,0.2448,0.2462,
0.3460,0.2845,0.2624,0.2463,0.2425,0.2385,0.2373,0.2422,
0.3857,0.2860,0.2578,0.2399,0.2357,0.2327,0.2312,0.2351,
0.3976,0.2860,0.2607,0.2356,0.2297,0.2268,0.2241,0.2320 };
Handle<Quote> s0(boost::shared_ptr<Quote>(new
SimpleQuote(4468.17)));
Real strike[] = { 3400,3600,3800,4000,4200,4400,
4500,4600,4800,5000,5200,5400,5600 };
std::vector<boost::shared_ptr<CalibrationHelper> >
options;
for (Size s = 0; s < 13; ++s) {
for (Size m = 0; m < 8; ++m) {
Handle<Quote> vol(boost::shared_ptr<Quote>(
new
SimpleQuote(v[s*8+m])));
Period maturity((int)((t[m]+3)/7.), Weeks); // round to
weeks
options.push_back(boost::shared_ptr<CalibrationHelper>(
new HestonModelHelper(maturity, calendar,
s0->value(), strike[s], vol,
riskFreeTS, dividendTS,
CalibrationHelper::ImpliedVolError)));
}
}
const Real v0=0.1;
const Real kappa=1.0;
const Real theta=0.1;
const Real sigma=0.5;
const Real rho=-0.5;
boost::shared_ptr<HestonProcess> process(new
HestonProcess(
riskFreeTS, dividendTS, s0, v0, kappa, theta, sigma, rho));
boost::shared_ptr<HestonModel> model(new
HestonModel(process));
boost::shared_ptr<PricingEngine> engine(
new
AnalyticHestonEngine(model, 64));
for (i = 0; i < options.size(); ++i)
options[i]->setPricingEngine(engine);
LevenbergMarquardt om(1e-8, 1e-8, 1e-8);
model->calibrate(options, om, EndCriteria(400, 40, 1.0e-8,
1.0e-8, 1.0e-8));
Date today = Date::todaysDate();
DayCounter dc = Actual360();
boost::shared_ptr<SimpleQuote> spot(new
SimpleQuote(60.0));
boost::shared_ptr<SimpleQuote> qRate(new
SimpleQuote(0.04));
boost::shared_ptr<YieldTermStructure> qTS =
flatRate(today, qRate, dc);
boost::shared_ptr<SimpleQuote> rRate(new
SimpleQuote(0.08));
boost::shared_ptr<YieldTermStructure> rTS =
flatRate(today, rRate, dc);
boost::shared_ptr<SimpleQuote> vol(new SimpleQuote(0.30));
boost::shared_ptr<BlackVolTermStructure> volTS =
flatVol(today, vol, dc);
std::vector<Date> reset;
reset.push_back(today + 90);
Date maturity = today + 360;
Option::Type type = Option::Call;
Real moneyness = 1.1;
boost::shared_ptr<PercentageStrikePayoff> payoff(
new
PercentageStrikePayoff(type, moneyness));
boost::shared_ptr<EuropeanExercise> exercise(
new
EuropeanExercise(maturity));
CliquetOption option1(payoff, exercise, reset);
option1.setPricingEngine(engine);
Real ff = option1.NPV()
--
Regards,
Animesh Saxena
(http://quantanalysis.wordpress.com)
Ph: (+91)9920098221
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:
Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users