21#include <ql/exercise.hpp>
22#include <ql/instruments/payoffs.hpp>
23#include <ql/math/distributions/normaldistribution.hpp>
24#include <ql/math/solvers1d/brent.hpp>
25#include <ql/quotes/simplequote.hpp>
26#include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
27#include <ql/termstructures/yieldtermstructure.hpp>
28#include <boost/make_shared.hpp>
36class ImpliedVolHelper {
38 ImpliedVolHelper(
const IndexCdsOption& cdsoption,
const Handle<DefaultProbabilityTermStructure>& probability,
39 Real recoveryRate,
const Handle<YieldTermStructure>& termStructureSwapCurrency,
40 const Handle<YieldTermStructure>& termStructureTradeCollateral, Real targetValue)
43 vol_ = QuantLib::ext::shared_ptr<SimpleQuote>(
new SimpleQuote(0.0));
44 Handle<BlackVolTermStructure> h(
45 QuantLib::ext::make_shared<BlackConstantVol>(0, NullCalendar(), Handle<Quote>(vol_), Actual365Fixed()));
46 engine_ = QuantLib::ext::make_shared<QuantExt::BlackIndexCdsOptionEngine>(
47 probability, recoveryRate, termStructureSwapCurrency, termStructureTradeCollateral,
48 Handle<CreditVolCurve>(QuantLib::ext::make_shared<CreditVolCurveWrapper>(h)));
49 cdsoption.setupArguments(
engine_->getArguments());
53 Real operator()(Volatility x)
const {
60 QuantLib::ext::shared_ptr<PricingEngine>
engine_;
62 QuantLib::ext::shared_ptr<SimpleQuote>
vol_;
69 const QuantLib::ext::shared_ptr<Exercise>& exercise, Real strike,
71 Real tradeDateNtl, Real realisedFep,
const QuantLib::Period& indexTerm)
72 : Option(
QuantLib::ext::make_shared<NullPayoff>(), exercise), swap_(swap), strike_(strike), strikeType_(strikeType),
73 settlementType_(settlementType), tradeDateNtl_(tradeDateNtl), realisedFep_(realisedFep),
74 indexTerm_(indexTerm), riskyAnnuity_(0.0) {
81 Instrument::setupExpired();
86 swap_->setupArguments(args);
87 Option::setupArguments(args);
91 QL_REQUIRE(
arguments != 0,
"wrong argument type");
103 Option::fetchResults(r);
105 QL_ENSURE(
results != 0,
"wrong results type");
113 QL_REQUIRE(
riskyAnnuity_ != Null<Real>(),
"risky annuity not provided");
118 const Handle<YieldTermStructure>& termStructureSwapCurrency,
119 const Handle<YieldTermStructure>& termStructureTradeCollateral,
120 const Handle<DefaultProbabilityTermStructure>& probability,
121 Real recoveryRate, Real accuracy, Size maxEvaluations, Volatility minVol,
122 Volatility maxVol)
const {
124 QL_REQUIRE(!
isExpired(),
"instrument expired");
126 Volatility guess = 0.10;
128 ImpliedVolHelper f(*
this, probability, recoveryRate, termStructureSwapCurrency, termStructureTradeCollateral,
131 solver.setMaxEvaluations(maxEvaluations);
132 return solver.solve(f, accuracy, guess, minVol, maxVol);
136 IndexCreditDefaultSwap::arguments::validate();
137 Option::arguments::validate();
138 QL_REQUIRE(
swap,
"CDS not set");
139 QL_REQUIRE(exercise,
"exercise not set");
143 Option::results::reset();
Black index credit default swap option engine.
QuantLib::ext::shared_ptr< PricingEngine > engine_
QuantLib::ext::shared_ptr< SimpleQuote > vol_
const Instrument::results * results_
Arguments for index CDS option calculation
QuantLib::Period indexTerm
QuantLib::Real realisedFep
CdsOption::StrikeType strikeType
Settlement::Type settlementType
void validate() const override
QuantLib::Real tradeDateNtl
QuantLib::ext::shared_ptr< IndexCreditDefaultSwap > swap
Results from index CDS option calculation
QuantLib::Real riskyAnnuity
void setupArguments(QuantLib::PricingEngine::arguments *args) const override
QuantLib::Real riskyAnnuity() const
bool isExpired() const override
QuantLib::Volatility impliedVolatility(QuantLib::Real price, const QuantLib::Handle< QuantLib::YieldTermStructure > &termStructureSwapCurrency, const QuantLib::Handle< QuantLib::YieldTermStructure > &termStructureTradeCollateral, const QuantLib::Handle< QuantLib::DefaultProbabilityTermStructure > &, QuantLib::Real recoveryRate, QuantLib::Real accuracy=1.e-4, QuantLib::Size maxEvaluations=100, QuantLib::Volatility minVol=1.0e-7, QuantLib::Volatility maxVol=4.0) const
void fetchResults(const QuantLib::PricingEngine::results *results) const override
CdsOption::StrikeType strikeType_
QuantLib::Rate atmRate() const
QuantLib::ext::shared_ptr< IndexCreditDefaultSwap > swap_
QuantLib::Real realisedFep_
void setupExpired() const override
IndexCdsOption(const QuantLib::ext::shared_ptr< IndexCreditDefaultSwap > &swap, const QuantLib::ext::shared_ptr< QuantLib::Exercise > &exercise, QuantLib::Real strike, CdsOption::StrikeType strikeType_=CdsOption::Spread, Settlement::Type settlementType=Settlement::Cash, QuantLib::Real tradeDateNtl=QuantLib::Null< QuantLib::Real >(), QuantLib::Real realisedFep=QuantLib::Null< QuantLib::Real >(), const QuantLib::Period &indexTerm=5 *Years)
QuantLib::Real riskyAnnuity_
Settlement::Type settlementType_
QuantLib::Real tradeDateNtl_
QuantLib::Period indexTerm_
Index CDS option instrument.