QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
vannavolgainterpolation.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2013 Yue Tian
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy 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
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
24#ifndef quantlib_vanna_volga_interpolation_hpp
25#define quantlib_vanna_volga_interpolation_hpp
26
27#include <ql/math/interpolation.hpp>
28#include <ql/pricingengines/blackformula.hpp>
29#include <ql/math/distributions/normaldistribution.hpp>
30#include <vector>
31
32namespace QuantLib {
33
34 namespace detail {
35 template<class I1, class I2> class VannaVolgaInterpolationImpl;
36 }
37
40 public:
42 template <class I1, class I2>
43 VannaVolgaInterpolation(const I1& xBegin, const I1& xEnd,
44 const I2& yBegin,
45 Real spot,
46 DiscountFactor dDiscount,
47 DiscountFactor fDiscount,
48 Time T) {
49 impl_ = ext::make_shared<
51 xBegin, xEnd, yBegin,
52 spot, dDiscount, fDiscount, T);
53 impl_->update();
54 }
55 };
56
58 class VannaVolga {
59 public:
61 DiscountFactor dDiscount,
62 DiscountFactor fDiscount,
63 Time T)
64 :spot_(spot), dDiscount_(dDiscount), fDiscount_(fDiscount), T_(T)
65 {}
66 template <class I1, class I2>
67 Interpolation interpolate(const I1& xBegin, const I1& xEnd,
68 const I2& yBegin) const {
69 return VannaVolgaInterpolation(xBegin, xEnd, yBegin, spot_, dDiscount_, fDiscount_, T_);
70 }
71 static const Size requiredPoints = 3;
72 private:
77 };
78
79 namespace detail {
80
81 template <class I1, class I2>
83 : public Interpolation::templateImpl<I1,I2> {
84 public:
85 VannaVolgaInterpolationImpl(const I1& xBegin, const I1& xEnd,
86 const I2& yBegin,
87 Real spot,
88 DiscountFactor dDiscount,
89 DiscountFactor fDiscount,
90 Time T)
91 : Interpolation::templateImpl<I1,I2>(xBegin, xEnd, yBegin,
92 VannaVolga::requiredPoints),
93 spot_(spot), dDiscount_(dDiscount), fDiscount_(fDiscount), T_(T) {
94 QL_REQUIRE(this->xEnd_-this->xBegin_ == 3,
95 "Vanna Volga Interpolator only interpolates 3 volatilities in strike space");
96 }
97 void update() override {
98 //atmVol should be the second vol
99 atmVol_ = this->yBegin_[1];
101 for(Size i = 0; i < 3; i++){
102 premiaBS.push_back(blackFormula(Option::Call, this->xBegin_[i], fwd_, atmVol_ * std::sqrt(T_), dDiscount_));
103 premiaMKT.push_back(blackFormula(Option::Call, this->xBegin_[i], fwd_, this->yBegin_[i] * std::sqrt(T_), dDiscount_));
104 vegas.push_back(vega(this->xBegin_[i]));
105 }
106 }
107 Real value(Real k) const override {
108 Real x1 = vega(k)/vegas[0]
109 * (std::log(this->xBegin_[1]/k) * std::log(this->xBegin_[2]/k))
110 / (std::log(this->xBegin_[1]/this->xBegin_[0]) * std::log(this->xBegin_[2]/this->xBegin_[0]));
111 Real x2 = vega(k)/vegas[1]
112 * (std::log(k/this->xBegin_[0]) * std::log(this->xBegin_[2]/k))
113 / (std::log(this->xBegin_[1]/this->xBegin_[0]) * std::log(this->xBegin_[2]/this->xBegin_[1]));
114 Real x3 = vega(k)/vegas[2]
115 * (std::log(k/this->xBegin_[0]) * std::log(k/this->xBegin_[1]))
116 / (std::log(this->xBegin_[2]/this->xBegin_[0]) * std::log(this->xBegin_[2]/this->xBegin_[1]));
117
118 Real cBS = blackFormula(Option::Call, k, fwd_, atmVol_ * std::sqrt(T_), dDiscount_);
119 Real c = cBS + x1*(premiaMKT[0] - premiaBS[0]) + x2*(premiaMKT[1] - premiaBS[1]) + x3*(premiaMKT[2] - premiaBS[2]);
121 return std / sqrt(T_);
122 }
123 Real primitive(Real) const override {
124 QL_FAIL("Vanna Volga primitive not implemented");
125 }
126 Real derivative(Real) const override {
127 QL_FAIL("Vanna Volga derivative not implemented");
128 }
129 Real secondDerivative(Real) const override {
130 QL_FAIL("Vanna Volga secondDerivative not implemented");
131 }
132
133 private:
134 std::vector<Real> premiaBS;
135 std::vector<Real> premiaMKT;
136 std::vector<Real> vegas;
143
144 Real vega(Real k) const {
145 Real d1 = (std::log(fwd_/k) + 0.5 * std::pow(atmVol_, 2.0) * T_)/(atmVol_ * std::sqrt(T_));
147 return spot_ * dDiscount_ * std::sqrt(T_) * norm(d1);
148 }
149 };
150
151 }
152
153}
154
155#endif
basic template implementation
templateImpl(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, const int requiredPoints=2)
base class for 1-D interpolations.
ext::shared_ptr< Impl > impl_
Normal distribution function.
VannaVolga-interpolation factory and traits
VannaVolga(Real spot, DiscountFactor dDiscount, DiscountFactor fDiscount, Time T)
static const Size requiredPoints
Interpolation interpolate(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin) const
Vanna Volga interpolation between discrete points
VannaVolgaInterpolation(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, Real spot, DiscountFactor dDiscount, DiscountFactor fDiscount, Time T)
VannaVolgaInterpolationImpl(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, Real spot, DiscountFactor dDiscount, DiscountFactor fDiscount, Time T)
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
Real blackFormulaImpliedStdDev(Option::Type optionType, Real strike, Real forward, Real blackPrice, Real discount, Real displacement, Real guess, Real accuracy, Natural maxIterations)
Real blackFormula(Option::Type optionType, Real strike, Real forward, Real stdDev, Real discount, Real displacement)
STL namespace.