File: ratehelpers.hpp

package info (click to toggle)
quantlib 0.2.1.cvs20020322-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 4,716 kB
  • ctags: 4,614
  • sloc: cpp: 19,601; sh: 7,389; makefile: 796; ansic: 22
file content (240 lines) | stat: -rw-r--r-- 9,468 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240


/*
 Copyright (C) 2000, 2001, 2002 RiskMap srl

 This file is part of QuantLib, a free-software/open-source library
 for financial quantitative analysts and developers - http://quantlib.org/

 QuantLib is free software: you can redistribute it and/or modify it under the
 terms of the QuantLib license.  You should have received a copy of the
 license along with this program; if not, please email ferdinando@ametrano.net
 The license is also available online at http://quantlib.org/html/license.html

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
*/
/*! \file ratehelpers.hpp
    \brief rate helpers base class

    \fullpath
    ql/TermStructures/%ratehelpers.hpp
*/

// $Id: ratehelpers.hpp,v 1.19 2002/03/05 16:58:03 lballabio Exp $

#ifndef quantlib_ratehelper_h
#define quantlib_ratehelper_h

#include <ql/Instruments/simpleswap.hpp>

namespace QuantLib {

    namespace TermStructures {

        //! base class for rate helpers
        /*! This class provides an abstraction for the instruments used to
            bootstrap a term structure.
            It is advised that a rate helper for an instrument contains an
            instance of the actual instrument class to ensure consistancy
            between the algorithms used during bootstrapping and later
            instrument pricing. This is not yet fully enforced in the
            available rate helpers, though - only SwapRateHelper contains a
            Swap instrument for the time being.
        */

        class RateHelper : public Patterns::Observer,
                           public Patterns::Observable {
          public:
            RateHelper(const RelinkableHandle<MarketElement>& quote);
            RateHelper(double quote);
            virtual ~RateHelper() {}
            //! \name RateHelper interface
            //@{
            double quoteError() const;
            virtual double impliedQuote() const = 0;
            virtual DiscountFactor discountGuess() const {
                return Null<double>();
            }
            //! sets the term structure to be used for pricing
            /*! \warning Being a pointer and not a Handle, the term structure
                is not guaranteed to remain allocated for the whole life of
                the rate helper. It is responsibility of the programmer to
                ensure that the pointer remains valid. It is advised that
                rate helpers be used only in term structure constructors,
                setting the term structure to <b>this</b>, i.e., the one
                being constructed.
            */
            virtual void setTermStructure(TermStructure*);
            //! maturity date
            virtual Date maturity() const = 0;
            //@}
            //! \name Observer interface
            //@{
            void update() { notifyObservers(); }
            //@}
          protected:
            RelinkableHandle<MarketElement> quote_;
            TermStructure* termStructure_;
        };


        //! Deposit rate
        /*! \warning This class assumes that today's date does not change
            between calls of setTermStructure().
        */
        class DepositRateHelper : public RateHelper {
          public:
            DepositRateHelper(const RelinkableHandle<MarketElement>& rate,
                              int settlementDays,
                              int n, TimeUnit units,
                              const Calendar& calendar,
                              RollingConvention convention,
                              const DayCounter& dayCounter);
            DepositRateHelper(double rate,
                              int settlementDays,
                              int n, TimeUnit units,
                              const Calendar& calendar,
                              RollingConvention convention,
                              const DayCounter& dayCounter);
            double impliedQuote() const;
            DiscountFactor discountGuess() const;
            void setTermStructure(TermStructure*);
            Date maturity() const;
          private:
            int settlementDays_;
            int n_;
            TimeUnit units_;
            Calendar calendar_;
            RollingConvention convention_;
            DayCounter dayCounter_;
            Date settlement_, maturity_;
            double yearFraction_;
        };


        //! Forward rate agreement
        /*! \warning This class assumes that today's date does not change
            between calls of setTermStructure().

            \todo convexity adjustment should be implemented.
        */
        class FraRateHelper : public RateHelper {
          public:
            FraRateHelper(const RelinkableHandle<MarketElement>& rate,
                          int settlementDays,
                          int monthsToStart, int monthsToEnd,
                          const Calendar& calendar,
                          RollingConvention convention,
                          const DayCounter& dayCounter);
            FraRateHelper(double rate,
                          int settlementDays,
                          int monthsToStart, int monthsToEnd,
                          const Calendar& calendar,
                          RollingConvention convention,
                          const DayCounter& dayCounter);
            double impliedQuote() const;
            DiscountFactor discountGuess() const;
            void setTermStructure(TermStructure*);
            Date maturity() const;
          private:
            int settlementDays_;
            int monthsToStart_, monthsToEnd_;
            TimeUnit units_;
            Calendar calendar_;
            RollingConvention convention_;
            DayCounter dayCounter_;
            Date settlement_, start_, maturity_;
            double yearFraction_;
        };


        //! Interest Rate Futures
        /*! \warning This class assumes that today's date does not change
            between calls of setTermStructure().
        */
        class FuturesRateHelper : public RateHelper {
          public:
            FuturesRateHelper(const RelinkableHandle<MarketElement>& price,
                              const Date& ImmDate,
                              int settlementDays,
                              int nMonths,
                              const Calendar& calendar,
                              RollingConvention convention,
                              const DayCounter& dayCounter);
            FuturesRateHelper(double price,
                              const Date& ImmDate,
                              int settlementDays,
                              int nMonths,
                              const Calendar& calendar,
                              RollingConvention convention,
                              const DayCounter& dayCounter);
            double impliedQuote() const;
            DiscountFactor discountGuess() const;
            Date maturity() const;
          private:
            Date ImmDate_;
            int settlementDays_;
            int nMonths_;
            Calendar calendar_;
            RollingConvention convention_;
            DayCounter dayCounter_;
            Date maturity_;
            double yearFraction_;
        };


        //! swap rate
        /*! \warning This class assumes that today's date does not change
            between calls of setTermStructure().

        */
        class SwapRateHelper : public RateHelper {
          public:
            SwapRateHelper(const RelinkableHandle<MarketElement>& rate,
                           int settlementDays,
                           int lengthInYears,
                           const Calendar& calendar,
                           RollingConvention convention,
                           // fixed leg
                           int fixedFrequency,
                           bool fixedIsAdjusted,
                           const DayCounter& fixedDayCount,
                           // floating leg
                           int floatingFrequency);
            SwapRateHelper(double rate,
                           int settlementDays,
                           int lengthInYears,
                           const Calendar& calendar,
                           RollingConvention convention,
                           // fixed leg
                           int fixedFrequency,
                           bool fixedIsAdjusted,
                           const DayCounter& fixedDayCount,
                           // floating leg
                           int floatingFrequency);
            double impliedQuote() const;
            // implementing discountGuess() is not worthwhile,
            // and may not avoid the root-finding process
            Date maturity() const;
            void setTermStructure(TermStructure*);
          protected:  
            int settlementDays_;
            int lengthInYears_;
            Calendar calendar_;
            RollingConvention convention_;
            int fixedFrequency_, floatingFrequency_;
            bool fixedIsAdjusted_;
            DayCounter fixedDayCount_;
            Date settlement_;
            Handle<Instruments::SimpleSwap> swap_;
            RelinkableHandle<TermStructure> termStructureHandle_;
        };

    }

}


#endif