Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
swaptionvolcubewithatm.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 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
19/*! \file qle/termstructures/swaptionvolcubewithatm.hpp
20 \brief Wrapper class for a SwaptionVolatilityCube that easily and efficiently exposes ATM vols.
21 \ingroup termstructures
22*/
23
24#ifndef quantext_swaptionvolcubewithatm_hpp
25#define quantext_swaptionvolcubewithatm_hpp
26
27#include <ql/termstructures/volatility/swaption/swaptionvolcube.hpp>
28
29#include <ql/shared_ptr.hpp>
30
31namespace QuantExt {
32using namespace QuantLib;
33
34//! Wrapper class for a SwaptionVolatilityCube that easily and efficiently exposes ATM vols.
35/*! This class implements SwaptionVolatilityStructure and takes a cube as an input. If asked for
36 a volatility with strike=Null<Real>() it will return the ATM vol by asking the ATM surface directly.
37 If asked for any other strike it will pass it on to the cube.
38
39 There is no calculation of ATM in this class.
40
41 \ingroup termstructures
42 */
43class SwaptionVolCubeWithATM : public SwaptionVolatilityStructure {
44public:
45 //! Constructor. This is a floating term structure (settlement days is zero) to match
46 //! QuantLib::SwaptionVolatilityCube
47 SwaptionVolCubeWithATM(const QuantLib::ext::shared_ptr<SwaptionVolatilityCube>& cube)
48 : SwaptionVolatilityStructure(0, cube->calendar(), cube->businessDayConvention(), cube->dayCounter()),
49 cube_(cube) {
50 enableExtrapolation(cube_->allowsExtrapolation());
51 registerWith(cube);
52 }
53
54 //! \name TermStructure interface
55 //@{
56 DayCounter dayCounter() const override { return cube_->dayCounter(); }
57 Date maxDate() const override { return cube_->maxDate(); }
58 Time maxTime() const override { return cube_->maxTime(); }
59 const Date& referenceDate() const override { return cube_->referenceDate(); }
60 Calendar calendar() const override { return cube_->calendar(); }
61 Natural settlementDays() const override { return cube_->settlementDays(); }
62 //! \name VolatilityTermStructure interface
63 //@{
64 Rate minStrike() const override { return cube_->minStrike(); }
65 Rate maxStrike() const override { return cube_->maxStrike(); }
66 //@}
67 //! \name SwaptionVolatilityStructure interface
68 //@{
69 const Period& maxSwapTenor() const override { return cube_->maxSwapTenor(); }
70 VolatilityType volatilityType() const override { return cube_->volatilityType(); }
71 //@}
72
73 QuantLib::ext::shared_ptr<SwaptionVolatilityCube> cube() const { return cube_; }
74
75protected:
76 // Nothing to do here, just ask the cube
77 QuantLib::ext::shared_ptr<SmileSection> smileSectionImpl(Time optionTime, Time swapLength) const override {
78 return cube_->smileSection(optionTime, swapLength);
79 }
80
81 // Here we check if strike is Null<Real>() and ask the ATM surface if so.
82 Volatility volatilityImpl(Time optionTime, Time swapLength, Rate strike) const override {
83 if (strike == Null<Real>()) {
84 return cube_->atmVol()->volatility(optionTime, swapLength, 0.0);
85 } else {
86 return cube_->volatility(optionTime, swapLength, strike);
87 }
88 }
89
90 Real shiftImpl(Time optionTime, Time swapLength) const override { return cube_->shift(optionTime, swapLength); }
91
92private:
93 QuantLib::ext::shared_ptr<SwaptionVolatilityCube> cube_;
94};
95
96} // namespace QuantExt
97
98#endif
Wrapper class for a SwaptionVolatilityCube that easily and efficiently exposes ATM vols.
QuantLib::ext::shared_ptr< SwaptionVolatilityCube > cube() const
Volatility volatilityImpl(Time optionTime, Time swapLength, Rate strike) const override
QuantLib::ext::shared_ptr< SwaptionVolatilityCube > cube_
QuantLib::ext::shared_ptr< SmileSection > smileSectionImpl(Time optionTime, Time swapLength) const override
const Date & referenceDate() const override
Real shiftImpl(Time optionTime, Time swapLength) const override
VolatilityType volatilityType() const override
DayCounter dayCounter() const override
const Period & maxSwapTenor() const override
SwaptionVolCubeWithATM(const QuantLib::ext::shared_ptr< SwaptionVolatilityCube > &cube)