Coverage Report

Created: 2026-02-03 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/models/shortrate/calibrationhelpers/swaptionhelper.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb
5
 Copyright (C) 2015 Peter Caspers
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
 <https://www.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 swaptionhelper.hpp
22
    \brief Swaption calibration helper
23
*/
24
25
#ifndef quantlib_swaption_calibration_helper_hpp
26
#define quantlib_swaption_calibration_helper_hpp
27
28
#include <ql/models/calibrationhelper.hpp>
29
#include <ql/instruments/swaption.hpp>
30
#include <ql/termstructures/volatility/volatilitytype.hpp>
31
#include <ql/cashflows/rateaveraging.hpp>
32
33
namespace QuantLib {
34
35
    //! calibration helper for interest-rate swaptions
36
    /*! \warning passing an overnight index to the constructor will
37
                 result in an overnight-indexed swap being built, but
38
                 model-based engines will treat it as a vanilla swap.
39
                 This is at best a decent proxy, at worst simply wrong.
40
                 Use with caution.
41
    */
42
    class SwaptionHelper : public BlackCalibrationHelper {
43
      public:
44
        SwaptionHelper(const Period& maturity,
45
                       const Period& length,
46
                       const Handle<Quote>& volatility,
47
                       ext::shared_ptr<IborIndex> index,
48
                       const Period& fixedLegTenor,
49
                       DayCounter fixedLegDayCounter,
50
                       DayCounter floatingLegDayCounter,
51
                       Handle<YieldTermStructure> termStructure,
52
                       CalibrationErrorType errorType = RelativePriceError,
53
                       Real strike = Null<Real>(),
54
                       Real nominal = 1.0,
55
                       VolatilityType type = ShiftedLognormal,
56
                       Real shift = 0.0,
57
                       Natural settlementDays = Null<Size>(),
58
                       RateAveraging::Type averagingMethod = RateAveraging::Compound);
59
60
        SwaptionHelper(const Date& exerciseDate,
61
                       const Period& length,
62
                       const Handle<Quote>& volatility,
63
                       ext::shared_ptr<IborIndex> index,
64
                       const Period& fixedLegTenor,
65
                       DayCounter fixedLegDayCounter,
66
                       DayCounter floatingLegDayCounter,
67
                       Handle<YieldTermStructure> termStructure,
68
                       CalibrationErrorType errorType = RelativePriceError,
69
                       Real strike = Null<Real>(),
70
                       Real nominal = 1.0,
71
                       VolatilityType type = ShiftedLognormal,
72
                       Real shift = 0.0,
73
                       Natural settlementDays = Null<Size>(),
74
                       RateAveraging::Type averagingMethod = RateAveraging::Compound);
75
76
        SwaptionHelper(const Date& exerciseDate,
77
                       const Date& endDate,
78
                       const Handle<Quote>& volatility,
79
                       ext::shared_ptr<IborIndex> index,
80
                       const Period& fixedLegTenor,
81
                       DayCounter fixedLegDayCounter,
82
                       DayCounter floatingLegDayCounter,
83
                       Handle<YieldTermStructure> termStructure,
84
                       CalibrationErrorType errorType = RelativePriceError,
85
                       Real strike = Null<Real>(),
86
                       Real nominal = 1.0,
87
                       VolatilityType type = ShiftedLognormal,
88
                       Real shift = 0.0,
89
                       Natural settlementDays = Null<Size>(),
90
                       RateAveraging::Type averagingMethod = RateAveraging::Compound);
91
92
        void addTimesTo(std::list<Time>& times) const override;
93
        Real modelValue() const override;
94
        Real blackPrice(Volatility volatility) const override;
95
96
0
        const ext::shared_ptr<FixedVsFloatingSwap>& underlying() const {
97
0
            calculate();
98
0
            return swap_;
99
0
        }
100
0
        ext::shared_ptr<Swaption> swaption() const { calculate(); return swaption_; }
101
102
      private:
103
        void performCalculations() const override;
104
        ext::shared_ptr<FixedVsFloatingSwap> makeSwap(Schedule fixedSchedule,
105
                                                      Schedule floatSchedule,
106
                                                      Rate exerciseRate,
107
                                                      Swap::Type type) const;
108
        mutable Date exerciseDate_, endDate_;
109
        const Period maturity_, length_, fixedLegTenor_;
110
        const ext::shared_ptr<IborIndex> index_;
111
        const Handle<YieldTermStructure> termStructure_;
112
        const DayCounter fixedLegDayCounter_, floatingLegDayCounter_;
113
        const Real strike_, nominal_;
114
        const Natural settlementDays_;
115
        const RateAveraging::Type averagingMethod_;
116
        mutable Rate exerciseRate_;
117
        mutable ext::shared_ptr<FixedVsFloatingSwap> swap_;
118
        mutable ext::shared_ptr<Swaption> swaption_;
119
    };
120
121
}
122
123
#endif