38 class ImpliedSwaptionVolHelper {
40 ImpliedSwaptionVolHelper(
const Swaption&,
41 Handle<YieldTermStructure> discountCurve,
51 ext::shared_ptr<SimpleQuote>
vol_;
55 ImpliedSwaptionVolHelper::ImpliedSwaptionVolHelper(
const Swaption& swaption,
56 Handle<YieldTermStructure> discountCurve,
61 vol_(ext::make_shared<SimpleQuote>(-1.0)) {
66 Handle<Quote> h(
vol_);
70 engine_ = ext::make_shared<BlackSwaptionEngine>(
74 engine_ = ext::make_shared<BachelierSwaptionEngine>(
78 QL_FAIL(
"unknown VolatilityType (" << type <<
")");
81 swaption.setupArguments(
engine_->getArguments());
82 results_ =
dynamic_cast<const Instrument::results *
>(
86 Real ImpliedSwaptionVolHelper::operator()(Volatility x)
const {
87 if (x!=
vol_->value()) {
94 Real ImpliedSwaptionVolHelper::derivative(Volatility x)
const {
95 if (x!=
vol_->value()) {
99 auto vega_ =
results_->additionalResults.find(
"vega");
101 "vega not provided");
102 return ext::any_cast<Real>(vega_->second);
109 case Settlement::Physical:
110 return out <<
"Delivery";
111 case Settlement::Cash:
112 return out <<
"Cash";
120 case Settlement::PhysicalOTC:
121 return out <<
"PhysicalOTC";
122 case Settlement::PhysicalCleared:
123 return out <<
"PhysicalCleared";
124 case Settlement::CollateralizedCashPrice:
125 return out <<
"CollateralizedCashPrice";
126 case Settlement::ParYieldCurve:
127 return out <<
"ParYieldCurve";
133 Swaption::Swaption(ext::shared_ptr<FixedVsFloatingSwap> swap,
134 const ext::shared_ptr<Exercise>& exercise,
138 settlementType_(delivery), settlementMethod_(settlementMethod) {
148 swap_->alwaysForwardNotifications();
164 swap_->setupArguments(args);
190 Real displacement)
const {
194 ImpliedSwaptionVolHelper
f(*
this,
d, targetValue, displacement,
type);
198 return solver.
solve(
f, accuracy, guess, minVol, maxVol);
207 "invalid settlement method for physical settlement");
212 "invalid settlement method for cash settlement");
Maps any to either the boost or std implementation.
Black-formula swaption engine.
const YieldTermStructure & discountCurve_
ext::shared_ptr< SimpleQuote > vol_
ext::shared_ptr< PricingEngine > engine_
const Instrument::results * results_
virtual bool hasOccurred(const Date &refDate=Date(), ext::optional< bool > includeRefDate=ext::nullopt) const
returns true if an event has already occurred before a date
void validate() const override
Shared handle to an observable.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
ext::shared_ptr< Exercise > exercise
ext::shared_ptr< Exercise > exercise_
Abstract base class for option payoffs.
void setMaxEvaluations(Size evaluations)
Real solve(const F &f, Real accuracy, Real guess, Real step) const
Arguments for swaption calculation
ext::shared_ptr< FixedVsFloatingSwap > swap
Settlement::Method settlementMethod
Settlement::Type settlementType
void validate() const override
void setupArguments(PricingEngine::arguments *) const override
Settlement::Type settlementType() const
bool isExpired() const override
returns whether the instrument might have value greater than zero.
void deepUpdate() override
ext::shared_ptr< FixedVsFloatingSwap > swap_
Settlement::Method settlementMethod_
ext::shared_ptr< VanillaSwap > vanilla_
Volatility impliedVolatility(Real price, const Handle< YieldTermStructure > &discountCurve, Volatility guess, Real accuracy=1.0e-4, Natural maxEvaluations=100, Volatility minVol=1.0e-7, Volatility maxVol=4.0, VolatilityType type=ShiftedLognormal, Real displacement=0.0) const
implied volatility
Settlement::Method settlementMethod() const
Settlement::Type settlementType_
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Option exercise classes and payoff function.
unsigned QL_INTEGER Natural
positive integer
Real Volatility
volatility
QL_INTEGER Integer
integer number
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
void swap(Array &v, Array &w) noexcept
Safe (bracketed) Newton 1-D solver.
Maps shared_ptr to either the boost or std implementation.
static void checkTypeAndMethodConsistency(Settlement::Type, Settlement::Method)
check consistency of settlement type and method
Handle< YieldTermStructure > discountCurve_
ext::shared_ptr< SimpleQuote > vol_
ext::shared_ptr< PricingEngine > engine_
const Instrument::results * results_