Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
discountingriskybondengine.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file qle/pricingengines/discountingriskybondengine.hpp
20 \brief Risky Bond Engine
21 \ingroup engines
22*/
23
24#ifndef quantext_discounting_riskybond_engine_hpp
25#define quantext_discounting_riskybond_engine_hpp
26
27#include <ql/instruments/bond.hpp>
28#include <ql/termstructures/defaulttermstructure.hpp>
29#include <ql/termstructures/yieldtermstructure.hpp>
30#include <ql/time/period.hpp>
32
33namespace QuantExt {
34using namespace QuantLib;
35
36//! Discounting Risky Bond Engine
37/*! WARNING: Only covers Vanilla coupon bonds (floating and fixed rate), and
38 Zero Bonds (one cashflow, a redemption at maturity).
39
40 This class implements pricing of Risky Bonds by discounting the future
41 nominal cash flows using the respective yield curves, and probability of
42 survival.
43 The nominal recovered in case of default is calculated as recovery rate times
44 the integral of probability of default until maturity date. For coupon bonds
45 the coupon periods are taken as the time step for integration, for a zero
46 bond the time step period provided is used.
47
48 \ingroup engines
49
50*/
52public:
53
55 // always provided in calculateNpv()
56 Real npv;
59 // only provided in calculateNpv() when additionalResults = true
60 std::vector<CashFlowResults> cashflowResults;
61 };
62
63 DiscountingRiskyBondEngine(const Handle<YieldTermStructure>& discountCurve,
64 const Handle<DefaultProbabilityTermStructure>& defaultCurve,
65 const Handle<Quote>& recoveryRate, const Handle<Quote>& securitySpread,
66 Period timestepPeriod, boost::optional<bool> includeSettlementDateFlows = boost::none);
67
68 //! alternative constructor (does not require default curve or recovery rate)
69 DiscountingRiskyBondEngine(const Handle<YieldTermStructure>& discountCurve, const Handle<Quote>& securitySpread,
70 Period timestepPeriod, boost::optional<bool> includeSettlementDateFlows = boost::none);
71
72 void calculate() const override;
73
74 /*! Calculate the npv, compoundFactorSettlement, cashflowsBeforeSettlementValue and the additional CashflowResults
75 as of the npvDate including cashflows eligible w.r.t. the given settlement date
76 - If conditionalOnSurvival is set to true, the npv is computed conditional on the survival until the npvDate,
77 otherwise the npv is including the default probability between today and the npvDate
78 - If an incomeCurve is given, this is used to compound the npv from today to the npvDate, otherwise the curve
79 built in the engine as discount curve + security Spread is used. */
80 BondNPVCalculationResults calculateNpv(const Date& npvDate, const Date& settlementDate, const Leg& cashflows,
81 boost::optional<bool> includeSettlementDateFlows = boost::none,
82 const Handle<YieldTermStructure>& incomeCurve = Handle<YieldTermStructure>(),
83 const bool conditionalOnSurvival = true,
84 const bool additionalResults = true) const;
85
86 // inspectors
87 Handle<YieldTermStructure> discountCurve() const { return discountCurve_; };
88 Handle<DefaultProbabilityTermStructure> defaultCurve() const { return defaultCurve_; };
89 Handle<Quote> recoveryRate() const { return recoveryRate_; };
90 Handle<Quote> securitySpread() const { return securitySpread_; };
91
92protected:
93 Handle<YieldTermStructure> discountCurve_;
94 mutable Handle<DefaultProbabilityTermStructure> defaultCurve_;
95 mutable Handle<Quote> recoveryRate_;
96 Handle<Quote> securitySpread_;
98 boost::optional<bool> includeSettlementDateFlows_;
99};
100} // namespace QuantExt
101
102#endif
class holding cashflow-related results
Handle< YieldTermStructure > discountCurve() const
Handle< DefaultProbabilityTermStructure > defaultCurve() const
BondNPVCalculationResults calculateNpv(const Date &npvDate, const Date &settlementDate, const Leg &cashflows, boost::optional< bool > includeSettlementDateFlows=boost::none, const Handle< YieldTermStructure > &incomeCurve=Handle< YieldTermStructure >(), const bool conditionalOnSurvival=true, const bool additionalResults=true) const
Handle< DefaultProbabilityTermStructure > defaultCurve_