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 Copyright (C) 2003, 2004, 2005, 2006, 2007 StatPro Italia srl
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21/*! \file blackconstantvol.hpp
22 \brief Black constant volatility, no time dependence, no strike dependence
23*/
24
25#ifndef quantlib_blackconstantvol_hpp
26#define quantlib_blackconstantvol_hpp
27
28#include <ql/quotes/simplequote.hpp>
29#include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp>
30#include <ql/time/daycounters/actual365fixed.hpp>
31#include <utility>
32
33namespace QuantLib {
34
35 //! Constant Black volatility, no time-strike dependence
36 /*! This class implements the BlackVolatilityTermStructure
37 interface for a constant Black volatility (no time/strike
38 dependence).
39 */
40 class BlackConstantVol : public BlackVolatilityTermStructure {
41 public:
42 BlackConstantVol(const Date& referenceDate,
43 const Calendar&,
44 Volatility volatility,
45 const DayCounter& dayCounter);
46 BlackConstantVol(const Date& referenceDate,
47 const Calendar&,
48 Handle<Quote> volatility,
49 const DayCounter& dayCounter);
50 BlackConstantVol(Natural settlementDays,
51 const Calendar&,
52 Volatility volatility,
53 const DayCounter& dayCounter);
54 BlackConstantVol(Natural settlementDays,
55 const Calendar&,
56 Handle<Quote> volatility,
57 const DayCounter& dayCounter);
58 //! \name TermStructure interface
59 //@{
60 Date maxDate() const override;
61 //@}
62 //! \name VolatilityTermStructure interface
63 //@{
64 Real minStrike() const override;
65 Real maxStrike() const override;
66 //@}
67 //! \name Visitability
68 //@{
69 void accept(AcyclicVisitor&) override;
70 //@}
71 protected:
72 Volatility blackVolImpl(Time t, Real) const override;
73
74 private:
75 Handle<Quote> volatility_;
76 };
77
78
79 // inline definitions
80
81 inline BlackConstantVol::BlackConstantVol(const Date& referenceDate,
82 const Calendar& cal,
83 Volatility volatility,
84 const DayCounter& dc)
85 : BlackVolatilityTermStructure(referenceDate, cal, Following, dc),
86 volatility_(ext::shared_ptr<Quote>(new SimpleQuote(volatility))) {}
87
88 inline BlackConstantVol::BlackConstantVol(const Date& referenceDate,
89 const Calendar& cal,
90 Handle<Quote> volatility,
91 const DayCounter& dc)
92 : BlackVolatilityTermStructure(referenceDate, cal, Following, dc),
93 volatility_(std::move(volatility)) {
94 registerWith(h: volatility_);
95 }
96
97 inline BlackConstantVol::BlackConstantVol(Natural settlementDays,
98 const Calendar& cal,
99 Volatility volatility,
100 const DayCounter& dc)
101 : BlackVolatilityTermStructure(settlementDays, cal, Following, dc),
102 volatility_(ext::shared_ptr<Quote>(new SimpleQuote(volatility))) {}
103
104 inline BlackConstantVol::BlackConstantVol(Natural settlementDays,
105 const Calendar& cal,
106 Handle<Quote> volatility,
107 const DayCounter& dc)
108 : BlackVolatilityTermStructure(settlementDays, cal, Following, dc),
109 volatility_(std::move(volatility)) {
110 registerWith(h: volatility_);
111 }
112
113 inline Date BlackConstantVol::maxDate() const {
114 return Date::maxDate();
115 }
116
117 inline Real BlackConstantVol::minStrike() const {
118 return QL_MIN_REAL;
119 }
120
121 inline Real BlackConstantVol::maxStrike() const {
122 return QL_MAX_REAL;
123 }
124
125 inline void BlackConstantVol::accept(AcyclicVisitor& v) {
126 auto* v1 = dynamic_cast<Visitor<BlackConstantVol>*>(&v);
127 if (v1 != nullptr)
128 v1->visit(*this);
129 else
130 BlackVolatilityTermStructure::accept(v);
131 }
132
133 inline Volatility BlackConstantVol::blackVolImpl(Time, Real) const {
134 return volatility_->value();
135 }
136
137}
138
139
140#endif
141

source code of quantlib/ql/termstructures/volatility/equityfx/blackconstantvol.hpp