Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
proxyoptionletvolatility.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
25
26#include <ql/cashflows/averagebmacoupon.hpp>
27#include <ql/indexes/iborindex.hpp>
28#include <ql/termstructures/volatility/smilesection.hpp>
29
30namespace QuantExt {
31
32using namespace QuantLib;
33
34namespace {
35
36bool isOis(const QuantLib::ext::shared_ptr<IborIndex>& index) {
37 return QuantLib::ext::dynamic_pointer_cast<QuantLib::OvernightIndex>(index) != nullptr;
38}
39
40bool isBMA(const QuantLib::ext::shared_ptr<IborIndex>& index) {
41 return QuantLib::ext::dynamic_pointer_cast<QuantExt::BMAIndexWrapper>(index) != nullptr;
42}
43
44} // namespace
45
46ProxyOptionletVolatility::ProxyOptionletVolatility(const Handle<OptionletVolatilityStructure>& baseVol,
47 const QuantLib::ext::shared_ptr<IborIndex>& baseIndex,
48 const QuantLib::ext::shared_ptr<IborIndex>& targetIndex,
49 const Period& baseRateComputationPeriod,
50 const Period& targetRateComputationPeriod)
51 : OptionletVolatilityStructure(baseVol->businessDayConvention(), baseVol->dayCounter()), baseVol_(baseVol),
52 baseIndex_(baseIndex), targetIndex_(targetIndex), baseRateComputationPeriod_(baseRateComputationPeriod),
53 targetRateComputationPeriod_(targetRateComputationPeriod) {
54
55 QL_REQUIRE(baseIndex != nullptr, "ProxyOptionletVolatility: no base index given.");
56 QL_REQUIRE(targetIndex != nullptr, "ProxyOptionletVolatility: no target index given.");
57 QL_REQUIRE((!isOis(targetIndex_) && !isBMA(targetIndex)) || targetRateComputationPeriod != 0 * Days,
58 "ProxyOptionletVolatility: target index is OIS or BMA/SIFMA ("
59 << targetIndex->name() << "), so targetRateComputationPeriod must be given and != 0D.");
60 QL_REQUIRE((!isOis(baseIndex_) && !isBMA(baseIndex_)) || baseRateComputationPeriod != 0 * Days,
61 "ProxyOptionletVolatility: base index is OIS or BMA/SIFMA ("
62 << baseIndex->name() << "), so baseRateComputationPeriod must be given and != 0D.");
63 registerWith(baseVol_);
64 registerWith(baseIndex_);
65 registerWith(targetIndex_);
66 enableExtrapolation(baseVol->allowsExtrapolation());
67}
68
69QuantLib::ext::shared_ptr<QuantLib::SmileSection> ProxyOptionletVolatility::smileSectionImpl(QuantLib::Time optionTime) const {
70 // imply a fixing date from the optionTime
71 Date fixingDate = lowerDate(optionTime, referenceDate(), dayCounter());
72 return smileSectionImpl(fixingDate);
73}
74
75QuantLib::ext::shared_ptr<SmileSection> ProxyOptionletVolatility::smileSectionImpl(const Date& fixingDate) const {
76
77 // compute the base and target forward rate levels
78
79 Real baseAtmLevel;
80 if (isOis(baseIndex_))
81 baseAtmLevel = getOisAtmLevel(QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(baseIndex_),
82 baseIndex_->fixingCalendar().adjust(fixingDate), baseRateComputationPeriod_);
83 else if (isBMA(baseIndex_))
84 baseAtmLevel = getBMAAtmLevel(QuantLib::ext::dynamic_pointer_cast<BMAIndexWrapper>(baseIndex_)->bma(),
85 baseIndex_->fixingCalendar().adjust(fixingDate), baseRateComputationPeriod_);
86 else
87 baseAtmLevel = baseIndex_->fixing(baseIndex_->fixingCalendar().adjust(fixingDate));
88
89 Real targetAtmLevel;
90 if (isOis(targetIndex_))
91 targetAtmLevel =
92 getOisAtmLevel(QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(targetIndex_),
93 targetIndex_->fixingCalendar().adjust(fixingDate), targetRateComputationPeriod_);
94 else if (isBMA(targetIndex_))
95 targetAtmLevel =
96 getBMAAtmLevel(QuantLib::ext::dynamic_pointer_cast<BMAIndexWrapper>(targetIndex_)->bma(),
97 targetIndex_->fixingCalendar().adjust(fixingDate), targetRateComputationPeriod_);
98 else
99 targetAtmLevel = targetIndex_->fixing(targetIndex_->fixingCalendar().adjust(fixingDate));
100
101 // build the atm-adjusted smile section and return it
102
103 QL_REQUIRE(!baseVol_.empty(), "ProxyOptionletVolatility: no base vol given.");
104 return QuantLib::ext::make_shared<AtmAdjustedSmileSection>(baseVol_->smileSection(fixingDate, true), baseAtmLevel,
105 targetAtmLevel);
106}
107
108Volatility ProxyOptionletVolatility::volatilityImpl(Time optionTime, Rate strike) const {
109 return smileSection(optionTime)->volatility(strike);
110}
111
112} // namespace QuantExt
wrapper class for bmaindex, for the purpose of providing iborindex inheritance.
QuantLib::ext::shared_ptr< QuantLib::IborIndex > baseIndex_
QuantLib::Handle< QuantLib::OptionletVolatilityStructure > baseVol_
QuantLib::Volatility volatilityImpl(QuantLib::Time optionTime, QuantLib::Rate strike) const override
QuantLib::ext::shared_ptr< QuantLib::IborIndex > targetIndex_
QuantLib::ext::shared_ptr< QuantLib::SmileSection > smileSectionImpl(const QuantLib::Date &optionDate) const override
ProxyOptionletVolatility(const QuantLib::Handle< OptionletVolatilityStructure > &baseVol, const QuantLib::ext::shared_ptr< QuantLib::IborIndex > &baseIndex, const QuantLib::ext::shared_ptr< QuantLib::IborIndex > &targetIndex, const QuantLib::Period &baseRateComputationPeriod=0 *QuantLib::Days, const QuantLib::Period &targetRateComputationPeriod=0 *QuantLib::Days)
const QuantLib::Date & referenceDate() const override
Real getOisAtmLevel(const QuantLib::ext::shared_ptr< OvernightIndex > &on, const Date &fixingDate, const Period &rateComputationPeriod)
Definition: cashflows.cpp:29
QuantLib::Date lowerDate(const Real t, const QuantLib::Date &refDate, const QuantLib::DayCounter &dc)
Definition: time.cpp:66
Real getBMAAtmLevel(const QuantLib::ext::shared_ptr< BMAIndex > &bma, const Date &fixingDate, const Period &rateComputationPeriod)
Definition: cashflows.cpp:41
coupon paying the compounded daily overnight rate, copy of QL class, added includeSpread flag
moneyness-adjusted optionlet vol for normal vols
time related utilities.
some cashflow related utilities.