1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4Copyright (C) 2018 Sebastian Schlenkrich
5
6This file is part of QuantLib, a free-software/open-source library
7for financial quantitative analysts and developers - http://quantlib.org/
8
9QuantLib is free software: you can redistribute it and/or modify it
10under the terms of the QuantLib license. You should have received a
11copy of the license along with this program; if not, please email
12<quantlib-dev@lists.sf.net>. The license is also available online at
13<http://quantlib.org/license.shtml>.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20/*! \file tenoroptionletvts.hpp
21 \brief caplet volatility term structure based on volatility transformation
22*/
23
24#ifndef quantlib_tenoroptionletvts_hpp
25#define quantlib_tenoroptionletvts_hpp
26
27#include <ql/indexes/iborindex.hpp>
28#include <ql/math/interpolation.hpp>
29#include <ql/termstructures/volatility/optionlet/optionletvolatilitystructure.hpp>
30#include <ql/termstructures/volatility/smilesection.hpp>
31#include <ql/time/dategenerationrule.hpp>
32#include <utility>
33
34
35namespace QuantLib {
36
37 class TenorOptionletVTS : public OptionletVolatilityStructure {
38
39 public:
40 class CorrelationStructure; // declaration below
41
42 protected:
43 class TenorOptionletSmileSection : public SmileSection {
44 protected:
45 ext::shared_ptr<CorrelationStructure> correlation_;
46 std::vector<ext::shared_ptr<SmileSection> > baseSmileSection_;
47 std::vector<Time> startTimeBase_; // for correlation parametrisation
48 std::vector<Real> fraRateBase_;
49 Real fraRateTarg_;
50 std::vector<Real> v_;
51 // implement transformation formula
52 Volatility volatilityImpl(Rate strike) const override;
53
54 public:
55 // constructor includes actual transformation details
56 TenorOptionletSmileSection(const TenorOptionletVTS& volTS, Time optionTime);
57
58 // further SmileSection interface methods
59 Real minStrike() const override {
60 return baseSmileSection_[0]->minStrike() + fraRateTarg_ - fraRateBase_[0];
61 }
62 Real maxStrike() const override {
63 return baseSmileSection_[0]->maxStrike() + fraRateTarg_ - fraRateBase_[0];
64 }
65 Real atmLevel() const override { return fraRateTarg_; }
66 };
67
68 Handle<OptionletVolatilityStructure> baseVTS_;
69 ext::shared_ptr<IborIndex> baseIndex_;
70 ext::shared_ptr<IborIndex> targIndex_;
71 ext::shared_ptr<CorrelationStructure> correlation_;
72
73 public:
74 // functor interface for parametric correlation
75 class CorrelationStructure {
76 public:
77 // return the correlation between two FRA rates starting at start1 and start2
78 virtual Real operator()(const Time& start1, const Time& start2) const = 0;
79 virtual ~CorrelationStructure() = default;
80 ;
81 };
82
83 // very basic choice for correlation structure
84 class TwoParameterCorrelation : public CorrelationStructure {
85 protected:
86 ext::shared_ptr<Interpolation> rhoInf_;
87 ext::shared_ptr<Interpolation> beta_;
88
89 public:
90 TwoParameterCorrelation(ext::shared_ptr<Interpolation> rhoInf,
91 ext::shared_ptr<Interpolation> beta)
92 : rhoInf_(std::move(rhoInf)), beta_(std::move(beta)) {}
93 Real operator()(const Time& start1, const Time& start2) const override {
94 Real rhoInf = (*rhoInf_)(start1);
95 Real beta = (*beta_)(start1);
96 Real rho = rhoInf + (1.0 - rhoInf) * exp(x: -beta * fabs(x: start2 - start1));
97 return rho;
98 }
99 };
100
101 // constructor
102 TenorOptionletVTS(const Handle<OptionletVolatilityStructure>& baseVTS,
103 ext::shared_ptr<IborIndex> baseIndex,
104 ext::shared_ptr<IborIndex> targIndex,
105 ext::shared_ptr<CorrelationStructure> correlation);
106
107 // Termstructure interface
108
109 //! the latest date for which the curve can return values
110 Date maxDate() const override { return baseVTS_->maxDate(); }
111
112 // VolatilityTermstructure interface
113
114 //! implements the actual smile calculation in derived classes
115 ext::shared_ptr<SmileSection> smileSectionImpl(Time optionTime) const override {
116 return ext::shared_ptr<SmileSection>(new TenorOptionletSmileSection(*this, optionTime));
117 }
118 //! implements the actual volatility calculation in derived classes
119 Volatility volatilityImpl(Time optionTime, Rate strike) const override {
120 return smileSection(optionTime)->volatility(strike);
121 }
122
123
124 //! the minimum strike for which the term structure can return vols
125 Rate minStrike() const override { return baseVTS_->minStrike(); }
126 //! the maximum strike for which the term structure can return vols
127 Rate maxStrike() const override { return baseVTS_->maxStrike(); }
128
129 // the methodology is designed for normal volatilities
130 VolatilityType volatilityType() const override { return Normal; }
131 };
132
133 typedef TenorOptionletVTS::CorrelationStructure TenorOptionletVTSCorrelationStructure;
134
135}
136
137#endif
138

source code of quantlib/ql/experimental/basismodels/tenoroptionletvts.hpp