21#ifndef QL_PATCH_SOLARIS
23#include <ql/cashflows/fixedratecoupon.hpp>
24#include <ql/termstructures/yieldtermstructure.hpp>
25#include <boost/timer/timer.hpp>
28using boost::timer::cpu_timer;
34 boost::optional<bool> includeSettlementDateFlows)
35 : discountCurve_(discountCurve),
36 includeSettlementDateFlows_(includeSettlementDateFlows) {
37 registerWith(discountCurve);
47 Real upfrontPremiumAmount =
arguments_.upfrontPayment->amount();
50 results_.upfrontPremiumValue = upfrontPremiumAmount *
63 results_.accrualRebateCurrentValue = 0.0;
73 QL_REQUIRE(basket,
"IndexCdsTrancheEngine expects a non-null basket.");
74 results_.xMin = basket->attachmentAmount();
75 results_.xMax = basket->detachmentAmount();
81 vector<Real>& etls =
results_.expectedTrancheLoss;
85 Date today = Settings::instance().evaluationDate();
88 Real inceptionTrancheNotional =
arguments_.basket->trancheNotional();
91 for (Size i = 0; i <
arguments_.normalizedLeg.size(); i++) {
95 if (
arguments_.normalizedLeg[i]->hasOccurred(today)) {
100 QuantLib::ext::shared_ptr<Coupon> coupon = QuantLib::ext::dynamic_pointer_cast<Coupon>(
arguments_.normalizedLeg[i]);
101 QL_REQUIRE(coupon,
"IndexCdsTrancheEngine expects leg to have Coupon cashflow type.");
104 Date paymentDate = coupon->date();
105 Date startDate = std::max(coupon->accrualStartDate(), today);
106 Date endDate = coupon->accrualEndDate();
107 Date defaultDate = startDate + (endDate - startDate) / 2;
110 Real etl = basket->expectedTrancheLoss(endDate,
arguments_.recoveryRate);
120 effNtl = inceptionTrancheNotional - (etl + etls.back()) / 2.0;
122 effNtl = inceptionTrancheNotional - etl;
124 results_.premiumValue += (coupon->amount() / inceptionTrancheNotional) *
135 upfrontPremiumAmount *= -1;
139 results_.accrualRebateCurrentValue *= -1;
147 Real fairSpread = 0.0;
159 results_.additionalResults[
"fairSpread"] = fairSpread;
160 results_.additionalResults[
"upfrontPremium"] = upfrontPremiumAmount;
161 Real correlation =
arguments_.basket->correlation();
162 if (correlation != Null<Real>())
163 results_.additionalResults[
"correlation"] = correlation;
164 results_.additionalResults[
"upfrontPremiumNPV"] =
results_.upfrontPremiumValue;
166 results_.additionalResults[
"accrualRebateNPV"] =
results_.accrualRebateValue;
167 results_.additionalResults[
"accrualRebateCurrentNPV"] =
results_.accrualRebateCurrentValue;
170 results_.additionalResults[
"calculationTime"] = timer.elapsed().wall * 1e-9;
const Instrument::results * results_
IndexCdsTrancheEngine(const QuantLib::Handle< QuantLib::YieldTermStructure > &discountCurve, boost::optional< bool > includeSettlementDateFlows=boost::none)
boost::optional< bool > includeSettlementDateFlows_
void calculate() const override
QuantLib::Handle< QuantLib::YieldTermStructure > discountCurve_
Index CDS tranche pricing engine.
Swap::arguments * arguments_