Coverage Report

Created: 2025-08-05 06:45

/src/quantlib/ql/termstructures/volatility/equityfx/fixedlocalvolsurface.hpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2015 Johannes Göttker-Schnetmann
5
 Copyright (C) 2015 Klaus Spanderen
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 fixedlocalvolsurface.hpp
22
    \brief Local volatility surface based on fixed values plus interpolation
23
*/
24
25
#ifndef quantlib_fixed_local_vol_surface_hpp
26
#define quantlib_fixed_local_vol_surface_hpp
27
28
#include <ql/math/matrix.hpp>
29
#include <ql/math/interpolation.hpp>
30
#include <ql/math/interpolations/linearinterpolation.hpp>
31
32
#include <ql/termstructures/volatility/equityfx/localvoltermstructure.hpp>
33
34
namespace QuantLib {
35
36
    class FixedLocalVolSurface : public LocalVolTermStructure {
37
      public:
38
        enum Extrapolation { ConstantExtrapolation,
39
                             InterpolatorDefaultExtrapolation };
40
        FixedLocalVolSurface(const Date& referenceDate,
41
                             const std::vector<Date>& dates,
42
                             const std::vector<Real>& strikes,
43
                             ext::shared_ptr<Matrix> localVolMatrix,
44
                             const DayCounter& dayCounter,
45
                             Extrapolation lowerExtrapolation = ConstantExtrapolation,
46
                             Extrapolation upperExtrapolation = ConstantExtrapolation);
47
48
        FixedLocalVolSurface(const Date& referenceDate,
49
                             const std::vector<Time>& times,
50
                             const std::vector<Real>& strikes,
51
                             ext::shared_ptr<Matrix> localVolMatrix,
52
                             const DayCounter& dayCounter,
53
                             Extrapolation lowerExtrapolation = ConstantExtrapolation,
54
                             Extrapolation upperExtrapolation = ConstantExtrapolation);
55
56
        FixedLocalVolSurface(const Date& referenceDate,
57
                             const std::vector<Time>& times,
58
                             const std::vector<ext::shared_ptr<std::vector<Real> > >& strikes,
59
                             ext::shared_ptr<Matrix> localVolMatrix,
60
                             const DayCounter& dayCounter,
61
                             Extrapolation lowerExtrapolation = ConstantExtrapolation,
62
                             Extrapolation upperExtrapolation = ConstantExtrapolation);
63
64
65
        Date maxDate() const override;
66
        Time maxTime() const override;
67
        Real minStrike() const override;
68
        Real maxStrike() const override;
69
70
        template <class Interpolator>
71
0
        void setInterpolation(const Interpolator& i = Interpolator()) {
72
0
            for (Size j=0; j < times_.size(); ++j) {
73
0
                localVolInterpol_[j] = i.interpolate(
74
0
                    strikes_[j]->begin(), strikes_[j]->end(),
75
0
                    localVolMatrix_->column_begin(j));
76
0
            }
77
0
            notifyObservers();
78
0
        }
79
80
      protected:
81
        Volatility localVolImpl(Time t, Real strike) const override;
82
83
        const Date maxDate_;
84
        std::vector<Time> times_;
85
        const ext::shared_ptr<Matrix> localVolMatrix_;
86
        const std::vector<ext::shared_ptr<std::vector<Real> > > strikes_;
87
88
        std::vector<Interpolation> localVolInterpol_;
89
        Extrapolation lowerExtrapolation_, upperExtrapolation_;
90
91
      private:
92
        void checkSurface();
93
    };
94
}
95
96
#endif