Posted by
japari on
Sep 29, 2009; 11:38am
URL: http://quantlib.414.s1.nabble.com/Fwd-Re-CreditDefaultSwap-throws-RuntimeError-tp8028.html
Was there a reason why we are not forcing the refDate to be before the val date
in the CDS engines?
Regards
Pepe
----- Forwarded message from Jose Aparicio-Navarro <
[hidden email]> -----
Date: Tue, 29 Sep 2009 12:47:51 +0200
From: Jose Aparicio-Navarro <
[hidden email]>
Reply-To: Jose Aparicio-Navarro <
[hidden email]>
Subject: Re: [Quantlib-users] CreditDefaultSwap throws RuntimeError
To:
[hidden email]
Quoting
[hidden email]:
>
> hazard_rate_structure=ql.FlatHazardRate(
> ql.QuoteHandle(ql.SimpleQuote(hazard_rate)), # quote handle
> ql.ActualActual() # day counter
> )
>
> issuer=ql.Issuer(
> ql.RelinkableDefaultProbabilityTermStructureHandle(
> hazard_rate_structure
> ), # relinkable handle to default prob term struct
> recovery_rate # recovery rate
> )
>
> yield_term_structure=ql.FlatForward(
> 2, # settlement days
> calendar, # calendar
> rate, # rate
> ql.ActualActual() # day counter
> )
>
The FlatHR is (I assuming what the Py binds are doing) constructing a relative
date curve linked to the instance date with a 0 settlement delay.
The Yield term structure is doing the same with a 2 days settlement delay.
The engine requests DFs and Probabilities on coupon days and default days.
16th June 06 is a thursday, next coupon goes over a weekend, your TS jumps the
weekend, the prob not. The coupon is on the following Tuesday. The the engine is
asking on a past date, is my guess this is the first date this situation takes
place.
I was surprised it crashed on the 15th so I coded it and in C++ it crashes on
the 16th (Friday). It might be your output buffer not being flushed.
Date date(1,January, 2006);
date = TARGET().adjust(date, Following);
Date maturity(20,December, 2014);
Rate spread = 0.05;
Real recoveryRate = 0.4;
Rate hazardRate = 0.2;
Rate yieldRate = 0.03;
Schedule schedCds =
MakeSchedule().from(date)
.to(maturity)
.withFrequency(Quarterly)
.withConvention(Following)
.withTerminationDateConvention(Following)
.withCalendar(TARGET())
.withRule(DateGeneration::TwentiethIMM)
;
CreditDefaultSwap our_cds(Protection::Buyer,
1., spread, schedCds,
Following,
Actual360()
);
Handle<DefaultProbabilityTermStructure> probability(
boost::shared_ptr<DefaultProbabilityTermStructure>(new
FlatHazardRate(0, // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
TARGET(),
hazardRate, ActualActual())));
Handle<YieldTermStructure> yield_term_structure(
boost::shared_ptr<FlatForward>(
new FlatForward(0, //2, //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
TARGET(), yieldRate,
ActualActual())));
boost::shared_ptr<CreditDefaultSwap::engine>
HRengine_tst(boost::shared_ptr<MidPointCdsEngine>
(new MidPointCdsEngine(probability,
recoveryRate, yield_term_structure, true
)));
our_cds.setPricingEngine(HRengine_tst);
while(date < Date(24, September, 2009)) {
Settings::instance().evaluationDate() = date;
cout << date << " , " << our_cds.NPV() << endl;
date = TARGET().advance(date, 1, Days);
}
Regards
Pepe
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users----- End forwarded message -----
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users