39 class ImpliedCapVolHelper {
41 ImpliedCapVolHelper(
const CapFloor&,
42 Handle<YieldTermStructure> discountCurve,
52 ext::shared_ptr<SimpleQuote>
vol_;
56 ImpliedCapVolHelper::ImpliedCapVolHelper(
const CapFloor& cap,
57 Handle<YieldTermStructure> discountCurve,
62 vol_(ext::make_shared<SimpleQuote>(-1.0)) {
66 Handle<Quote> h(
vol_);
70 engine_ = ext::shared_ptr<PricingEngine>(
new
75 engine_ = ext::shared_ptr<PricingEngine>(
new
80 QL_FAIL(
"unknown VolatilityType (" << type <<
")");
84 cap.setupArguments(
engine_->getArguments());
87 dynamic_cast<const Instrument::results*
>(
engine_->getResults());
90 Real ImpliedCapVolHelper::operator()(Volatility x)
const {
91 if (x!=
vol_->value()) {
98 Real ImpliedCapVolHelper::derivative(Volatility x)
const {
99 if (x!=
vol_->value()) {
103 auto vega_ =
results_->additionalResults.find(
"vega");
105 "vega not provided");
106 return ext::any_cast<Real>(vega_->second);
115 case CapFloor::Floor:
116 return out <<
"Floor";
117 case CapFloor::Collar:
118 return out <<
"Collar";
126 std::vector<Rate> capRates,
127 std::vector<Rate> floorRates)
128 : type_(type), floatingLeg_(
std::move(floatingLeg)), capRates_(
std::move(capRates)),
129 floorRates_(
std::move(floorRates)) {
142 Leg::const_iterator i;
150 : type_(type), floatingLeg_(
std::move(floatingLeg)) {
151 QL_REQUIRE(!strikes.empty(),
"no strikes given");
163 QL_FAIL(
"only Cap/Floor types allowed in this constructor");
165 Leg::const_iterator i;
187 ext::shared_ptr<FloatingRateCoupon>
190 ext::shared_ptr<FloatingRateCoupon> lastFloatingCoupon =
191 ext::dynamic_pointer_cast<FloatingRateCoupon>(lastCF);
192 return lastFloatingCoupon;
197 io::ordinal(i+1) <<
" optionlet does not exist, only " <<
201 std::vector<Rate> cap, floor;
207 return ext::make_shared<CapFloor>(
type(), cf, cap, floor);
232 for (
Size i=0; i<
n; ++i) {
233 ext::shared_ptr<FloatingRateCoupon> coupon =
234 ext::dynamic_pointer_cast<FloatingRateCoupon>(
236 QL_REQUIRE(coupon,
"non-FloatingRateCoupon given");
252 Spread spread = coupon->spread();
253 Real gearing = coupon->gearing();
280 "number of start dates (" <<
startDates.size()
281 <<
") different from that of end dates ("
284 "number of start dates (" <<
startDates.size()
285 <<
") different from that of accrual times ("
289 "number of start dates (" <<
startDates.size()
290 <<
") different from that of cap rates ("
294 "number of start dates (" <<
startDates.size()
295 <<
") different from that of floor rates ("
298 "number of start dates (" <<
startDates.size()
299 <<
") different from that of gearings ("
302 "number of start dates (" <<
startDates.size()
303 <<
") different from that of spreads ("
306 "number of start dates (" <<
startDates.size()
307 <<
") different from that of nominals ("
310 "number of start dates (" <<
startDates.size()
311 <<
") different from that of forwards ("
316 bool includeSettlementDateFlows =
false;
319 includeSettlementDateFlows,
331 Real displacement)
const {
335 ImpliedCapVolHelper
f(*
this,
d, targetValue, displacement,
type);
339 return solver.
solve(
f, accuracy, guess, minVol, maxVol);
Maps any to either the boost or std implementation.
Bachelier-Black-formula cap/floor engine.
Black-formula cap/floor engine.
Handle< YieldTermStructure > discountCurve_
ext::shared_ptr< SimpleQuote > vol_
ext::shared_ptr< PricingEngine > engine_
const Instrument::results * results_
const YieldTermStructure & discountCurve_
Cash-flow analysis functions.
ext::shared_ptr< SimpleQuote > vol_
ext::shared_ptr< PricingEngine > engine_
const Instrument::results * results_
Arguments for cap/floor calculation
std::vector< Time > accrualTimes
std::vector< Rate > forwards
std::vector< Date > startDates
std::vector< Real > gearings
std::vector< Rate > floorRates
std::vector< ext::shared_ptr< InterestRateIndex > > indexes
std::vector< Real > nominals
std::vector< Date > endDates
std::vector< Rate > capRates
std::vector< Date > fixingDates
std::vector< Real > spreads
void validate() const override
Volatility impliedVolatility(Real price, const Handle< YieldTermStructure > &disc, 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 term volatility
ext::shared_ptr< CapFloor > optionlet(Size n) const
Returns the n-th optionlet as a new CapFloor with only one cash flow.
CapFloor(Type type, Leg floatingLeg, std::vector< Rate > capRates, std::vector< Rate > floorRates)
void setupArguments(PricingEngine::arguments *) const override
bool isExpired() const override
returns whether the instrument might have value greater than zero.
const std::vector< Rate > & capRates() const
const Leg & floatingLeg() const
void deepUpdate() override
ext::shared_ptr< FloatingRateCoupon > lastFloatingRateCoupon() const
Rate atmRate(const YieldTermStructure &discountCurve) const
Date maturityDate() const
const std::vector< Rate > & floorRates() const
std::vector< Rate > capRates_
std::vector< Rate > floorRates_
static Date maturityDate(const Leg &leg)
static Date startDate(const Leg &leg)
static Rate atmRate(const Leg &leg, const YieldTermStructure &discountCurve, bool includeSettlementDateFlows, Date settlementDate=Date(), Date npvDate=Date(), Real npv=Null< Real >())
At-the-money rate of the cash flows.
Shared handle to an observable.
template class providing a null value for a given type.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
DateProxy & evaluationDate()
the date at which pricing is to be performed.
static Settings & instance()
access to the unique instance
void setMaxEvaluations(Size evaluations)
Real solve(const F &f, Real accuracy, Real guess, Real step) const
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
Interest-rate term structure.
#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)
detail::ordinal_holder ordinal(Size)
outputs naturals as 1st, 2nd, 3rd...
unsigned QL_INTEGER Natural
positive integer
Real Volatility
volatility
QL_INTEGER Integer
integer number
Real Spread
spreads on interest rates
std::size_t Size
size of a container
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Safe (bracketed) Newton 1-D solver.
Interest-rate term structure.