Coverage Report

Created: 2025-10-14 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/termstructures/volatility/swaption/gaussian1dswaptionvolatility.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2015 Peter Caspers
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 gaussian1dswaptionvolatility.hpp
21
    \brief swaption volatility implied by a gaussian 1d model
22
*/
23
24
#ifndef quantlib_swaption_gaussian1d_swaption_volatility_hpp
25
#define quantlib_swaption_gaussian1d_swaption_volatility_hpp
26
27
#include <ql/termstructures/volatility/swaption/swaptionvolstructure.hpp>
28
#include <ql/time/period.hpp>
29
#include <ql/indexes/swapindex.hpp>
30
#include <ql/models/shortrate/onefactormodels/gaussian1dmodel.hpp>
31
#include <ql/pricingengines/swaption/gaussian1dswaptionengine.hpp>
32
33
namespace QuantLib {
34
35
class Quote;
36
37
class Gaussian1dSwaptionVolatility : public SwaptionVolatilityStructure {
38
  public:
39
    Gaussian1dSwaptionVolatility(const Calendar& cal,
40
                                 BusinessDayConvention bdc,
41
                                 ext::shared_ptr<SwapIndex> indexBase,
42
                                 const ext::shared_ptr<Gaussian1dModel>& model,
43
                                 const DayCounter& dc,
44
                                 ext::shared_ptr<Gaussian1dSwaptionEngine> swaptionEngine =
45
                                     ext::shared_ptr<Gaussian1dSwaptionEngine>());
46
    //@{
47
0
    Date maxDate() const override { return Date::maxDate(); }
48
    //@}
49
    //! \name VolatilityTermStructure interface
50
    //@{
51
0
    Real minStrike() const override { return 0.0; }
52
0
    Real maxStrike() const override { return QL_MAX_REAL; }
53
    //@}
54
    //! \name SwaptionVolatilityStructure interface
55
    //@{
56
0
    const Period& maxSwapTenor() const override { return maxSwapTenor_; }
57
    //@}
58
  protected:
59
    ext::shared_ptr<SmileSection> smileSectionImpl(const Date&, const Period&) const override;
60
    ext::shared_ptr<SmileSection> smileSectionImpl(Time, Time) const override;
61
    Volatility volatilityImpl(const Date&, const Period&, Rate) const override;
62
    Volatility volatilityImpl(Time, Time, Rate) const override;
63
64
  private:
65
    ext::shared_ptr<SwapIndex> indexBase_;
66
    ext::shared_ptr<Gaussian1dModel> model_;
67
    ext::shared_ptr<Gaussian1dSwaptionEngine> engine_;
68
    const Period maxSwapTenor_;
69
70
    class DateHelper {
71
      public:
72
0
        DateHelper(const TermStructure &ts, const Time t) : ts_(ts), t_(t) {}
73
0
        Real operator()(Real date) const {
74
0
            Date d1(static_cast<Date::serial_type>(date));
75
0
            Date d2(static_cast<Date::serial_type>(date) + 1);
76
0
            Real t1 = ts_.timeFromReference(d1) - t_;
77
0
            Real t2 = ts_.timeFromReference(d2) - t_;
78
0
            Real h = date - static_cast<Date::serial_type>(date);
79
0
            return h * t2 + (1.0 - h) * t1;
80
0
        }
81
0
        Real derivative(Real date) const {
82
            // use fwd difference to avoid dates before reference date
83
0
            return (operator()(date + 1E-6) - operator()(date)) * 1E6;
84
0
        }
85
        const TermStructure &ts_;
86
        const Time t_;
87
    };
88
};
89
}
90
91
#endif