Coverage Report

Created: 2026-08-14 07:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/instruments/forwardrateagreement.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2006 Allen Kuo
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 forwardrateagreement.hpp
21
    \brief forward rate agreement
22
*/
23
24
#ifndef quantlib_forward_rate_agreement_hpp
25
#define quantlib_forward_rate_agreement_hpp
26
27
#include <ql/instruments/forward.hpp>
28
29
namespace QuantLib {
30
31
    class IborIndex;
32
33
    //! %Forward rate agreement (FRA) class
34
    /*! 1. Unlike the forward contract conventions on carryable
35
           financial assets (stocks, bonds, commodities), the
36
           valueDate for a FRA is taken to be the day when the forward
37
           loan or deposit begins and when full settlement takes place
38
           (based on the NPV of the contract on that date).
39
           maturityDate is the date when the forward loan or deposit
40
           ends. In fact, the FRA settles and expires on the
41
           valueDate, not on the (later) maturityDate. It follows that
42
           (maturityDate - valueDate) is the tenor/term of the
43
           underlying loan or deposit
44
45
        2. Choose position type = Long for an "FRA purchase" (future
46
           long loan, short deposit [borrower])
47
48
        3. Choose position type = Short for an "FRA sale" (future short
49
           loan, long deposit [lender])
50
51
        <b>Example: </b>
52
        \link FRA.cpp
53
        valuation of a forward-rate agreement
54
        \endlink
55
56
        \todo Add preconditions and tests
57
58
        \todo Differentiate between BBA (British)/AFB (French)
59
              [assumed here] and ABA (Australian) banker conventions
60
              in the calculations.
61
62
        \warning This class still needs to be rigorously tested
63
64
        \ingroup instruments
65
    */
66
    class ForwardRateAgreement: public Instrument {
67
      public:
68
        /*! When using this constructor, the forward rate will be
69
            forecast by the passed index.  This corresponds to
70
            useIndexedCoupon=true in the FraRateHelper class.
71
        */
72
        ForwardRateAgreement(
73
            const ext::shared_ptr<IborIndex>& index,
74
            const Date& valueDate,
75
            Position::Type type,
76
            Rate strikeForwardRate,
77
            Real notionalAmount,
78
            Handle<YieldTermStructure> discountCurve = {});
79
80
        /*! When using this constructor, a par-rate approximation will
81
            be used, i.e., the forward rate will be forecast from
82
            value date to maturity date by the forecast curve
83
            contained in the index.  This corresponds to
84
            useIndexedCoupon=false in the FraRateHelper class.
85
        */
86
        ForwardRateAgreement(
87
            const ext::shared_ptr<IborIndex>& index,
88
            const Date& valueDate,
89
            const Date& maturityDate,
90
            Position::Type type,
91
            Rate strikeForwardRate,
92
            Real notionalAmount,
93
            Handle<YieldTermStructure> discountCurve = {});
94
95
        //! \name Calculations
96
        //@{
97
        //! A FRA expires/settles on the value date
98
        bool isExpired() const override;
99
        //! The payoff on the value date
100
        Real amount() const;
101
102
        const Calendar& calendar() const;
103
        BusinessDayConvention businessDayConvention() const;
104
        const DayCounter& dayCounter() const;
105
        //! term structure relevant to the contract (e.g. repo curve)
106
        const Handle<YieldTermStructure>& discountCurve() const;
107
108
        Date fixingDate() const;
109
110
        //! Returns the relevant forward rate associated with the FRA term
111
        InterestRate forwardRate() const;
112
        //@}
113
114
      protected:
115
        void setupExpired() const override;
116
        void performCalculations() const override;
117
        Position::Type fraType_;
118
        //! aka FRA rate (the market forward rate)
119
        mutable InterestRate forwardRate_;
120
        //! aka FRA fixing rate, contract rate
121
        InterestRate strikeForwardRate_;
122
        Real notionalAmount_;
123
        ext::shared_ptr<IborIndex> index_;
124
        bool useIndexedCoupon_;
125
126
        DayCounter dayCounter_;
127
        Calendar calendar_;
128
        BusinessDayConvention businessDayConvention_;
129
130
        //! the valueDate is the date the underlying index starts accruing and the FRA is settled.
131
        Date valueDate_;
132
        //! maturityDate of the underlying index; not the date the FRA is settled.
133
        Date maturityDate_;
134
        Handle<YieldTermStructure> discountCurve_;
135
136
      private:
137
        void calculateForwardRate() const;
138
        void calculateAmount() const;
139
        mutable Real amount_;
140
    };
141
142
0
    inline const Calendar& ForwardRateAgreement::calendar() const { return calendar_; }
143
144
0
    inline BusinessDayConvention ForwardRateAgreement::businessDayConvention() const {
145
0
        return businessDayConvention_;
146
0
    }
147
148
0
    inline const DayCounter& ForwardRateAgreement::dayCounter() const { return dayCounter_; }
149
150
0
    inline const Handle<YieldTermStructure>& ForwardRateAgreement::discountCurve() const {
151
0
        return discountCurve_;
152
0
    }
153
154
}
155
156
157
#endif