QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
bondforward.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2006 Allen Kuo
5 Copyright (C) 2022 Marcin Rybacki
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 <http://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 bondforward.hpp
22 \brief forward contract on a bond
23*/
24
25#ifndef quantlib_bond_forward_hpp
26#define quantlib_bond_forward_hpp
27
30
31namespace QuantLib {
32
33 //! %Forward contract on a bond
34 /*! 1. valueDate refers to the settlement date of the bond forward
35 contract. maturityDate is the delivery (or repurchase)
36 date for the underlying bond (not the bond's maturity
37 date).
38
39 2. Relevant formulas used in the calculations (\f$P\f$ refers
40 to a price):
41
42 a. \f$ P_{CleanFwd}(t) = P_{DirtyFwd}(t) -
43 AI(t=deliveryDate) \f$ where \f$ AI \f$ refers to the
44 accrued interest on the underlying bond.
45
46 b. \f$ P_{DirtyFwd}(t) = \frac{P_{DirtySpot}(t) -
47 SpotIncome(t)} {discountCurve->discount(t=deliveryDate)} \f$
48
49 c. \f$ SpotIncome(t) = \sum_i \left( CF_i \times
50 incomeDiscountCurve->discount(t_i) \right) \f$ where \f$
51 CF_i \f$ represents the ith bond cash flow (coupon
52 payment) associated with the underlying bond falling
53 between the settlementDate and the deliveryDate. (Note
54 the two different discount curves used in b. and c.)
55
56 \todo Add preconditions and tests
57
58 \todo Create switch- if coupon goes to seller is toggled on,
59 don't consider income in the \f$ P_{DirtyFwd}(t) \f$
60 calculation.
61
62 \todo Verify this works when the underlying is paper (in which
63 case ignore all AI.)
64
65 \warning This class still needs to be rigorously tested
66
67 \ingroup instruments
68 */
69 class BondForward : public Forward {
70 public:
71 //! \name Constructors
72 /*! If strike is given in the constructor, can calculate the
73 NPV of the contract via NPV().
74
75 If strike/forward price is desired, it can be obtained via
76 forwardPrice(). In this case, the strike variable in the
77 constructor is irrelevant and will be ignored.
78 */
79 //@{
81 const Date& valueDate,
82 const Date& maturityDate,
83 Position::Type type,
84 Real strike,
85 Natural settlementDays,
87 const Calendar& calendar,
89 const ext::shared_ptr<Bond>& bond,
92 //@}
93
94 //! \name Calculations
95 //@{
96
97 //! (dirty) forward bond price
98 Real forwardPrice() const;
99
100 //! (dirty) forward bond price minus accrued on bond at delivery
101 Real cleanForwardPrice() const;
102
103 //! NPV of bond coupons discounted using incomeDiscountCurve
104 /*! Here only coupons between max(evaluation date,settlement
105 date) and maturity date of bond forward contract are
106 considered income.
107 */
109
110 //! NPV of underlying bond
111 Real spotValue() const override;
112
113 //@}
114
115 protected:
116 ext::shared_ptr<Bond> bond_;
117 void performCalculations() const override;
118 };
119
120}
121
122#endif
concrete bond class
Forward contract on a bond
Definition: bondforward.hpp:69
void performCalculations() const override
Definition: bondforward.cpp:91
Real forwardPrice() const
(dirty) forward bond price
Definition: bondforward.cpp:54
Real cleanForwardPrice() const
(dirty) forward bond price minus accrued on bond at delivery
Definition: bondforward.cpp:49
Real spotValue() const override
NPV of underlying bond.
Definition: bondforward.cpp:86
Real spotIncome(const Handle< YieldTermStructure > &incomeDiscountCurve) const override
NPV of bond coupons discounted using incomeDiscountCurve.
Definition: bondforward.cpp:59
ext::shared_ptr< Bond > bond_
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Abstract base forward class.
Definition: forward.hpp:66
const DayCounter & dayCounter() const
Definition: forward.hpp:176
Handle< YieldTermStructure > discountCurve() const
term structure relevant to the contract (e.g. repo curve)
Definition: forward.hpp:180
const Calendar & calendar() const
Definition: forward.hpp:168
BusinessDayConvention businessDayConvention() const
Definition: forward.hpp:172
Handle< YieldTermStructure > incomeDiscountCurve() const
term structure that discounts the underlying's income cash flows
Definition: forward.hpp:184
Shared handle to an observable.
Definition: handle.hpp:41
Base forward class.
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Definition: any.hpp:35