QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
impliedvoltermstructure.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2003 Ferdinando Ametrano
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_implied_vol_term_structure_hpp
25#define quantlib_implied_vol_term_structure_hpp
26
27#include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp>
28#include <utility>
29
30namespace QuantLib {
31
33
44 public:
47
48 DayCounter dayCounter() const override { return originalTS_->dayCounter(); }
49 Date maxDate() const override;
51
53 Real minStrike() const override;
54 Real maxStrike() const override;
56
58 void accept(AcyclicVisitor&) override;
60 protected:
61 Real blackVarianceImpl(Time t, Real strike) const override;
62
63 private:
65 };
66
67
68 // inline definitions
69
71 Handle<BlackVolTermStructure> originalTS, const Date& referenceDate)
72 : BlackVarianceTermStructure(referenceDate), originalTS_(std::move(originalTS)) {
74 }
75
77 return originalTS_->maxDate();
78 }
79
81 return originalTS_->minStrike();
82 }
83
85 return originalTS_->maxStrike();
86 }
87
89 auto* v1 = dynamic_cast<Visitor<ImpliedVolTermStructure>*>(&v);
90 if (v1 != nullptr)
91 v1->visit(*this);
92 else
94 }
95
97 Real strike) const {
98 /* timeShift (and/or variance) variance at evaluation date
99 cannot be cached since the original curve could change
100 between invocations of this method */
101 Time timeShift =
102 dayCounter().yearFraction(originalTS_->referenceDate(),
103 referenceDate());
104 /* t is relative to the current reference date
105 and needs to be converted to the time relative
106 to the reference date of the original curve */
107 return originalTS_->blackForwardVariance(timeShift,
108 timeShift+t,
109 strike,
110 true);
111 }
112
113}
114
115#endif
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
void accept(AcyclicVisitor &) override
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Definition: daycounter.hpp:128
Shared handle to an observable.
Definition: handle.hpp:41
Implied vol term structure at a given date in the future.
ImpliedVolTermStructure(Handle< BlackVolTermStructure > origTS, const Date &referenceDate)
Real minStrike() const override
the minimum strike for which the term structure can return vols
void accept(AcyclicVisitor &) override
DayCounter dayCounter() const override
the day counter used for date/time conversion
Date maxDate() const override
the latest date for which the curve can return values
Real blackVarianceImpl(Time t, Real strike) const override
Black variance calculation.
Handle< BlackVolTermStructure > originalTS_
Real maxStrike() const override
the maximum strike for which the term structure can return vols
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
STL namespace.