Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
forwardbond.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file forwardbond.hpp
20 \brief Forward bond class
21*/
22
23#ifndef quantext_forwardbond_hpp
24#define quantext_forwardbond_hpp
25
26#include <ql/handle.hpp>
27#include <ql/instrument.hpp>
28#include <ql/instruments/bond.hpp>
29#include <ql/interestrate.hpp>
30#include <ql/payoff.hpp>
31#include <ql/position.hpp>
32#include <ql/termstructures/yieldtermstructure.hpp>
33#include <ql/time/calendar.hpp>
34#include <ql/time/daycounter.hpp>
35#include <ql/types.hpp>
36
37namespace QuantExt {
38using namespace QuantLib;
39
40//! Forward Bond class
41class ForwardBond : public Instrument {
42public:
43 class arguments;
44 class engine;
45 class results;
46 //! Constructor vanilla forward bond
47 ForwardBond(const QuantLib::ext::shared_ptr<QuantLib::Bond>& underlying, const QuantLib::ext::shared_ptr<Payoff>& payoff,
48 const Date& fwdMaturityDate, const Date& fwdSettlementDate, const bool isPhysicallySettled,
49 const bool settlementDirty, const Real compensationPayment, const Date compensationPaymentDate,
50 const Real bondNotional = 1.0);
51 //! Constructor for tlocks with lock rate
52 ForwardBond(const QuantLib::ext::shared_ptr<QuantLib::Bond>& underlying, const Real lockRate,
53 const DayCounter& lockRateDayCounter, const bool longInForward, const Date& fwdMaturityDate,
54 const Date& fwdSettlementDate, const bool isPhysicallySettled, const bool settlementDirty,
55 const Real compensationPayment, const Date compensationPaymentDate, const Real bondNotional = 1.0,
56 const Real dv01 = Null<Real>());
57
58 //! \name Instrument interface
59 //@{
60 bool isExpired() const override;
61 void setupArguments(PricingEngine::arguments*) const override;
62 void fetchResults(const PricingEngine::results*) const override;
63 //@}
64
65 //! \name Inspectors
66 //@{
67 const QuantLib::ext::shared_ptr<QuantLib::Bond>& underlying() { return underlying_; }
68 //@}
69
70private:
71 QuantLib::ext::shared_ptr<QuantLib::Bond> underlying_;
72 QuantLib::ext::shared_ptr<Payoff> payoff_; // nullptr for tlocks
73 Real lockRate_; // Null<Real>() for vanilla forwards
74 DayCounter lockRateDayCounter_; // empty dc for vanilla forwards
75 boost::optional<bool> longInForward_; // only filled for tlocks
83 Real dv01_;
84 mutable Real underlyingIncome_;
86 mutable Real forwardValue_;
87};
88
89//! \ingroup instruments
91public:
92 QuantLib::ext::shared_ptr<QuantLib::Bond> underlying;
93 QuantLib::ext::shared_ptr<Payoff> payoff; // nullptr for tlocks
94 Real lockRate; // Null<Real>() for vanilla forwards
95 boost::optional<bool> longInForward; // only filled for tlocks
96 DayCounter lockRateDayCounter; // empty dc for vanilla forwards
104 Real dv01;
105 void validate() const override;
106};
107
108//! \ingroup instruments
110public:
114 void reset() override;
115};
116
117//! Class for forward type payoffs
119public:
120 ForwardBondTypePayoff(Position::Type type, Real strike) : type_(type), strike_(strike) {
121 QL_REQUIRE(strike >= 0.0, "negative strike given");
122 }
123 Position::Type forwardType() const { return type_; };
124 Real strike() const { return strike_; };
125 //! \name Payoff interface
126 //@{
127 std::string name() const override { return "ForwardBond"; }
128 std::string description() const override;
129 Real operator()(Real price) const override;
130 //@}
131protected:
132 Position::Type type_;
134};
135
136// inline definitions
137inline std::string ForwardBondTypePayoff::description() const {
138 std::ostringstream result;
139 result << name() << ", " << strike() << " strike";
140 return result.str();
141}
142
143inline Real ForwardBondTypePayoff::operator()(Real price) const {
144 switch (type_) {
145 case Position::Long:
146 return (price - strike_);
147 case Position::Short:
148 return (strike_ - price);
149 default:
150 QL_FAIL("unknown/illegal position type");
151 }
152}
153
154//! \ingroup instruments
155class ForwardBond::engine : public GenericEngine<ForwardBond::arguments, ForwardBond::results> {};
156
157} // namespace QuantExt
158
159#endif
boost::optional< bool > longInForward
Definition: forwardbond.hpp:95
QuantLib::ext::shared_ptr< Payoff > payoff
Definition: forwardbond.hpp:93
QuantLib::ext::shared_ptr< QuantLib::Bond > underlying
Definition: forwardbond.hpp:92
void validate() const override
Definition: forwardbond.cpp:82
Forward Bond class.
Definition: forwardbond.hpp:41
DayCounter lockRateDayCounter_
Definition: forwardbond.hpp:74
void setupArguments(PricingEngine::arguments *) const override
Definition: forwardbond.cpp:48
bool isExpired() const override
Definition: forwardbond.cpp:46
boost::optional< bool > longInForward_
Definition: forwardbond.hpp:75
QuantLib::ext::shared_ptr< Payoff > payoff_
Definition: forwardbond.hpp:72
void fetchResults(const PricingEngine::results *) const override
Definition: forwardbond.cpp:73
ForwardBond(const QuantLib::ext::shared_ptr< QuantLib::Bond > &underlying, const QuantLib::ext::shared_ptr< Payoff > &payoff, const Date &fwdMaturityDate, const Date &fwdSettlementDate, const bool isPhysicallySettled, const bool settlementDirty, const Real compensationPayment, const Date compensationPaymentDate, const Real bondNotional=1.0)
Constructor vanilla forward bond.
ForwardBond(const QuantLib::ext::shared_ptr< QuantLib::Bond > &underlying, const Real lockRate, const DayCounter &lockRateDayCounter, const bool longInForward, const Date &fwdMaturityDate, const Date &fwdSettlementDate, const bool isPhysicallySettled, const bool settlementDirty, const Real compensationPayment, const Date compensationPaymentDate, const Real bondNotional=1.0, const Real dv01=Null< Real >())
Constructor for tlocks with lock rate.
const QuantLib::ext::shared_ptr< QuantLib::Bond > & underlying()
Definition: forwardbond.hpp:67
QuantLib::ext::shared_ptr< QuantLib::Bond > underlying_
Definition: forwardbond.hpp:71
Class for forward type payoffs.
Real operator()(Real price) const override
std::string description() const override
ForwardBondTypePayoff(Position::Type type, Real strike)
std::string name() const override
Position::Type forwardType() const