Coverage Report

Created: 2025-08-11 06:28

/src/quantlib/ql/termstructures/volatility/swaption/gaussian1dswaptionvolatility.cpp
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 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
 <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
#include <ql/math/solvers1d/newtonsafe.hpp>
21
#include <ql/termstructures/volatility/gaussian1dsmilesection.hpp>
22
#include <ql/termstructures/volatility/swaption/gaussian1dswaptionvolatility.hpp>
23
#include <utility>
24
25
namespace QuantLib {
26
27
    Gaussian1dSwaptionVolatility::Gaussian1dSwaptionVolatility(
28
        const Calendar& cal,
29
        BusinessDayConvention bdc,
30
        ext::shared_ptr<SwapIndex> indexBase,
31
        const ext::shared_ptr<Gaussian1dModel>& model,
32
        const DayCounter& dc,
33
        ext::shared_ptr<Gaussian1dSwaptionEngine> swaptionEngine)
34
0
    : SwaptionVolatilityStructure(model->termStructure()->referenceDate(), cal, bdc, dc),
35
0
      indexBase_(std::move(indexBase)), model_(model), engine_(std::move(swaptionEngine)),
36
0
      maxSwapTenor_(100 * Years) {}
Unexecuted instantiation: QuantLib::Gaussian1dSwaptionVolatility::Gaussian1dSwaptionVolatility(QuantLib::Calendar const&, QuantLib::BusinessDayConvention, boost::shared_ptr<QuantLib::SwapIndex>, boost::shared_ptr<QuantLib::Gaussian1dModel> const&, QuantLib::DayCounter const&, boost::shared_ptr<QuantLib::Gaussian1dSwaptionEngine>)
Unexecuted instantiation: QuantLib::Gaussian1dSwaptionVolatility::Gaussian1dSwaptionVolatility(QuantLib::Calendar const&, QuantLib::BusinessDayConvention, boost::shared_ptr<QuantLib::SwapIndex>, boost::shared_ptr<QuantLib::Gaussian1dModel> const&, QuantLib::DayCounter const&, boost::shared_ptr<QuantLib::Gaussian1dSwaptionEngine>)
37
38
    ext::shared_ptr<SmileSection>
39
0
    Gaussian1dSwaptionVolatility::smileSectionImpl(const Date& d, const Period& tenor) const {
40
0
        ext::shared_ptr<SmileSection> tmp = ext::make_shared<Gaussian1dSmileSection>(
41
0
            d, indexBase_->clone(tenor), model_, this->dayCounter(), engine_);
42
0
        return tmp;
43
0
}
44
45
ext::shared_ptr<SmileSection>
46
Gaussian1dSwaptionVolatility::smileSectionImpl(Time optionTime,
47
0
                                               Time swapLength) const {
48
0
    DateHelper hlp(*this, optionTime);
49
0
    NewtonSafe newton;
50
0
    Date d(static_cast<Date::serial_type>(newton.solve(
51
0
        hlp, 0.1,
52
0
        365.25 * optionTime + static_cast<Real>(referenceDate().serialNumber()),
53
0
        1.0)));
54
0
    Period tenor(
55
0
        static_cast<Integer>(Rounding(0)(swapLength * 12.0)),
56
0
        Months);
57
0
    d = indexBase_->fixingCalendar().adjust(d);
58
0
    return smileSectionImpl(d, tenor);
59
0
}
60
61
Volatility Gaussian1dSwaptionVolatility::volatilityImpl(const Date &d,
62
                                                        const Period &tenor,
63
0
                                                        Rate strike) const {
64
0
    return smileSectionImpl(d, tenor)->volatility(strike);
65
0
}
66
67
Volatility Gaussian1dSwaptionVolatility::volatilityImpl(Time optionTime,
68
                                                        Time swapLength,
69
0
                                                        Rate strike) const {
70
0
    return smileSectionImpl(optionTime, swapLength)->volatility(strike);
71
0
}
72
}