QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
defaultprobabilityhelpers.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008, 2009 Jose Aparicio
5 Copyright (C) 2008 Chris Kenyon
6 Copyright (C) 2008 Roland Lichters
7 Copyright (C) 2008 StatPro Italia srl
8 Copyright (C) 2023 Andrea Pellegatta
9
10 This file is part of QuantLib, a free-software/open-source library
11 for financial quantitative analysts and developers - http://quantlib.org/
12
13 QuantLib is free software: you can redistribute it and/or modify it
14 under the terms of the QuantLib license. You should have received a
15 copy of the license along with this program; if not, please email
16 <quantlib-dev@lists.sf.net>. The license is also available online at
17 <http://quantlib.org/license.shtml>.
18
19 This program is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21 FOR A PARTICULAR PURPOSE. See the license for more details.
22*/
23
24/*! \file defaultprobabilityhelpers.hpp
25 \brief bootstrap helpers for default-probability term structures
26*/
27
28#ifndef quantlib_default_probability_helpers_hpp
29#define quantlib_default_probability_helpers_hpp
30
33#include <ql/time/schedule.hpp>
35
36namespace QuantLib {
37
38 class YieldTermStructure;
39 class CreditDefaultSwap;
40
41 //! alias for default-probability bootstrap helpers
42 typedef BootstrapHelper<DefaultProbabilityTermStructure>
46
47 //! Base class for CDS helpers
49 public:
50 /*! Constructor taking CDS market quote
51 @param quote The helper's market quote.
52 @param tenor CDS tenor.
53 @param settlementDays The number of days from evaluation date to the start of the protection period.
54 Prior to the CDS Big Bang in 2009, this was typically 1 calendar day. After the
55 CDS Big Bang, this is typically 0 calendar days i.e. protection starts
56 immediately.
57 @param calendar CDS calendar. Typically weekends only for standard non-JPY CDS and TYO for JPY.
58 @param frequency Coupon frequency. Typically 3 months for standard CDS.
59 @param paymentConvention The convention applied to coupons schedules and settlement dates.
60 @param rule The date generation rule for generating the CDS schedule. Typically, for CDS prior to the
61 Big Bang, \c OldCDS should be used. After the Big Bang, \c CDS was typical and since 2015
62 \c CDS2015 is standard.
63 @param dayCounter The day counter for CDS fee leg coupons. Typically it is Actual/360, excluding
64 accrual end, for all but the final coupon period with Actual/360, including accrual
65 end, for the final coupon. The \p lastPeriodDayCounter below allows for this
66 distinction.
67 @param recoveryRate The recovery rate of the underlying reference entity.
68 @param discountCurve A handle to the relevant discount curve.
69 @param settlesAccrual Set to \c true if accrued fee is paid on the occurrence of a credit event and set
70 to \c false if it is not. Typically this is \c true.
71 @param paysAtDefaultTime Set to \c true if default payment is made at time of credit event or postponed
72 to the end of the coupon period. Typically this is \c true.
73 @param startDate Used to specify an explicit start date for the CDS schedule and the date from which the
74 CDS maturity is calculated via the \p tenor. Useful for off-the-run index schedules.
75 @param lastPeriodDayCounter The day counter for the last fee leg coupon. See comment on \p dayCounter.
76 @param rebatesAccrual Set to \c true if the fee leg accrual is rebated on the cash settlement date. For
77 CDS after the Big Bang, this is typically \c true.
78 @param model The pricing model to use for the helper.
79 */
81 const Period& tenor,
82 Integer settlementDays,
83 Calendar calendar,
84 Frequency frequency,
85 BusinessDayConvention paymentConvention,
87 DayCounter dayCounter,
88 Real recoveryRate,
89 const Handle<YieldTermStructure>& discountCurve,
90 bool settlesAccrual = true,
91 bool paysAtDefaultTime = true,
92 const Date& startDate = Date(),
93 DayCounter lastPeriodDayCounter = DayCounter(),
94 bool rebatesAccrual = true,
96
97 //! \copydoc CdsHelper::CdsHelper
99 const Period& tenor,
100 Integer settlementDays,
101 Calendar calendar,
102 Frequency frequency,
103 BusinessDayConvention paymentConvention,
105 DayCounter dayCounter,
106 Real recoveryRate,
107 const Handle<YieldTermStructure>& discountCurve,
108 bool settlesAccrual = true,
109 bool paysAtDefaultTime = true,
110 const Date& startDate = Date(),
111 DayCounter lastPeriodDayCounter = DayCounter(),
112 bool rebatesAccrual = true,
115 // NOLINTNEXTLINE(cppcoreguidelines-noexcept-swap,performance-noexcept-swap)
116 ext::shared_ptr<CreditDefaultSwap> swap() const {
117 return swap_;
118 }
119 void update() override;
120
121 protected:
122 void initializeDates() override;
123 virtual void resetEngine() = 0;
138
140 ext::shared_ptr<CreditDefaultSwap> swap_;
142 //! protection effective date.
145 };
146
147 //! Spread-quoted CDS hazard rate bootstrap helper.
148 class SpreadCdsHelper : public CdsHelper {
149 public:
150 SpreadCdsHelper(const Handle<Quote>& runningSpread,
151 const Period& tenor,
152 Integer settlementDays,
153 const Calendar& calendar,
154 Frequency frequency,
155 BusinessDayConvention paymentConvention,
157 const DayCounter& dayCounter,
158 Real recoveryRate,
159 const Handle<YieldTermStructure>& discountCurve,
160 bool settlesAccrual = true,
161 bool paysAtDefaultTime = true,
162 const Date& startDate = Date(),
163 const DayCounter& lastPeriodDayCounter = DayCounter(),
164 bool rebatesAccrual = true,
166
168 Rate runningSpread,
169 const Period& tenor,
170 Integer settlementDays, // ISDA: 1
171 const Calendar& calendar,
172 Frequency frequency, // ISDA: Quarterly
173 BusinessDayConvention paymentConvention, // ISDA:Following
174 DateGeneration::Rule rule, // ISDA: CDS
175 const DayCounter& dayCounter, // ISDA: Actual/360
176 Real recoveryRate,
177 const Handle<YieldTermStructure>& discountCurve,
178 bool settlesAccrual = true,
179 bool paysAtDefaultTime = true,
180 const Date& startDate = Date(),
181 const DayCounter& lastPeriodDayCounter = DayCounter(), // ISDA: Actual/360(inc)
182 bool rebatesAccrual = true, // ISDA: true
184 Real impliedQuote() const override;
185
186 private:
187 void resetEngine() override;
188 };
189
190 //! Upfront-quoted CDS hazard rate bootstrap helper.
192 public:
193 /*! \note the upfront must be quoted in fractional units. */
194 UpfrontCdsHelper(const Handle<Quote>& upfront,
195 Rate runningSpread,
196 const Period& tenor,
197 Integer settlementDays,
198 const Calendar& calendar,
199 Frequency frequency,
200 BusinessDayConvention paymentConvention,
202 const DayCounter& dayCounter,
203 Real recoveryRate,
204 const Handle<YieldTermStructure>& discountCurve,
205 Natural upfrontSettlementDays = 3,
206 bool settlesAccrual = true,
207 bool paysAtDefaultTime = true,
208 const Date& startDate = Date(),
209 const DayCounter& lastPeriodDayCounter = DayCounter(),
210 bool rebatesAccrual = true,
212
213 /*! \note the upfront must be quoted in fractional units. */
214 UpfrontCdsHelper(Rate upfront,
215 Rate runningSpread,
216 const Period& tenor,
217 Integer settlementDays,
218 const Calendar& calendar,
219 Frequency frequency,
220 BusinessDayConvention paymentConvention,
222 const DayCounter& dayCounter,
223 Real recoveryRate,
224 const Handle<YieldTermStructure>& discountCurve,
225 Natural upfrontSettlementDays = 3,
226 bool settlesAccrual = true,
227 bool paysAtDefaultTime = true,
228 const Date& startDate = Date(),
229 const DayCounter& lastPeriodDayCounter = DayCounter(),
230 bool rebatesAccrual = true,
232 Real impliedQuote() const override;
233
234 private:
236 void initializeDates() override;
237 void resetEngine() override;
241 };
242
243}
244
245
246#endif
base helper class used for bootstrapping
const Handle< Quote > & quote() const
calendar class
Definition: calendar.hpp:61
Base class for CDS helpers.
Handle< YieldTermStructure > discountCurve_
RelinkableHandle< DefaultProbabilityTermStructure > probability_
void setTermStructure(DefaultProbabilityTermStructure *) override
ext::shared_ptr< CreditDefaultSwap > swap() const
CreditDefaultSwap::PricingModel model_
BusinessDayConvention paymentConvention_
virtual void resetEngine()=0
ext::shared_ptr< CreditDefaultSwap > swap_
Date protectionStart_
protection effective date.
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Default probability term structure.
Shared handle to an observable.
Definition: handle.hpp:41
Bootstrap helper with date schedule relative to global evaluation date.
Relinkable handle to an observable.
Definition: handle.hpp:117
Payment schedule.
Definition: schedule.hpp:40
Spread-quoted CDS hazard rate bootstrap helper.
Upfront-quoted CDS hazard rate bootstrap helper.
Credit default swap.
default-probability term structure
Frequency
Frequency of events.
Definition: frequency.hpp:37
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
BootstrapHelper< DefaultProbabilityTermStructure > DefaultProbabilityHelper
alias for default-probability bootstrap helpers
RelativeDateBootstrapHelper< DefaultProbabilityTermStructure > RelativeDateDefaultProbabilityHelper
date schedule