QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
bondforward.cpp
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#include <ql/instruments/bondforward.hpp>
22#include <ql/termstructures/yieldtermstructure.hpp>
23#include <ql/cashflow.hpp>
24
25namespace QuantLib {
26
28 const Date& valueDate,
29 const Date& maturityDate,
30 Position::Type type,
31 Real strike,
32 Natural settlementDays,
33 const DayCounter& dayCounter,
34 const Calendar& calendar,
35 BusinessDayConvention businessDayConvention,
36 const ext::shared_ptr<Bond>& bond,
37 const Handle<YieldTermStructure>& discountCurve,
38 const Handle<YieldTermStructure>& incomeDiscountCurve)
39 : Forward(dayCounter, calendar, businessDayConvention, settlementDays,
40 ext::shared_ptr<Payoff>(new ForwardTypePayoff(type,strike)),
41 valueDate, maturityDate, discountCurve), bond_(bond) {
42
45 registerWith(bond);
46 }
47
48
50 return forwardValue() - bond_->accruedAmount(maturityDate_);
51 }
52
53
55 return forwardValue();
56 }
57
58
60 const Handle<YieldTermStructure>& incomeDiscountCurve) const {
61
62 Real income = 0.0;
63 Date settlement = settlementDate();
64 Leg cf = bond_->cashflows();
65
66 /*
67 the following assumes
68 1. cashflows are in ascending order !
69 2. considers as income: all coupons paid between settlementDate()
70 and contract delivery/maturity date
71 */
72 for (auto& i : cf) {
73 if (!i->hasOccurred(settlement, false)) {
74 if (i->hasOccurred(maturityDate_, false)) {
75 income += i->amount() * incomeDiscountCurve->discount(i->date());
76 } else {
77 break;
78 }
79 }
80 }
81
82 return income;
83 }
84
85
87 return bond_->dirtyPrice();
88 }
89
90
92
95
97 }
98
99}
100
void performCalculations() const override
Definition: bondforward.cpp:91
BondForward(const Date &valueDate, const Date &maturityDate, Position::Type type, Real strike, Natural settlementDays, const DayCounter &dayCounter, const Calendar &calendar, BusinessDayConvention businessDayConvention, const ext::shared_ptr< Bond > &bond, const Handle< YieldTermStructure > &discountCurve=Handle< YieldTermStructure >(), const Handle< YieldTermStructure > &incomeDiscountCurve=Handle< YieldTermStructure >())
Definition: bondforward.cpp:27
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
void performCalculations() const override
Definition: forward.cpp:83
Real underlyingSpotValue_
Definition: forward.hpp:125
virtual Real forwardValue() const
forward value/price of underlying, discounting income/dividends
Definition: forward.cpp:61
virtual Date settlementDate() const
Definition: forward.cpp:48
Date maturityDate_
maturityDate of the forward contract or delivery date of underlying
Definition: forward.hpp:137
Real underlyingIncome_
Definition: forward.hpp:123
Handle< YieldTermStructure > incomeDiscountCurve() const
term structure that discounts the underlying's income cash flows
Definition: forward.hpp:184
Handle< YieldTermStructure > incomeDiscountCurve_
Definition: forward.hpp:140
Class for forward type payoffs.
Definition: forward.hpp:145
Shared handle to an observable.
Definition: handle.hpp:41
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Abstract base class for option payoffs.
Definition: payoff.hpp:36
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
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78