Coverage Report

Created: 2025-09-04 07:11

/src/quantlib/ql/pricingengines/swaption/gaussian1dnonstandardswaptionengine.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) 2013 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 gaussian1dnonstandardswaptionengine.hpp
21
    \brief
22
*/
23
24
#ifndef quantlib_pricers_gaussian1d_nonstandardswaption_hpp
25
#define quantlib_pricers_gaussian1d_nonstandardswaption_hpp
26
27
#include <ql/instruments/nonstandardswaption.hpp>
28
#include <ql/models/shortrate/onefactormodels/gsr.hpp>
29
#include <ql/pricingengines/genericmodelengine.hpp>
30
#include <ql/termstructures/volatility/swaption/swaptionvolstructure.hpp>
31
32
namespace QuantLib {
33
34
    //! One factor model non standard swaption engine
35
    /*! \ingroup swaptionengines
36
37
       All fixed coupons with start date greater or equal to the
38
       respective option expiry are considered to be part of the
39
       exercise into right.
40
41
       All float coupons with start date greater or equal to the
42
       respective option expiry are consideres to be part of the
43
       exercise into right.
44
45
       For redemption flows an associated start date is considered
46
       in the criterion, which is the start date of the regular
47
       xcoupon period with same payment date as the redemption flow.
48
49
       \warning Cash settled swaptions are not supported
50
51
    */
52
53
    class Gaussian1dNonstandardSwaptionEngine
54
        : public BasketGeneratingEngine,
55
          public GenericModelEngine<Gaussian1dModel,
56
                                    NonstandardSwaption::arguments,
57
                                    NonstandardSwaption::results> {
58
      public:
59
        enum Probabilities {
60
            None,
61
            Naive,
62
            Digital
63
        };
64
65
        Gaussian1dNonstandardSwaptionEngine(
66
            const ext::shared_ptr<Gaussian1dModel> &model,
67
            const int integrationPoints = 64, const Real stddevs = 7.0,
68
            const bool extrapolatePayoff = true,
69
            const bool flatPayoffExtrapolation = false,
70
            const Handle<Quote> &oas = Handle<Quote>(), // continuously
71
                                                        // compounded w.r.t. yts
72
                                                        // daycounter
73
            const Handle<YieldTermStructure> &discountCurve =
74
                Handle<YieldTermStructure>(),
75
            const Probabilities probabilities = None)
76
            : BasketGeneratingEngine(model, oas, discountCurve),
77
              GenericModelEngine<Gaussian1dModel,
78
                                 NonstandardSwaption::arguments,
79
                                 NonstandardSwaption::results>(model),
80
              integrationPoints_(integrationPoints), stddevs_(stddevs),
81
              extrapolatePayoff_(extrapolatePayoff),
82
              flatPayoffExtrapolation_(flatPayoffExtrapolation),
83
              discountCurve_(discountCurve), oas_(oas),
84
0
              probabilities_(probabilities) {
85
0
86
0
            if (!oas_.empty())
87
0
                registerWith(oas_);
88
0
89
0
            if (!discountCurve_.empty())
90
0
                registerWith(discountCurve_);
91
0
        }
92
93
        Gaussian1dNonstandardSwaptionEngine(
94
            const Handle<Gaussian1dModel> &model,
95
            const int integrationPoints = 64, const Real stddevs = 7.0,
96
            const bool extrapolatePayoff = true,
97
            const bool flatPayoffExtrapolation = false,
98
            const Handle<Quote> &oas = Handle<Quote>(), // continuously
99
                                                        // compounded w.r.t. yts
100
                                                        // daycounter
101
            const Handle<YieldTermStructure> &discountCurve =
102
                Handle<YieldTermStructure>(),
103
            const Probabilities probabilities = None)
104
            : BasketGeneratingEngine(model, oas, discountCurve),
105
              GenericModelEngine<Gaussian1dModel,
106
                                 NonstandardSwaption::arguments,
107
                                 NonstandardSwaption::results>(model),
108
              integrationPoints_(integrationPoints), stddevs_(stddevs),
109
              extrapolatePayoff_(extrapolatePayoff),
110
              flatPayoffExtrapolation_(flatPayoffExtrapolation),
111
              discountCurve_(discountCurve), oas_(oas),
112
0
              probabilities_(probabilities) {
113
0
114
0
            if (!oas_.empty())
115
0
                registerWith(oas_);
116
0
117
0
            if (!discountCurve_.empty())
118
0
                registerWith(discountCurve_);
119
0
        }
120
121
        void calculate() const override;
122
123
      protected:
124
        Real underlyingNpv(const Date& expiry, Real y) const override;
125
        Swap::Type underlyingType() const override;
126
        const Date underlyingLastDate() const override;
127
        const Array initialGuess(const Date& expiry) const override;
128
129
      private:
130
        const int integrationPoints_;
131
        const Real stddevs_;
132
        const bool extrapolatePayoff_, flatPayoffExtrapolation_;
133
        const Handle<YieldTermStructure> discountCurve_;
134
        const Handle<Quote> oas_;
135
        const Probabilities probabilities_;
136
    };
137
}
138
139
#endif