40#include <ql/exercise.hpp>
41#include <ql/instruments/payoffs.hpp>
42#include <ql/math/distributions/normaldistribution.hpp>
43#include <ql/math/solvers1d/brent.hpp>
44#include <ql/quotes/simplequote.hpp>
45#include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
46#include <ql/termstructures/yieldtermstructure.hpp>
48#include <boost/make_shared.hpp>
55class ImpliedVolHelper {
57 ImpliedVolHelper(
const CdsOption& cdsoption,
const Handle<DefaultProbabilityTermStructure>& probability,
58 Real recoveryRate,
const Handle<YieldTermStructure>& termStructure, Real targetValue)
61 vol_ = QuantLib::ext::shared_ptr<SimpleQuote>(
new SimpleQuote(0.0));
62 Handle<BlackVolTermStructure> h(
63 QuantLib::ext::make_shared<BlackConstantVol>(0, NullCalendar(), Handle<Quote>(vol_), Actual365Fixed()));
64 engine_ = QuantLib::ext::shared_ptr<PricingEngine>(
66 Handle<CreditVolCurve>(QuantLib::ext::make_shared<CreditVolCurveWrapper>(h))));
67 cdsoption.setupArguments(
engine_->getArguments());
71 Real operator()(Volatility x)
const {
78 QuantLib::ext::shared_ptr<PricingEngine>
engine_;
80 QuantLib::ext::shared_ptr<SimpleQuote>
vol_;
85CdsOption::CdsOption(
const QuantLib::ext::shared_ptr<CreditDefaultSwap>& swap,
const QuantLib::ext::shared_ptr<Exercise>& exercise,
86 bool knocksOut,
const Real strike,
const StrikeType strikeType)
87 : Option(
QuantLib::ext::shared_ptr<
Payoff>(new NullPayoff), exercise), swap_(swap), knocksOut_(knocksOut),
88 strike_(strike == Null<Real>() ? swap_->runningSpread() : strike), strikeType_(strikeType) {
95 Instrument::setupExpired();
100 swap_->setupArguments(args);
101 Option::setupArguments(args);
105 QL_REQUIRE(
arguments != 0,
"wrong argument type");
114 Option::fetchResults(r);
116 QL_ENSURE(
results != 0,
"wrong results type");
124 QL_REQUIRE(
riskyAnnuity_ != Null<Real>(),
"risky annuity not provided");
129 const Handle<DefaultProbabilityTermStructure>& probability, Real recoveryRate,
130 Real accuracy, Size maxEvaluations, Volatility minVol,
131 Volatility maxVol)
const {
133 QL_REQUIRE(!
isExpired(),
"instrument expired");
135 Volatility guess = 0.10;
137 ImpliedVolHelper f(*
this, probability, recoveryRate, termStructure, targetValue);
139 solver.setMaxEvaluations(maxEvaluations);
140 return solver.solve(f, accuracy, guess, minVol, maxVol);
144 CreditDefaultSwap::arguments::validate();
145 Option::arguments::validate();
146 QL_REQUIRE(
swap,
"CDS not set");
147 QL_REQUIRE(exercise,
"exercise not set");
151 Option::results::reset();
Black credit default swap option engine.
QuantLib::ext::shared_ptr< PricingEngine > engine_
QuantLib::ext::shared_ptr< SimpleQuote > vol_
const Instrument::results * results_
CDS option, removed requirements (rec must knock out, no upfront amount), that should be taken care o...
Arguments for CDS-option calculation
QuantLib::ext::shared_ptr< CreditDefaultSwap > swap
void validate() const override
CdsOption(const QuantLib::ext::shared_ptr< CreditDefaultSwap > &swap, const QuantLib::ext::shared_ptr< Exercise > &exercise, bool knocksOut=true, const Real strike=Null< Real >(), const StrikeType strikeType=StrikeType::Spread)
Real riskyAnnuity() const
void setupArguments(PricingEngine::arguments *) const override
Volatility impliedVolatility(Real price, const Handle< QuantLib::YieldTermStructure > &termStructure, const Handle< DefaultProbabilityTermStructure > &, Real recoveryRate, Real accuracy=1.e-4, Size maxEvaluations=100, Volatility minVol=1.0e-7, Volatility maxVol=4.0) const
bool isExpired() const override
QuantLib::ext::shared_ptr< CreditDefaultSwap > swap_
void setupExpired() const override
void fetchResults(const PricingEngine::results *) const override