Coverage Report

Created: 2026-01-25 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/termstructures/volatility/equityfx/localconstantvol.hpp
Line
Count
Source
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
 <https://www.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
27
#include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
28
#include <ql/termstructures/volatility/equityfx/localvoltermstructure.hpp>
29
#include <utility>
30
31
namespace 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
    */
40
    class LocalConstantVol : public LocalVolTermStructure {
41
      public:
42
        LocalConstantVol(const Date& referenceDate, Volatility volatility, DayCounter dayCounter);
43
        LocalConstantVol(const Date& referenceDate,
44
                         Handle<Quote> volatility,
45
                         DayCounter dayCounter);
46
        LocalConstantVol(Natural settlementDays,
47
                         const Calendar&,
48
                         Volatility volatility,
49
                         DayCounter dayCounter);
50
        LocalConstantVol(Natural settlementDays,
51
                         const Calendar&,
52
                         Handle<Quote> volatility,
53
                         DayCounter dayCounter);
54
        //! \name TermStructure interface
55
        //@{
56
0
        DayCounter dayCounter() const override { return dayCounter_; }
57
0
        Date maxDate() const override { return Date::maxDate(); }
58
        //@}
59
        //! \name VolatilityTermStructure interface
60
        //@{
61
0
        Real minStrike() const override { return QL_MIN_REAL; }
62
0
        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;
70
        Handle<Quote> volatility_;
71
        DayCounter dayCounter_;
72
    };
73
74
    // inline definitions
75
76
    inline LocalConstantVol::LocalConstantVol(const Date& referenceDate,
77
                                              Volatility volatility,
78
                                              DayCounter dayCounter)
79
0
    : LocalVolTermStructure(referenceDate),
80
0
      volatility_(ext::shared_ptr<Quote>(new SimpleQuote(volatility))),
81
0
      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)) {
88
        registerWith(volatility_);
89
    }
90
91
    inline LocalConstantVol::LocalConstantVol(Natural settlementDays,
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
99
    inline LocalConstantVol::LocalConstantVol(Natural settlementDays,
100
                                              const Calendar& calendar,
101
                                              Handle<Quote> volatility,
102
                                              DayCounter dayCounter)
103
    : LocalVolTermStructure(settlementDays, calendar), volatility_(std::move(volatility)),
104
      dayCounter_(std::move(dayCounter)) {
105
        registerWith(volatility_);
106
    }
107
108
0
    inline void LocalConstantVol::accept(AcyclicVisitor& v) {
109
0
        auto* v1 = dynamic_cast<Visitor<LocalConstantVol>*>(&v);
110
0
        if (v1 != nullptr)
111
0
            v1->visit(*this);
112
0
        else
113
0
            LocalVolTermStructure::accept(v);
114
0
    }
115
116
0
    inline Volatility LocalConstantVol::localVolImpl(Time, Real) const {
117
0
        return volatility_->value();
118
0
    }
119
120
}
121
122
123
#endif