QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
creditdefaultswap.hpp
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 Roland Lichters
6 Copyright (C) 2008 StatPro Italia srl
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
26#ifndef quantlib_credit_default_swap_hpp
27#define quantlib_credit_default_swap_hpp
28
29#include <ql/instrument.hpp>
30#include <ql/cashflows/simplecashflow.hpp>
31#include <ql/default.hpp>
32#include <ql/termstructures/defaulttermstructure.hpp>
33#include <ql/time/schedule.hpp>
34#include <ql/optional.hpp>
35
36namespace QuantLib {
37
38 class YieldTermStructure;
39 class Claim;
40
42
57 public:
58 class arguments;
59 class results;
60 class engine;
63 ISDA
64 };
66
67
101 Rate spread,
102 const Schedule& schedule,
103 BusinessDayConvention paymentConvention,
104 const DayCounter& dayCounter,
105 bool settlesAccrual = true,
106 bool paysAtDefaultTime = true,
107 const Date& protectionStart = Date(),
108 ext::shared_ptr<Claim> = ext::shared_ptr<Claim>(),
109 const DayCounter& lastPeriodDayCounter = DayCounter(),
110 bool rebatesAccrual = true,
111 const Date& tradeDate = Date(),
114
154 Rate spread,
155 const Schedule& schedule,
156 BusinessDayConvention paymentConvention,
157 const DayCounter& dayCounter,
158 bool settlesAccrual = true,
159 bool paysAtDefaultTime = true,
160 const Date& protectionStart = Date(),
161 const Date& upfrontDate = Date(),
162 ext::shared_ptr<Claim> = ext::shared_ptr<Claim>(),
163 const DayCounter& lastPeriodDayCounter = DayCounter(),
164 bool rebatesAccrual = true,
165 const Date& tradeDate = Date(),
168
170 bool isExpired() const override;
171 void setupArguments(PricingEngine::arguments*) const override;
172 void fetchResults(const PricingEngine::results*) const override;
174
176 Protection::Side side() const;
177 Real notional() const;
178 Rate runningSpread() const;
179 ext::optional<Rate> upfront() const;
180 bool settlesAccrual() const;
181 bool paysAtDefaultTime() const;
182 const Leg& coupons() const;
184 const Date& protectionStartDate() const;
186 const Date& protectionEndDate() const;
187 bool rebatesAccrual() const { return accrualRebate_ != nullptr; }
188 const ext::shared_ptr<SimpleCashFlow>& upfrontPayment() const;
189 const ext::shared_ptr<SimpleCashFlow>& accrualRebate() const;
190 const Date& tradeDate() const;
193
195
199 Rate fairUpfront() const;
206 Rate fairSpread() const;
210 Real couponLegBPS() const;
211 Real upfrontBPS() const;
212 Real couponLegNPV() const;
213 Real defaultLegNPV() const;
214 Real upfrontNPV() const;
215 Real accrualRebateNPV() const;
216
218
234 Rate impliedHazardRate(Real targetNPV,
235 const Handle<YieldTermStructure>& discountCurve,
236 const DayCounter& dayCounter,
237 Real recoveryRate = 0.4,
238 Real accuracy = 1.0e-8,
239 PricingModel model = Midpoint) const;
240
242
272 Rate conventionalSpread(Real conventionalRecovery,
273 const Handle<YieldTermStructure>& discountCurve,
274 const DayCounter& dayCounter,
275 PricingModel model = Midpoint) const;
277 protected:
279
280 void setupExpired() const override;
282 // data members
285 ext::optional<Rate> upfront_;
288 ext::shared_ptr<Claim> claim_;
290 ext::shared_ptr<SimpleCashFlow> upfrontPayment_;
291 ext::shared_ptr<SimpleCashFlow> accrualRebate_;
296 // results
303
304 private:
306 void init(const Schedule& schedule, BusinessDayConvention paymentConvention, const DayCounter& dayCounter,
307 const DayCounter& lastPeriodDayCounter, bool rebatesAccrual, const Date& upfrontDate = Date());
308 };
309
310
312 : public virtual PricingEngine::arguments {
313 public:
314 arguments();
317 ext::optional<Rate> upfront;
320 // if not initialized by constructors means theres no flows.
321 ext::shared_ptr<SimpleCashFlow> upfrontPayment;
322 ext::shared_ptr<SimpleCashFlow> accrualRebate;
325 ext::shared_ptr<Claim> claim;
328 void validate() const override;
329 };
330
332 public:
341 void reset() override;
342 };
343
345 : public GenericEngine<CreditDefaultSwap::arguments,
346 CreditDefaultSwap::results> {};
347
361 Date cdsMaturity(const Date& tradeDate, const Period& tenor, DateGeneration::Rule rule);
362
363}
364
365
366#endif
ext::shared_ptr< SimpleCashFlow > accrualRebate
ext::shared_ptr< SimpleCashFlow > upfrontPayment
const Date & protectionStartDate() const
The first date for which defaults will trigger the contract.
const ext::shared_ptr< SimpleCashFlow > & upfrontPayment() const
void init(const Schedule &schedule, BusinessDayConvention paymentConvention, const DayCounter &dayCounter, const DayCounter &lastPeriodDayCounter, bool rebatesAccrual, const Date &upfrontDate=Date())
Shared initialisation.
void setupArguments(PricingEngine::arguments *) const override
bool isExpired() const override
returns whether the instrument might have value greater than zero.
const Date & tradeDate() const
ext::shared_ptr< Claim > claim_
ext::shared_ptr< SimpleCashFlow > accrualRebate_
ext::optional< Rate > upfront() const
ext::optional< Rate > upfront_
Rate impliedHazardRate(Real targetNPV, const Handle< YieldTermStructure > &discountCurve, const DayCounter &dayCounter, Real recoveryRate=0.4, Real accuracy=1.0e-8, PricingModel model=Midpoint) const
Implied hazard rate calculation.
const ext::shared_ptr< SimpleCashFlow > & accrualRebate() const
void setupExpired() const override
const Date & protectionEndDate() const
The last date for which defaults will trigger the contract.
void fetchResults(const PricingEngine::results *) const override
Rate conventionalSpread(Real conventionalRecovery, const Handle< YieldTermStructure > &discountCurve, const DayCounter &dayCounter, PricingModel model=Midpoint) const
Conventional/standard upfront-to-spread conversion.
ext::shared_ptr< SimpleCashFlow > upfrontPayment_
Protection::Side side() const
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
template base class for option pricing engines
Shared handle to an observable.
Definition: handle.hpp:41
Abstract instrument class.
Definition: instrument.hpp:44
Payment schedule.
Definition: schedule.hpp:40
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
Date cdsMaturity(const Date &tradeDate, const Period &tenor, DateGeneration::Rule rule)
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78