23#include <ql/cashflows/floatingratecoupon.hpp>
24#include <ql/pricingengines/swaption/blackswaptionengine.hpp>
30 const std::string& baseCcy,
const std::map<std::string, Handle<YieldTermStructure>>& discountCurves,
31 const std::map<std::string, Handle<Quote>>& fxSpots,
const Handle<DefaultProbabilityTermStructure>& defaultCurve,
32 const Handle<Quote>& recoveryRate,
const Handle<SwaptionVolatilityStructure>& volatility,
33 const QuantLib::ext::shared_ptr<SwapIndex>& swapIndexBase,
const bool matchUnderlyingTenor,
const Real reversion,
34 const bool alwaysRecomputeOptionRepresentation,
const Size maxGapDays,
const Size maxDiscretisationPoints)
36 maxDiscretisationPoints),
37 volatility_(volatility), swapIndexBase_(swapIndexBase), matchUnderlyingTenor_(matchUnderlyingTenor),
38 reversion_(reversion), alwaysRecomputeOptionRepresentation_(alwaysRecomputeOptionRepresentation) {
46 "AnalyticBlackRiskParticipationAgreementEngine::calculate(): empty discount curve");
54 results_.optionRepresentationPeriods.clear();
55 results_.optionRepresentation.clear();
60 for (Size i = 0; i <
gridDates_.size() - 1; ++i) {
63 Date mid = start + (end - start) / 2;
67 results_.optionRepresentationPeriods.push_back(std::make_tuple(mid, start, end));
72 "AnalyticBlackRiskParticipationAgreementEngine::protectionLegNpv(): expected two underlying legs, got "
75 "AnalyticBlackRiskParticipationAgreementEngine::protectionLegNpv(): expected underlying legs in "
76 "samwe currency, got "
79 "AnalyticBlackRiskParticipationAgreementEngine::protectionLegNpv(): empty discount curve for ccy "
85 for (
auto const& e :
results_.optionRepresentationPeriods) {
87 std::get<0>(e), QuantExt::RepresentativeSwaptionMatcher::InclusionCriterion::PayDateGtExercise);
89 results_.optionRepresentation.push_back(swp);
92 results_.optionRepresentationReferenceDate =
arguments_.optionRepresentationReferenceDate;
96 results_.optionRepresentation.size() ==
results_.optionRepresentationPeriods.size(),
97 "AnalyticBlackRiskParticipationAgreementEngine::calculate(): inconsistent swaption representation periods");
102 QuantLib::ext::shared_ptr<PricingEngine> engine;
103 if (
volatility_->volatilityType() == ShiftedLognormal) {
110 for (
auto s :
results_.optionRepresentation) {
112 if (
auto tmp = QuantLib::ext::dynamic_pointer_cast<Swaption>(s)) {
113 s->setPricingEngine(engine);
115 QL_FAIL(
"AnalyticBlackRiskParticipationAgreementEngine::protectionLegNpv(): internal error, could not "
116 "cast representative instrument to Swaption");
124 "AnalyticBlackRiskParticipationAgreementEngine::protectionLegNpv(): empty fx spot for ccy pair "
128 std::vector<Real> optionPv(
results_.optionRepresentationPeriods.size(), 0.0);
129 for (Size i = 0; i <
results_.optionRepresentationPeriods.size(); ++i) {
130 if (
auto s =
results_.optionRepresentation[i]) {
132 std::get<2>(
results_.optionRepresentationPeriods[i]));
133 Real swpNpv = s ? s->NPV() : 0.0;
135 optionPv[i] = swpNpv;
141 QuantLib::ext::shared_ptr<PricingEngine> emptyEngine;
142 for (
auto s :
results_.optionRepresentation)
144 s->setPricingEngine(emptyEngine);
148 std::vector<Date> optionExerciseDates;
149 for (
auto const& e :
results_.optionRepresentationPeriods) {
150 optionExerciseDates.push_back(std::get<0>(e));
153 results_.additionalResults[
"OptionNpvs"] = optionPv;
155 results_.additionalResults[
"OptionExerciseDates"] = optionExerciseDates;
const Instrument::results * results_
boost::shared_ptr< Swaption > representativeSwaption(Date exerciseDate, const InclusionCriterion criterion=InclusionCriterion::AccrualStartGeqExercise)
const bool alwaysRecomputeOptionRepresentation_
const Handle< SwaptionVolatilityStructure > volatility_
AnalyticBlackRiskParticipationAgreementEngine(const std::string &baseCcy, const std::map< std::string, Handle< YieldTermStructure > > &discountCurves, const std::map< std::string, Handle< Quote > > &fxSpots, const Handle< DefaultProbabilityTermStructure > &defaultCurve, const Handle< Quote > &recoveryRate, const Handle< SwaptionVolatilityStructure > &volatility, const QuantLib::ext::shared_ptr< SwapIndex > &swapIndexBase, const bool matchUnderlyingTenor, const Real reversion, const bool alwaysRecomputeOptionRepresentation, const Size maxGapDays=Null< Size >(), const Size maxDiscretisationPoints=Null< Size >())
const QuantLib::ext::shared_ptr< SwapIndex > swapIndexBase_
Real protectionLegNpv() const override
const bool matchUnderlyingTenor_
Real effectiveRecoveryRate_
std::vector< Date > gridDates_
std::map< std::string, Handle< Quote > > fxSpots_
std::map< std::string, Handle< YieldTermStructure > > discountCurves_
Handle< DefaultProbabilityTermStructure > defaultCurve_
Serializable Credit Default Swap.
Swap::arguments * arguments_