Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
forwardbond.cpp
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#include <ql/event.hpp>
20#include <ql/termstructures/yieldtermstructure.hpp>
23
24namespace QuantExt {
25
26ForwardBond::ForwardBond(const QuantLib::ext::shared_ptr<Bond>& underlying, const QuantLib::ext::shared_ptr<Payoff>& payoff,
27 const Date& fwdMaturityDate, const Date& fwdSettlementDate, const bool isPhysicallySettled,
28 const bool settlementDirty, const Real compensationPayment, const Date compensationPaymentDate,
29 const Real bondNotional)
30 : underlying_(underlying), payoff_(payoff), lockRate_(Null<Real>()), fwdMaturityDate_(fwdMaturityDate),
31 fwdSettlementDate_(fwdSettlementDate), isPhysicallySettled_(isPhysicallySettled),
32 settlementDirty_(settlementDirty), compensationPayment_(compensationPayment),
33 compensationPaymentDate_(compensationPaymentDate), bondNotional_(bondNotional), dv01_(Null<Real>()) {}
34
35ForwardBond::ForwardBond(const QuantLib::ext::shared_ptr<Bond>& underlying, const Real lockRate,
36 const DayCounter& lockRateDayCounter, const bool longInForward, const Date& fwdMaturityDate,
37 const Date& fwdSettlementDate, const bool isPhysicallySettled, const bool settlementDirty,
38 const Real compensationPayment, const Date compensationPaymentDate,
39 const Real bondNotional,const Real dv01)
40 : underlying_(underlying), payoff_(nullptr), lockRate_(lockRate), lockRateDayCounter_(lockRateDayCounter),
41 longInForward_(longInForward), fwdMaturityDate_(fwdMaturityDate), fwdSettlementDate_(fwdSettlementDate),
42 isPhysicallySettled_(isPhysicallySettled), settlementDirty_(settlementDirty),
43 compensationPayment_(compensationPayment), compensationPaymentDate_(compensationPaymentDate),
44 bondNotional_(bondNotional), dv01_(dv01) {}
45
46bool ForwardBond::isExpired() const { return detail::simple_event(fwdMaturityDate_).hasOccurred(); }
47
48void ForwardBond::setupArguments(PricingEngine::arguments* args) const {
50 QL_REQUIRE(arguments != 0, "wrong argument type in forward bond");
51 arguments->underlying = underlying_;
52 arguments->payoff = payoff_;
53 arguments->lockRate = lockRate_;
54 arguments->lockRateDayCounter = lockRateDayCounter_;
55 arguments->longInForward = longInForward_;
56 arguments->fwdMaturityDate = fwdMaturityDate_;
57 arguments->fwdSettlementDate = fwdSettlementDate_;
58 arguments->isPhysicallySettled = isPhysicallySettled_;
59 arguments->settlementDirty = settlementDirty_;
60 arguments->compensationPayment = compensationPayment_;
61 arguments->compensationPaymentDate = compensationPaymentDate_;
62 arguments->bondNotional = bondNotional_;
63 arguments->dv01 = dv01_;
64}
65
66void ForwardBond::results::reset() {
67 Instrument::results::reset();
68 forwardValue = Null<Real>();
69 underlyingSpotValue = Null<Real>();
70 underlyingIncome = Null<Real>();
71}
72
73void ForwardBond::fetchResults(const PricingEngine::results* r) const {
74 Instrument::fetchResults(r);
75 const ForwardBond::results* results = dynamic_cast<const ForwardBond::results*>(r);
76 QL_REQUIRE(results, "wrong result type");
77 forwardValue_ = results->forwardValue;
78 underlyingSpotValue_ = results->underlyingSpotValue;
79 underlyingIncome_ = results->underlyingIncome;
80}
81
82void ForwardBond::arguments::validate() const {
83 QL_REQUIRE(underlying, "bond pointer is null");
84 QL_REQUIRE((payoff != nullptr && lockRate == Null<Real>()) || (payoff == nullptr && lockRate != Null<Real>()),
85 "exactly one of payoff or lockRate must be filled");
86 QL_REQUIRE(lockRate == Null<Real>() || longInForward, "if lockRate is given, longInForward must be given as well");
87}
88
89} // namespace QuantExt
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
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.
Engine to value a Forward Bond contract.
Forward bond class.