Coverage Report

Created: 2025-11-04 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/instruments/stickyratchet.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2007 Marco Bianchetti
5
 Copyright (C) 2007 Giorgio Facchinetti
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 stickyratchet.hpp
22
    \brief Payoffs for double nested options of sticky or ratchet type
23
*/
24
25
#ifndef quantlib_stickyratchet_hpp
26
#define quantlib_stickyratchet_hpp
27
28
#include <ql/option.hpp>
29
#include <ql/payoff.hpp>
30
31
namespace QuantLib {
32
    
33
    class AcyclicVisitor;
34
    //! Intermediate class for single/double sticky/ratchet payoffs.
35
    //  initialValues can be a (forward) rate or a coupon/accrualFactor 
36
    class DoubleStickyRatchetPayoff : public Payoff {
37
      public:
38
        DoubleStickyRatchetPayoff(Real type1, Real type2,
39
                            Real gearing1, Real gearing2, Real gearing3,
40
                            Real spread1, Real spread2, Real spread3,
41
                            Real initialValue1, Real initialValue2, 
42
                            Real accrualFactor) 
43
        : type1_(type1), type2_(type2), 
44
          gearing1_(gearing1), gearing2_(gearing2), gearing3_(gearing3),
45
          spread1_(spread1), spread2_(spread2), spread3_(spread3),
46
          initialValue1_(initialValue1), initialValue2_(initialValue2), 
47
0
          accrualFactor_(accrualFactor) {}
48
        //! \name Payoff interface
49
        //@{
50
        std::string name() const override;
51
        Real operator()(Real forward) const override;
52
        std::string description() const override;
53
        void accept(AcyclicVisitor&) override;
54
        //@}
55
      protected:
56
        Real type1_ ,type2_;
57
        Real gearing1_, gearing2_, gearing3_;
58
        Real spread1_, spread2_, spread3_;
59
        Real initialValue1_, initialValue2_, accrualFactor_;
60
    };
61
62
    //! Ratchet payoff (single option)
63
    class RatchetPayoff : public DoubleStickyRatchetPayoff {
64
      public:
65
         RatchetPayoff(Real gearing1, Real gearing2,
66
                       Real spread1, Real spread2,
67
                       Real initialValue, Real accrualFactor)
68
        : DoubleStickyRatchetPayoff(-1.0, 0.0,
69
                            gearing1, 0.0, gearing2,
70
                            spread1, 0.0, spread2,
71
                            initialValue, 0.0, 
72
0
                            accrualFactor) {}
73
        //! \name Payoff interface
74
        //@{
75
0
         std::string name() const override { return "Ratchet"; }
76
         //@}
77
    };    
78
79
    //! Sticky payoff (single option)
80
    class StickyPayoff : public DoubleStickyRatchetPayoff {
81
      public:
82
         StickyPayoff(Real gearing1, Real gearing2,
83
                       Real spread1, Real spread2,
84
                       Real initialValue, Real accrualFactor)
85
        : DoubleStickyRatchetPayoff(+1.0, 0.0,
86
                            gearing1, 0.0, gearing2,
87
                            spread1, 0.0, spread2,
88
                            initialValue, 0.0, 
89
0
                            accrualFactor) {}
90
        //! \name Payoff interface
91
        //@{
92
0
         std::string name() const override { return "Sticky"; }
93
         //@}
94
    };
95
96
    //! RatchetMax payoff (double option)
97
    class RatchetMaxPayoff : public DoubleStickyRatchetPayoff {
98
      public:
99
         RatchetMaxPayoff(Real gearing1, Real gearing2, Real gearing3,
100
                          Real spread1, Real spread2, Real spread3,
101
                          Real initialValue1, Real initialValue2, 
102
                          Real accrualFactor)
103
        : DoubleStickyRatchetPayoff(-1.0, -1.0,
104
                                    gearing1, gearing2, gearing3,
105
                                    spread1, spread2, spread3,
106
                                    initialValue1, initialValue2, 
107
0
                                    accrualFactor) {}
108
        //! \name Payoff interface
109
        //@{
110
0
         std::string name() const override { return "RatchetMax"; }
111
         //@}
112
    };    
113
114
    //! RatchetMin payoff (double option)
115
    class RatchetMinPayoff : public DoubleStickyRatchetPayoff {
116
      public:
117
         RatchetMinPayoff(Real gearing1, Real gearing2, Real gearing3,
118
                          Real spread1, Real spread2, Real spread3,
119
                          Real initialValue1, Real initialValue2, 
120
                          Real accrualFactor)
121
        : DoubleStickyRatchetPayoff(-1.0, +1.0,
122
                                    gearing1, gearing2, gearing3,
123
                                    spread1, spread2, spread3,
124
                                    initialValue1, initialValue2, 
125
0
                                    accrualFactor) {}
126
        //! \name Payoff interface
127
        //@{
128
0
         std::string name() const override { return "RatchetMin"; }
129
         //@}
130
    };    
131
132
    //! StickyMax payoff (double option)
133
    class StickyMaxPayoff : public DoubleStickyRatchetPayoff {
134
      public:
135
         StickyMaxPayoff(Real gearing1, Real gearing2, Real gearing3,
136
                          Real spread1, Real spread2, Real spread3,
137
                          Real initialValue1, Real initialValue2, 
138
                          Real accrualFactor)
139
        : DoubleStickyRatchetPayoff(+1.0, -1.0,
140
                                    gearing1, gearing2, gearing3,
141
                                    spread1, spread2, spread3,
142
                                    initialValue1, initialValue2, 
143
0
                                    accrualFactor) {}
144
        //! \name Payoff interface
145
        //@{
146
0
         std::string name() const override { return "StickyMax"; }
147
         //@}
148
    };    
149
150
    //! StickyMin payoff (double option)
151
    class StickyMinPayoff : public DoubleStickyRatchetPayoff {
152
      public:
153
         StickyMinPayoff(Real gearing1, Real gearing2, Real gearing3,
154
                          Real spread1, Real spread2, Real spread3,
155
                          Real initialValue1, Real initialValue2, 
156
                          Real accrualFactor)
157
        : DoubleStickyRatchetPayoff(+1.0, +1.0,
158
                                    gearing1, gearing2, gearing3,
159
                                    spread1, spread2, spread3,
160
                                    initialValue1, initialValue2, 
161
0
                                    accrualFactor) {}
162
        //! \name Payoff interface
163
        //@{
164
0
         std::string name() const override { return "StickyMin"; }
165
         //@}
166
    };    
167
168
/*---------------------------------------------------------------------------------
169
    // Old code for single sticky/ratchet payoffs, 
170
    // superated by DoubleStickyRatchetPayoff class above
171
172
    //! Intermediate class for sticky/ratchet payoffs
173
    //  initialValue can be a (forward) rate or a coupon/accrualFactor 
174
    class StickyRatchetPayoff : public Payoff {
175
      public:
176
        StickyRatchetPayoff(Real type,
177
                            Real gearing1, Real gearing2,
178
                            Real spread1, Real spread2,
179
                            Real initialValue, Real accrualFactor) 
180
        : type_(type), gearing1_(gearing1), gearing2_(gearing2), 
181
          spread1_(spread1), spread2_(spread2), initialValue_(initialValue),
182
          accrualFactor_(accrualFactor) {}
183
        //! \name Payoff interface
184
        //@{
185
        Real operator()(Real forward) const;
186
        std::string description() const;
187
        virtual void accept(AcyclicVisitor&);
188
        //@}
189
      protected:
190
        Real type_;
191
        Real gearing1_, gearing2_;
192
        Real spread1_, spread2_;
193
        Real initialValue_, accrualFactor_;
194
    };
195
196
    //! Ratchet_2 payoff
197
    class RatchetPayoff_2 : public StickyRatchetPayoff {
198
      public:
199
         RatchetPayoff_2(Real gearing1, Real gearing2,
200
                       Real spread1, Real spread2,
201
                       Real initialValue, Real accrualFactor)
202
        : StickyRatchetPayoff(-1,
203
                              gearing1, gearing2,
204
                              spread1, spread2,
205
                              initialValue, accrualFactor) {}
206
        //! \name Payoff interface
207
        //@{
208
        std::string name() const { return "Ratchet";}
209
        //@}
210
    };
211
212
    //! Sticky_2 payoff
213
    class StickyPayoff_2 : public StickyRatchetPayoff {
214
      public:
215
         StickyPayoff_2(Real gearing1, Real gearing2,
216
                       Real spread1, Real spread2,
217
                       Real initialValue, Real accrualFactor) 
218
        : StickyRatchetPayoff(+1,
219
                              gearing1, gearing2,
220
                              spread1, spread2,
221
                              initialValue, accrualFactor) {}
222
        //! \name Payoff interface
223
        //@{
224
        std::string name() const { return "Sticky";}
225
        //@}
226
    };
227
-----------------------------------------------------------------------------*/
228
229
}
230
231
#endif