Hello everybody,
currently, I am writing my Bachelor thesis and I try to use QuantLib to generate realistic Credit Default Swaps. I am new to quantitative finance. That’s why I tried to rebuild an example which I found in “Options, Futures, and Other Derivatives” by J.
Hull, using the CDS.cpp example from quantlib.org. Unfortunately, up to now, I wasn’t able to do so and I wondered if you might help me.
The following values were used by Hull:
I changed the “flatRate” to 0.05 and created “tenors” for each year (1*Years, …, 5*Years). Afterwards I changed the “schedule” from quarterly to annual and set the “DateGeneration” to Forward. Besides some further output, I did not make any other changes.
The resulting survival probability and discount factor are nearly as in the example from Hull. Moreover, the hazard rate values are ok. Unfortunately, the NPV, the default leg and the coupon leg are not the same as in Hull’s example. As far as I can see,
that’s because of a calibration, in order to get the NPV to zero. Is there a chance to prevent this calibration being computed, so that I can see the previous NPVs’ using the spread which I provided instead of the fair spread?
Thank you in advance.
Best regards,
Patrick
------------------------------------------------------------------------------ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hello Patrick,
may you post your modified code? Later, Luigi On Tue, Apr 1, 2014 at 3:35 PM, Heinze, Patrick <[hidden email]> wrote: > Hello everybody, > > currently, I am writing my Bachelor thesis and I try to use QuantLib to > generate realistic Credit Default Swaps. I am new to quantitative finance. > That's why I tried to rebuild an example which I found in "Options, Futures, > and Other Derivatives" by J. Hull, using the CDS.cpp example from > quantlib.org. Unfortunately, up to now, I wasn't able to do so and I > wondered if you might help me. > > The following values were used by Hull: > > Notional: 1 $ > Spread: 0.012420 > Schedule: Annual > Yield curve: 5% LIBOR > Recovery rate: 40% > Duration: 5 Years > > > I changed the "flatRate" to 0.05 and created "tenors" for each year > (1*Years, ..., 5*Years). Afterwards I changed the "schedule" from quarterly to > annual and set the "DateGeneration" to Forward. Besides some further output, > I did not make any other changes. > > The resulting survival probability and discount factor are nearly as in the > example from Hull. Moreover, the hazard rate values are ok. Unfortunately, > the NPV, the default leg and the coupon leg are not the same as in Hull's > example. As far as I can see, that's because of a calibration, in order to > get the NPV to zero. Is there a chance to prevent this calibration being > computed, so that I can see the previous NPVs' using the spread which I > provided instead of the fair spread? > > Thank you in advance. > > Best regards, > Patrick > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > QuantLib-users mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-users > -- <https://implementingquantlib.blogspot.com> <https://twitter.com/lballabio> ------------------------------------------------------------------------------ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hello, The default probability within a year is 2% upon condition that no default has occurred before. The corresponding continuous hazard rate is 2,02%
p.a. Time (Years) default probability
1
0.0200
2
0.0196
3
0.0192
4
0.0188
5
0.0184 Changing the point for bootstrap to 5-years only results in getting my previous 5-year result for each year. In numbers, the returned values are: NPV: -3.20674e-13 Default leg: 0.0511065 Coupon leg: -0.0511065 My expected premium is 4.07053964 and my expected protection is 0.08514138. Thanks again for your help. Patrick From: Luigi Ballabio [mailto:[hidden email]]
Hello, you set the spread you're given as all the quoted spreads that you're using for building the curve, so that's going to be the fair spread of all cds by construction. What default probability curve does Hull use? Also, what if you only
use the 5-years point for bootstrap? (That is, just one quoted spread and just one maturity = 5 years?) Are the values closer to what you expect? Luigi On Wed, Apr 2, 2014 at 1:22 PM, Heinze, Patrick <[hidden email]> wrote: Hello Luigi,
-- ------------------------------------------------------------------------------ Put Bad Developers to Shame Dominate Development with Jenkins Continuous Integration Continuously Automate Build, Test & Deployment Start a new project now. Try Jenkins in the cloud. http://p.sf.net/sfu/13600_Cloudbees _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users CreditDefaultSwap.cpp (14K) Download Attachment |
Ok, if you're given an hazard rate use that one instead of bootstrapping. You can use the FlatHazardRate class for that. Build an instance with the given hazard rate and use it in place of the PiecewiseDefaultCurve you're using. Luigi On Thu, Apr 10, 2014 at 8:49 AM, Heinze, Patrick <[hidden email]> wrote:
<https://implementingquantlib.blogspot.com> <https://twitter.com/lballabio> ------------------------------------------------------------------------------ Put Bad Developers to Shame Dominate Development with Jenkins Continuous Integration Continuously Automate Build, Test & Deployment Start a new project now. Try Jenkins in the cloud. http://p.sf.net/sfu/13600_Cloudbees _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
After I made the changes you suggested, I get the following results (payments year 1 to year 5) : Repricing of quoted CDSs employed for calibration:
NPV: 4.15861e-06 default leg: 0.011703 coupon leg: -0.0116988 NPV: 9.52244e-06 default leg: 0.0226702 coupon leg: -0.0226607 NPV: 1.14725e-05 default leg: 0.0328088 coupon leg: -0.0327973 NPV: 1.48407e-05 default leg: 0.0422875 coupon leg: -0.0422726 NPV: 1.79806e-05 default leg: 0.0511236 coupon leg: -0.0511056 My Problem is that the NPV is still nearly zero… These are the values, which I would expect:
Do you have any further ideas on how to calculate these values or is my problem maybe something else? Regards, Patrick From: Luigi Ballabio [mailto:[hidden email]]
Ok, if you're given an hazard rate use that one instead of bootstrapping. You can use the FlatHazardRate class for that. Build an instance with the given hazard rate and use it in place of the PiecewiseDefaultCurve you're using. Luigi On Thu, Apr 10, 2014 at 8:49 AM, Heinze, Patrick <[hidden email]> wrote: Hello, The default probability within a year is 2% upon condition that no default has occurred
before. The corresponding continuous hazard rate is 2,02% p.a. Time (Years) default probability 1
0.0200 2
0.0196 3
0.0192 4
0.0188 5
0.0184 Changing the point for bootstrap to 5-years only results in getting my previous 5-year
result for each year. In numbers, the returned values are: NPV: -3.20674e-13 Default leg: 0.0511065 Coupon leg: -0.0511065 My expected premium is 4.07053964 and my expected protection is 0.08514138. Thanks again for your help. Patrick From: Luigi
Ballabio [mailto:[hidden email]]
Sent: Mittwoch, 9. April 2014 17:22 Subject: Re: [Quantlib-users] Calibration of CDS.cpp Hello, you set the spread you're given as all the quoted spreads that you're using for building the curve, so that's going to be the fair spread of all cds by construction. What default
probability curve does Hull use? Also, what if you only use the 5-years point for bootstrap? (That is, just one quoted spread and just one maturity = 5 years?) Are the values closer to what you expect? Luigi On Wed, Apr 2, 2014 at 1:22 PM, Heinze, Patrick <[hidden email]> wrote: Hello Luigi,
--
-- ------------------------------------------------------------------------------ Put Bad Developers to Shame Dominate Development with Jenkins Continuous Integration Continuously Automate Build, Test & Deployment Start a new project now. Try Jenkins in the cloud. http://p.sf.net/sfu/13600_Cloudbees _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
I think the problem is in how you're interpreting Hull's example. I'm not sure we have the same book (I'm looking at the 7th edition) however: a) when he tabulates the figures for 1 year, 2 years and so on, they're not cumulative; they're just those for the year. So, for instance, when he says that the expected payoff is 0.0117 for the first year, 0.0109 for the second and so on, it means that the expected payoff for a 1-year CDS is 0.0117, the one for a 2-years swap is 0.0117+0.0109 = 0.0226, etc. The expected payoff for a 5-years swap is the one reported as total, that is, 0.0511, and it's the same one that QuantLib is returning as the NPV of the "default leg".
b) the figures you're reporting as premiums are the ones I see tabulated in the book for expected payments. In my edition, they are not 0.9322 etc; they're 0.9322s, that is, they're multiplied by the spread. For a spread s = 0.0124, the first one would be 0.9322*0.0124. Moreover, the spread is chosen specifically so that the expected payoff equals the expected payments (4.1130s = 0.0511 is the equation used), and that's why the NPV is 0 within accuracy.
In short, it seems to me that the calculations agree with the book. But it might be that you have a different edition, so let me know if your book says otherwise. Luigi On Thu, Apr 10, 2014 at 11:55 AM, Heinze, Patrick <[hidden email]> wrote:
<https://implementingquantlib.blogspot.com> <https://twitter.com/lballabio> ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. Written by three acclaimed leaders in the field, this first edition is now available. Download your free book today! http://p.sf.net/sfu/NeoTech _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |