File: forwardrateagreement.hpp

package info (click to toggle)
quantlib 1.29-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 46,032 kB
  • sloc: cpp: 389,443; makefile: 6,658; sh: 4,511; lisp: 86
file content (224 lines) | stat: -rw-r--r-- 8,293 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
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*
 Copyright (C) 2006 Allen Kuo

 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
 <quantlib-dev@lists.sf.net>. The license is also available online at
 <http://quantlib.org/license.shtml>.

 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 forwardrateagreement.hpp
    \brief forward rate agreement
*/

#ifndef quantlib_forward_rate_agreement_hpp
#define quantlib_forward_rate_agreement_hpp

#include <ql/instruments/forward.hpp>

namespace QuantLib {

    class IborIndex;

    QL_DEPRECATED_DISABLE_WARNING

    //! %Forward rate agreement (FRA) class
    /*! 1. Unlike the forward contract conventions on carryable
           financial assets (stocks, bonds, commodities), the
           valueDate for a FRA is taken to be the day when the forward
           loan or deposit begins and when full settlement takes place
           (based on the NPV of the contract on that date).
           maturityDate is the date when the forward loan or deposit
           ends. In fact, the FRA settles and expires on the
           valueDate, not on the (later) maturityDate. It follows that
           (maturityDate - valueDate) is the tenor/term of the
           underlying loan or deposit

        2. Choose position type = Long for an "FRA purchase" (future
           long loan, short deposit [borrower])

        3. Choose position type = Short for an "FRA sale" (future short
           loan, long deposit [lender])

        <b>Example: </b>
        \link FRA.cpp
        valuation of a forward-rate agreement
        \endlink

        \todo Add preconditions and tests

        \todo Differentiate between BBA (British)/AFB (French)
              [assumed here] and ABA (Australian) banker conventions
              in the calculations.

        \warning This class still needs to be rigorously tested

        \ingroup instruments
    */
    class ForwardRateAgreement: public Instrument {
      public:
        ForwardRateAgreement(
            const Date& valueDate,
            const Date& maturityDate,
            Position::Type type,
            Rate strikeForwardRate,
            Real notionalAmount,
            const ext::shared_ptr<IborIndex>& index,
            Handle<YieldTermStructure> discountCurve = Handle<YieldTermStructure>(),
            bool useIndexedCoupon = true);
        ForwardRateAgreement(
            const Date& valueDate,
            Position::Type type,
            Rate strikeForwardRate,
            Real notionalAmount,
            const ext::shared_ptr<IborIndex>& index,
            Handle<YieldTermStructure> discountCurve = Handle<YieldTermStructure>());
        //! \name Calculations
        //@{
        //! A FRA expires/settles on the value date
        bool isExpired() const override;
        //! The payoff on the value date
        Real amount() const;

        /*! \deprecated This used to be inherited from Forward, but it's not correct for FRAs.
                        Deprecated in version 1.25.
        */
        QL_DEPRECATED
        Date settlementDate() const;

        const Calendar& calendar() const;
        BusinessDayConvention businessDayConvention() const;
        const DayCounter& dayCounter() const;
        //! term structure relevant to the contract (e.g. repo curve)
        Handle<YieldTermStructure> discountCurve() const;

        /*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
                        Deprecated in version 1.25.
        */
        QL_DEPRECATED
        Handle<YieldTermStructure> incomeDiscountCurve() const;

        Date fixingDate() const;

        /*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
                        Deprecated in version 1.25.
        */
        QL_DEPRECATED
        Real spotIncome(const Handle<YieldTermStructure>& incomeDiscountCurve) const;
        /*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
                        Deprecated in version 1.25.
        */
        QL_DEPRECATED
        Real spotValue() const;

        //! Returns the relevant forward rate associated with the FRA term
        InterestRate forwardRate() const;

        /*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
                        Deprecated in version 1.25.
        */
        QL_DEPRECATED
        InterestRate impliedYield(Real underlyingSpotValue,
                                  Real forwardValue,
                                  Date settlementDate,
                                  Compounding compoundingConvention,
                                  const DayCounter& dayCounter);

        /*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
                        Deprecated in version 1.25.
        */
        QL_DEPRECATED
        virtual Real forwardValue() const;
        //@}

      protected:
        void setupExpired() const override;
        void performCalculations() const override;
        Position::Type fraType_;
        //! aka FRA rate (the market forward rate)
        mutable InterestRate forwardRate_;
        //! aka FRA fixing rate, contract rate
        InterestRate strikeForwardRate_;
        Real notionalAmount_;
        ext::shared_ptr<IborIndex> index_;
        bool useIndexedCoupon_;

        /*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
                        Deprecated in version 1.25.
        */
        QL_DEPRECATED
        mutable Real underlyingIncome_;
        /*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
                        Deprecated in version 1.25.
        */
        QL_DEPRECATED
        mutable Real underlyingSpotValue_;

        DayCounter dayCounter_;
        Calendar calendar_;
        BusinessDayConvention businessDayConvention_;

        /*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
                        Deprecated in version 1.25.
        */
        QL_DEPRECATED
        Natural settlementDays_;

        /*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
                        Deprecated in version 1.25.
        */
        QL_DEPRECATED
        ext::shared_ptr<Payoff> payoff_;

        //! the valueDate is the date the underlying index starts accruing and the FRA is settled.
        Date valueDate_;
        //! maturityDate of the underlying index; not the date the FRA is settled.
        Date maturityDate_;
        Handle<YieldTermStructure> discountCurve_;

        /*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
                        Deprecated in version 1.25.
        */
        QL_DEPRECATED
        Handle<YieldTermStructure> incomeDiscountCurve_;

      private:
        void calculateForwardRate() const;
        void calculateAmount() const;
        mutable Real amount_;
    };

    QL_DEPRECATED_ENABLE_WARNING

    inline const Calendar& ForwardRateAgreement::calendar() const { return calendar_; }

    inline BusinessDayConvention ForwardRateAgreement::businessDayConvention() const {
        return businessDayConvention_;
    }

    inline const DayCounter& ForwardRateAgreement::dayCounter() const { return dayCounter_; }

    inline Handle<YieldTermStructure> ForwardRateAgreement::discountCurve() const {
        return discountCurve_;
    }

    inline Handle<YieldTermStructure> ForwardRateAgreement::incomeDiscountCurve() const {
        QL_DEPRECATED_DISABLE_WARNING
        return incomeDiscountCurve_;
        QL_DEPRECATED_ENABLE_WARNING
    }

}


#endif