37 Real ctptyRecoveryRate,
39 Real invstRecoveryRate)
42 swaptionletEngine_(swaptionEngine),
45 ctptyRecoveryRate_(ctptyRecoveryRate),
48 ctptyDTS->dayCounter()) ) : invstDTS ),
49 invstRecoveryRate_(invstRecoveryRate)
51 registerWith(discountCurve);
52 registerWith(ctptyDTS);
54 registerWith(swaptionEngine);
61 Real ctptyRecoveryRate,
63 Real invstRecoveryRate)
71 ctptyRecoveryRate_(ctptyRecoveryRate),
74 ctptyDTS->dayCounter()) ) : invstDTS ),
75 invstRecoveryRate_(invstRecoveryRate)
77 registerWith(discountCurve);
78 registerWith(ctptyDTS);
86 Real ctptyRecoveryRate,
88 Real invstRecoveryRate)
96 ctptyRecoveryRate_(ctptyRecoveryRate),
99 ctptyDTS->dayCounter()) ) : invstDTS ),
100 invstRecoveryRate_(invstRecoveryRate)
102 registerWith(discountCurve);
103 registerWith(ctptyDTS);
105 registerWith(blackVol);
112 "no discount term structure set");
114 "no ctpty default term structure set");
116 "no swap option engine set");
119 "non-constant nominals are not supported yet");
127 std::vector<Date>::const_iterator nextFD =
128 arguments_.fixedPayDates.begin();
129 Date swapletStart = priceDate;
130 while (*nextFD < priceDate) ++nextFD;
135 QL_REQUIRE(noCVAArgs !=
nullptr,
"wrong argument type");
137 noCVAArgs->legs = this->arguments_.legs;
138 noCVAArgs->payer = this->arguments_.payer;
142 ext::shared_ptr<FixedRateCoupon> coupon = ext::dynamic_pointer_cast<FixedRateCoupon>(arguments_.legs[0][0]);
143 QL_REQUIRE(coupon,
"dynamic cast of fixed leg coupon failed.");
144 Rate baseSwapRate = coupon->rate();
147 QL_REQUIRE(vSResults !=
nullptr,
"wrong result type");
149 Rate baseSwapFairRate = -baseSwapRate * vSResults->legNPV[1] /
150 vSResults->legNPV[0];
151 Real baseSwapNPV = vSResults->value;
156 while(nextFD != arguments_.fixedPayDates.end()) {
158 ext::shared_ptr<FloatingRateCoupon> floatCoupon = ext::dynamic_pointer_cast<FloatingRateCoupon>(arguments_.legs[1][0]);
159 QL_REQUIRE(floatCoupon,
"dynamic cast of floating leg coupon failed.");
160 ext::shared_ptr<IborIndex> swapIndex = ext::dynamic_pointer_cast<IborIndex>(floatCoupon->index());
161 QL_REQUIRE(swapIndex,
"dynamic cast of floating leg index failed.");
167 Period baseSwapsTenor(arguments_.fixedPayDates.back().serialNumber()
191 ext::make_shared<EuropeanExercise>(swapletStart));
193 ext::make_shared<EuropeanExercise>(swapletStart));
199 cumOptVal += swaptionlet.
NPV() *
defaultTS_->defaultProbability(
200 swapletStart, *nextFD);
201 cumPutVal += putSwaplet.
NPV() *
invstDTS_->defaultProbability(
202 swapletStart, *nextFD);
204 swapletStart = *nextFD;
211 results_.fairRate = -baseSwapRate * (vSResults->legNPV[1]
214 / vSResults->legNPV[0];
Black-formula swaption engine.
const YieldTermStructure & discountCurve_
const Instrument::results * results_
Shifted Lognormal Black-formula swaption engine.
Handle< YieldTermStructure > discountCurve_
Handle< PricingEngine > swaptionletEngine_
Handle< DefaultProbabilityTermStructure > invstDTS_
Handle< PricingEngine > baseSwapEngine_
void calculate() const override
Handle< DefaultProbabilityTermStructure > defaultTS_
CounterpartyAdjSwapEngine(const Handle< YieldTermStructure > &discountCurve, const Handle< PricingEngine > &swaptionEngine, const Handle< DefaultProbabilityTermStructure > &ctptyDTS, Real ctptyRecoveryRate, const Handle< DefaultProbabilityTermStructure > &invstDTS=Handle< DefaultProbabilityTermStructure >(), Real invstRecoveryRate=0.999)
Date::serial_type serialNumber() const
Default probability term structure.
Discounting engine for swaps.
Shared handle to an observable.
Real NPV() const
returns the net present value of the instrument.
void setPricingEngine(const ext::shared_ptr< PricingEngine > &)
set the pricing engine to be used.
MakeVanillaSwap & withEffectiveDate(const Date &)
MakeVanillaSwap & withTerminationDate(const Date &)
MakeVanillaSwap & withNominal(Real n)
MakeVanillaSwap & withType(Swap::Type type)
Calendar for reproducing theoretical calculations.
template class providing a null value for a given type.
interface for pricing engines
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Option exercise classes and payoff function.
Coupon paying a fixed annual rate.
flat hazard-rate term structure
Coupon paying a variable index-based rate.
Real Volatility
volatility
base class for Inter-Bank-Offered-Rate indexes
Helper class to instantiate standard market swaps.
Calendar for reproducing theoretical calculations.