QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
localconstantvol.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2002, 2003, 2004 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
20/*! \file localconstantvol.hpp
21 \brief Local constant volatility, no time dependence, no asset dependence
22*/
23
24#ifndef quantlib_localconstantvol_hpp
25#define quantlib_localconstantvol_hpp
26
29#include <utility>
30
31namespace QuantLib {
32
33 //! Constant local volatility, no time-strike dependence
34 /*! This class implements the LocalVolatilityTermStructure
35 interface for a constant local volatility (no time/asset
36 dependence). Local volatility and Black volatility are the
37 same when volatility is at most time dependent, so this class
38 is basically a proxy for BlackVolatilityTermStructure.
39 */
41 public:
44 Handle<Quote> volatility,
47 const Calendar&,
48 Volatility volatility,
51 const Calendar&,
52 Handle<Quote> volatility,
54 //! \name TermStructure interface
55 //@{
56 DayCounter dayCounter() const override { return dayCounter_; }
57 Date maxDate() const override { return Date::maxDate(); }
58 //@}
59 //! \name VolatilityTermStructure interface
60 //@{
61 Real minStrike() const override { return QL_MIN_REAL; }
62 Real maxStrike() const override { return QL_MAX_REAL; }
63 //@}
64 //! \name Visitability
65 //@{
66 void accept(AcyclicVisitor&) override;
67 //@}
68 private:
69 Volatility localVolImpl(Time, Real) const override;
72 };
73
74 // inline definitions
75
76 inline LocalConstantVol::LocalConstantVol(const Date& referenceDate,
77 Volatility volatility,
78 DayCounter dayCounter)
79 : LocalVolTermStructure(referenceDate),
80 volatility_(ext::shared_ptr<Quote>(new SimpleQuote(volatility))),
81 dayCounter_(std::move(dayCounter)) {}
82
83 inline LocalConstantVol::LocalConstantVol(const Date& referenceDate,
84 Handle<Quote> volatility,
85 DayCounter dayCounter)
86 : LocalVolTermStructure(referenceDate), volatility_(std::move(volatility)),
87 dayCounter_(std::move(dayCounter)) {
89 }
90
92 const Calendar& calendar,
93 Volatility volatility,
94 DayCounter dayCounter)
95 : LocalVolTermStructure(settlementDays, calendar),
96 volatility_(ext::shared_ptr<Quote>(new SimpleQuote(volatility))),
97 dayCounter_(std::move(dayCounter)) {}
98
100 const Calendar& calendar,
101 Handle<Quote> volatility,
102 DayCounter dayCounter)
103 : LocalVolTermStructure(settlementDays, calendar), volatility_(std::move(volatility)),
104 dayCounter_(std::move(dayCounter)) {
106 }
107
109 auto* v1 = dynamic_cast<Visitor<LocalConstantVol>*>(&v);
110 if (v1 != nullptr)
111 v1->visit(*this);
112 else
114 }
115
117 return volatility_->value();
118 }
119
120}
121
122
123#endif
Black constant volatility, no time dependence, no strike dependence.
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
static Date maxDate()
latest allowed date
Definition: date.cpp:771
day counter class
Definition: daycounter.hpp:44
Shared handle to an observable.
Definition: handle.hpp:41
Constant local volatility, no time-strike dependence.
Volatility localVolImpl(Time, Real) const override
local vol calculation
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
LocalConstantVol(const Date &referenceDate, Volatility volatility, DayCounter dayCounter)
Date maxDate() const override
the latest date for which the curve can return values
Real maxStrike() const override
the maximum strike for which the term structure can return vols
virtual void accept(AcyclicVisitor &)
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
purely virtual base class for market observables
Definition: quote.hpp:37
market element returning a stored value
Definition: simplequote.hpp:33
virtual Natural settlementDays() const
the settlementDays used for reference date calculation
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
#define QL_MAX_REAL
Definition: qldefines.hpp:176
#define QL_MIN_REAL
Definition: qldefines.hpp:175
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Volatility
volatility
Definition: types.hpp:78
Local volatility term structure base class.
Definition: any.hpp:35
STL namespace.
ext::shared_ptr< BlackVolTermStructure > v