Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
DiscountingRiskyBondEngineMultiState Class Reference

#include <qle/pricingengines/discountingriskybondenginemultistate.hpp>

+ Inheritance diagram for DiscountingRiskyBondEngineMultiState:
+ Collaboration diagram for DiscountingRiskyBondEngineMultiState:

Public Member Functions

 DiscountingRiskyBondEngineMultiState (const Handle< YieldTermStructure > &discountCurve, const std::vector< Handle< DefaultProbabilityTermStructure > > &defaultCurves, const std::vector< Handle< Quote > > &recoveryRates, const Size mainResultState, const Handle< Quote > &securitySpread, Period timestepPeriod, const boost::optional< bool > includeSettlementDateFlows=boost::none)
 
void calculate () const
 
Real calculateNpv (const Size state) const
 
Real calculateDefaultValue () const
 
Handle< YieldTermStructure > discountCurve () const
 
const std::vector< Handle< DefaultProbabilityTermStructure > > & defaultCurves () const
 
const std::vector< Handle< Quote > > & recoveryRates () const
 
Handle< Quote > securitySpread () const
 
- Public Member Functions inherited from DiscountingRiskyBondEngine
 DiscountingRiskyBondEngine (const Handle< YieldTermStructure > &discountCurve, const Handle< DefaultProbabilityTermStructure > &defaultCurve, const Handle< Quote > &recoveryRate, const Handle< Quote > &securitySpread, Period timestepPeriod, boost::optional< bool > includeSettlementDateFlows=boost::none)
 
 DiscountingRiskyBondEngine (const Handle< YieldTermStructure > &discountCurve, const Handle< Quote > &securitySpread, Period timestepPeriod, boost::optional< bool > includeSettlementDateFlows=boost::none)
 alternative constructor (does not require default curve or recovery rate) More...
 
void calculate () const override
 
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< YieldTermStructure > discountCurve () const
 
Handle< DefaultProbabilityTermStructure > defaultCurve () const
 
Handle< Quote > recoveryRate () const
 
Handle< Quote > securitySpread () const
 

Private Member Functions

void linkCurves (Size i) const
 

Private Attributes

const std::vector< Handle< DefaultProbabilityTermStructure > > defaultCurves_
 
const std::vector< Handle< Quote > > recoveryRates_
 
const Size mainResultState_
 

Additional Inherited Members

- Protected Attributes inherited from DiscountingRiskyBondEngine
Handle< YieldTermStructure > discountCurve_
 
Handle< DefaultProbabilityTermStructure > defaultCurve_
 
Handle< Quote > recoveryRate_
 
Handle< Quote > securitySpread_
 
Period timestepPeriod_
 
boost::optional< boolincludeSettlementDateFlows_
 

Detailed Description

The engine takes a vector of default curves and recovery rates. For the given main result state it will produce the same results as the MidPointCdsEngine. In addition a result with label "stateNPV" is produced containing the NPV for each given default curve / recovery rate and an additional entry with a default value w.r.t. the last given recovery rate in the vector.

Definition at line 36 of file discountingriskybondenginemultistate.hpp.

Constructor & Destructor Documentation

◆ DiscountingRiskyBondEngineMultiState()

DiscountingRiskyBondEngineMultiState ( const Handle< YieldTermStructure > &  discountCurve,
const std::vector< Handle< DefaultProbabilityTermStructure > > &  defaultCurves,
const std::vector< Handle< Quote > > &  recoveryRates,
const Size  mainResultState,
const Handle< Quote > &  securitySpread,
Period  timestepPeriod,
const boost::optional< bool includeSettlementDateFlows = boost::none 
)

Definition at line 30 of file discountingriskybondenginemultistate.cpp.

35 : DiscountingRiskyBondEngine(discountCurve, Handle<DefaultProbabilityTermStructure>(), Handle<Quote>(),
36 securitySpread, timestepPeriod, includeSettlementDateFlows),
38 QL_REQUIRE(!defaultCurves.empty(), "DiscountingRiskBondEngineMultiState: no default curves / recovery rates given");
39 for (auto const& h : defaultCurves_) {
40 registerWith(h);
41 }
42 for (auto const& r : recoveryRates_) {
43 registerWith(r);
44 }
45 QL_REQUIRE(mainResultState < defaultCurves.size(), "DiscountingRiskBondEngineMultiState: mainResultState ("
46 << mainResultState << ") out of range 0..."
47 << defaultCurves.size() - 1);
48}
DiscountingRiskyBondEngine(const Handle< YieldTermStructure > &discountCurve, const Handle< DefaultProbabilityTermStructure > &defaultCurve, const Handle< Quote > &recoveryRate, const Handle< Quote > &securitySpread, Period timestepPeriod, boost::optional< bool > includeSettlementDateFlows=boost::none)
const std::vector< Handle< DefaultProbabilityTermStructure > > defaultCurves_
const std::vector< Handle< Quote > > & recoveryRates() const
const std::vector< Handle< DefaultProbabilityTermStructure > > & defaultCurves() const
+ Here is the call graph for this function:

Member Function Documentation

◆ calculate()

void calculate ( ) const

Definition at line 55 of file discountingriskybondenginemultistate.cpp.

55 {
56
57 // calculate all states except the main states
58
59 std::vector<Real> values(defaultCurves_.size() + 1);
60 for (Size i = 0; i < defaultCurves_.size(); ++i) {
61 if (i == mainResultState_)
62 continue;
63 linkCurves(i);
65 values[i] = results_.value;
66 }
67
68 // calculate the main state last to keep the results from this calculation
69
72 values[mainResultState_] = results_.value;
73
74 // calculate the default state
75
76 values.back() = calculateDefaultValue();
77
78 // set additional result
79
80 results_.additionalResults["stateNpv"] = values;
81}
const Instrument::results * results_
Definition: cdsoption.cpp:81
+ Here is the call graph for this function:

◆ calculateNpv()

Real calculateNpv ( const Size  state) const

◆ calculateDefaultValue()

Real calculateDefaultValue ( ) const

Definition at line 83 of file discountingriskybondenginemultistate.cpp.

83 {
84 Date npvDate = discountCurve_->referenceDate();
85 for (auto& cf : arguments_.cashflows) {
86 if (cf->hasOccurred(npvDate, includeSettlementDateFlows_))
87 continue;
88 QuantLib::ext::shared_ptr<Coupon> coupon = QuantLib::ext::dynamic_pointer_cast<Coupon>(cf);
89 if (coupon) {
90 return coupon->nominal() * recoveryRates_.back()->value();
91 }
92 }
93 // FIXME handle bonds without coupons
94 QL_FAIL("could not calculated default value, no alive coupons found");
95}
Swap::arguments * arguments_
+ Here is the caller graph for this function:

◆ discountCurve()

Handle< YieldTermStructure > discountCurve ( ) const

Definition at line 47 of file discountingriskybondenginemultistate.hpp.

47{ return discountCurve_; };

◆ defaultCurves()

const std::vector< Handle< DefaultProbabilityTermStructure > > & defaultCurves ( ) const

Definition at line 48 of file discountingriskybondenginemultistate.hpp.

48{ return defaultCurves_; };
+ Here is the caller graph for this function:

◆ recoveryRates()

const std::vector< Handle< Quote > > & recoveryRates ( ) const

Definition at line 49 of file discountingriskybondenginemultistate.hpp.

49{ return recoveryRates_; };

◆ securitySpread()

Handle< Quote > securitySpread ( ) const

◆ linkCurves()

void linkCurves ( Size  i) const
private

Definition at line 50 of file discountingriskybondenginemultistate.cpp.

+ Here is the caller graph for this function:

Member Data Documentation

◆ defaultCurves_

const std::vector<Handle<DefaultProbabilityTermStructure> > defaultCurves_
private

Definition at line 54 of file discountingriskybondenginemultistate.hpp.

◆ recoveryRates_

const std::vector<Handle<Quote> > recoveryRates_
private

Definition at line 55 of file discountingriskybondenginemultistate.hpp.

◆ mainResultState_

const Size mainResultState_
private

Definition at line 56 of file discountingriskybondenginemultistate.hpp.