QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
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 */
80 CdsHelper(const std::variant<Rate, Handle<Quote>>& quote,
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
98 // NOLINTNEXTLINE(cppcoreguidelines-noexcept-swap,performance-noexcept-swap)
99 ext::shared_ptr<CreditDefaultSwap> swap() const {
100 return swap_;
101 }
102 void update() override;
103
104 protected:
105 void initializeDates() override;
106 virtual void resetEngine() = 0;
121
123 ext::shared_ptr<CreditDefaultSwap> swap_;
125 //! protection effective date.
128 };
129
130 //! Spread-quoted CDS hazard rate bootstrap helper.
131 class SpreadCdsHelper : public CdsHelper {
132 public:
133 SpreadCdsHelper(const std::variant<Rate, Handle<Quote>>& runningSpread,
134 const Period& tenor,
135 Integer settlementDays,
136 const Calendar& calendar,
137 Frequency frequency,
138 BusinessDayConvention paymentConvention,
140 const DayCounter& dayCounter,
141 Real recoveryRate,
142 const Handle<YieldTermStructure>& discountCurve,
143 bool settlesAccrual = true,
144 bool paysAtDefaultTime = true,
145 const Date& startDate = Date(),
146 const DayCounter& lastPeriodDayCounter = DayCounter(),
147 bool rebatesAccrual = true,
149
150 Real impliedQuote() const override;
151
152 private:
153 void resetEngine() override;
154 };
155
156 //! Upfront-quoted CDS hazard rate bootstrap helper.
158 public:
159 /*! \note the upfront must be quoted in fractional units. */
160 UpfrontCdsHelper(const std::variant<Rate, Handle<Quote>>& upfront,
161 Rate runningSpread,
162 const Period& tenor,
163 Integer settlementDays,
164 const Calendar& calendar,
165 Frequency frequency,
166 BusinessDayConvention paymentConvention,
168 const DayCounter& dayCounter,
169 Real recoveryRate,
170 const Handle<YieldTermStructure>& discountCurve,
171 Natural upfrontSettlementDays = 3,
172 bool settlesAccrual = true,
173 bool paysAtDefaultTime = true,
174 const Date& startDate = Date(),
175 const DayCounter& lastPeriodDayCounter = DayCounter(),
176 bool rebatesAccrual = true,
178
179 Real impliedQuote() const override;
180
181 private:
183 void initializeDates() override;
184 void resetEngine() override;
188 };
189
190}
191
192
193#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:37
BootstrapHelper< DefaultProbabilityTermStructure > DefaultProbabilityHelper
alias for default-probability bootstrap helpers
RelativeDateBootstrapHelper< DefaultProbabilityTermStructure > RelativeDateDefaultProbabilityHelper
date schedule