Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
optionwrapper.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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 ored/portfolio/optionwrapper.hpp
20 \brief Wrapper for option instruments, tracks whether option has been exercised or not
21 \ingroup tradedata
22*/
23
24#pragma once
25
27
28namespace ore {
29namespace data {
30
31//! Option Wrapper
32/*!
33 Wrapper Class for Options
34 Prices underlying instrument if option has been exercised
35 Handles Physical and Cash Settlement
36
37 \ingroup tradedata
38*/
40public:
41 //! Constructor
42 OptionWrapper(const QuantLib::ext::shared_ptr<QuantLib::Instrument>& inst, const bool isLongOption,
43 const std::vector<QuantLib::Date>& exerciseDate, const bool isPhysicalDelivery,
44 const std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>& undInst,
45 // multiplier as seen from the option holder
46 const Real multiplier = 1.0,
47 // undMultiplier w.r.t. underlying as seen from the option holder
48 const Real undMultiplier = 1.0,
49 const std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>& additionalInstruments =
50 std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>(),
51 const std::vector<Real>& additionalMultipliers = std::vector<Real>());
52 //! \name InstrumentWrapper interface
53 //@{
54 void initialise(const std::vector<QuantLib::Date>& dates) override;
55 void reset() override;
56 QuantLib::Real NPV() const override;
57 Real multiplier2() const override { return (isLong_ ? 1.0 : -1.0); }
58 const std::map<std::string, boost::any>& additionalResults() const override;
59 void updateQlInstruments() override {
60 for (QuantLib::Size i = 0; i < underlyingInstruments_.size(); ++i)
61 underlyingInstruments_[i]->update();
63 }
64 bool isOption() override { return true; }
65 //@}
66
67 //! return the underlying instruments
68 const std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>& underlyingInstruments() const {
70 }
71
72 /*! return the active underlying instrument
73 Pass true if you trigger a calculation on the returned instrument and want to record
74 the timing for that calculation. If in doubt whether a calculation is triggered, pass false. */
75 const QuantLib::ext::shared_ptr<QuantLib::Instrument>& activeUnderlyingInstrument(const bool calculate = false) const {
76 if (calculate && activeUnderlyingInstrument_ != nullptr) {
78 }
80 }
81
82 //! return true if option is long, false if option is short
83 bool isLong() const { return isLong_; }
84
85 //! return true if option is exercised
86 bool isExercised() const { return exercised_; }
87
88 //! return true for physical delivery, false for cash settlement
89 bool isPhysicalDelivery() const { return isPhysicalDelivery_; }
90
91 //! the underlying multiplier
92 Real underlyingMultiplier() const { return undMultiplier_; }
93
94 //! the (actual) date the option was exercised
95 const QuantLib::Date& exerciseDate() const { return exerciseDate_; }
96
97 //! disable exercise decisions
98 void enableExercise() { exercisable_ = true; }
99
100 //! enable exercise decisions
101 void disableExercise() { exercisable_ = false; }
102
103 virtual bool exercise() const = 0;
104
105protected:
108 std::vector<QuantLib::Date> contractExerciseDates_;
109 std::vector<QuantLib::Date> effectiveExerciseDates_;
110 std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>> underlyingInstruments_;
111 mutable QuantLib::ext::shared_ptr<QuantLib::Instrument> activeUnderlyingInstrument_;
113 mutable bool exercised_;
115 mutable QuantLib::Date exerciseDate_;
116};
117
118//! European Option Wrapper
119/*! A European Option Wrapper will exercise if the underlying NPV is positive
120 */
122public:
123 EuropeanOptionWrapper(const QuantLib::ext::shared_ptr<QuantLib::Instrument>& inst, const bool isLongOption,
124 const QuantLib::Date& exerciseDate, const bool isPhysicalDelivery,
125 const QuantLib::ext::shared_ptr<QuantLib::Instrument>& undInst,
126 // multiplier as seen from the option holder
127 const Real multiplier = 1.0,
128 // undMultiplier w.r.t. underlying as seen from the option holder
129 const Real undMultiplier = 1.0,
130 const std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>& additionalInstruments =
131 std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>(),
132 const std::vector<Real>& additionalMultipliers = std::vector<Real>())
133 : OptionWrapper(inst, isLongOption, std::vector<QuantLib::Date>(1, exerciseDate), isPhysicalDelivery,
134 std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>(1, undInst), multiplier, undMultiplier,
136
137 bool exercise() const override;
138};
139
140//! American Option Wrapper
141/*! An American Option Wrapper will exercise whenever the underlying NPV is greater than
142 the option NPV. On the last date it will exercise if the underlying is positive.
143 */
145public:
146 AmericanOptionWrapper(const QuantLib::ext::shared_ptr<QuantLib::Instrument>& inst, const bool isLongOption,
147 const QuantLib::Date& exerciseDate, const bool isPhysicalDelivery,
148 const QuantLib::ext::shared_ptr<QuantLib::Instrument>& undInst,
149 // multiplier as seen from the option holder
150 const Real multiplier = 1.0,
151 // undMultiplier w.r.t. underlying as seen from the option holder
152 const Real undMultiplier = 1.0,
153 const std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>& additionalInstruments =
154 std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>(),
155 const std::vector<Real>& additionalMultipliers = std::vector<Real>())
156 : OptionWrapper(inst, isLongOption, std::vector<QuantLib::Date>(1, exerciseDate), isPhysicalDelivery,
157 std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>(1, undInst), multiplier, undMultiplier,
159
160 bool exercise() const override;
161};
162
163//! Bermudan Option Wrapper
164/*! A Bermudan Option Wrapper will exercise when the relevant underlying's NPV exceeds the
165 * option NPV. If only one exercise date is remaining, an analytic European pricing engine is used.
166 */
168public:
169 BermudanOptionWrapper(const QuantLib::ext::shared_ptr<QuantLib::Instrument>& inst, const bool isLongOption,
170 const std::vector<QuantLib::Date>& exerciseDates, const bool isPhysicalDelivery,
171 const std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>& undInsts,
172 // multiplier as seen from the option holder
173 const Real multiplier = 1.0,
174 // undMultiplier w.r.t. underlying as seen from the option holder
175 const Real undMultiplier = 1.0,
176 const std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>& additionalInstruments =
177 std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>(),
178 const std::vector<Real>& additionalMultipliers = std::vector<Real>())
179 : OptionWrapper(inst, isLongOption, exerciseDates, isPhysicalDelivery, undInsts, multiplier, undMultiplier,
181 QL_REQUIRE(exerciseDates.size() == undInsts.size(),
182 "sizes of exercise date and underlying instrument vectors do not match");
183 }
184
185 bool exercise() const override;
186
187private:
188 /*! Check if European engine can be used */
189 bool convertToEuropean() const;
190 QuantLib::ext::shared_ptr<QuantLib::Instrument> getUnderlying() const;
191};
192} // namespace data
193} // namespace ore
American Option Wrapper.
bool exercise() const override
AmericanOptionWrapper(const QuantLib::ext::shared_ptr< QuantLib::Instrument > &inst, const bool isLongOption, const QuantLib::Date &exerciseDate, const bool isPhysicalDelivery, const QuantLib::ext::shared_ptr< QuantLib::Instrument > &undInst, const Real multiplier=1.0, const Real undMultiplier=1.0, const std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > &additionalInstruments=std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > >(), const std::vector< Real > &additionalMultipliers=std::vector< Real >())
Bermudan Option Wrapper.
QuantLib::ext::shared_ptr< QuantLib::Instrument > getUnderlying() const
bool exercise() const override
BermudanOptionWrapper(const QuantLib::ext::shared_ptr< QuantLib::Instrument > &inst, const bool isLongOption, const std::vector< QuantLib::Date > &exerciseDates, const bool isPhysicalDelivery, const std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > &undInsts, const Real multiplier=1.0, const Real undMultiplier=1.0, const std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > &additionalInstruments=std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > >(), const std::vector< Real > &additionalMultipliers=std::vector< Real >())
European Option Wrapper.
EuropeanOptionWrapper(const QuantLib::ext::shared_ptr< QuantLib::Instrument > &inst, const bool isLongOption, const QuantLib::Date &exerciseDate, const bool isPhysicalDelivery, const QuantLib::ext::shared_ptr< QuantLib::Instrument > &undInst, const Real multiplier=1.0, const Real undMultiplier=1.0, const std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > &additionalInstruments=std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > >(), const std::vector< Real > &additionalMultipliers=std::vector< Real >())
bool exercise() const override
const std::vector< Real > & additionalMultipliers() const
virtual void updateQlInstruments()
call update on enclosed instrument(s)
const std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > & additionalInstruments() const
Real getTimedNPV(const QuantLib::ext::shared_ptr< QuantLib::Instrument > &instr) const
const QuantLib::Date & exerciseDate() const
the (actual) date the option was exercised
QuantLib::Real NPV() const override
Return the NPV of this instrument.
QuantLib::Date exerciseDate_
bool isOption() override
is it an Option?
virtual bool exercise() const =0
const std::map< std::string, boost::any > & additionalResults() const override
Return the additional results of this instrument.
void enableExercise()
disable exercise decisions
std::vector< QuantLib::Date > effectiveExerciseDates_
const std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > & underlyingInstruments() const
return the underlying instruments
void updateQlInstruments() override
call update on enclosed instrument(s)
void disableExercise()
enable exercise decisions
Real underlyingMultiplier() const
the underlying multiplier
bool isExercised() const
return true if option is exercised
void initialise(const std::vector< QuantLib::Date > &dates) override
Initialise with the given date grid.
QuantLib::ext::shared_ptr< QuantLib::Instrument > activeUnderlyingInstrument_
const QuantLib::ext::shared_ptr< QuantLib::Instrument > & activeUnderlyingInstrument(const bool calculate=false) const
Real multiplier2() const override
bool isPhysicalDelivery() const
return true for physical delivery, false for cash settlement
bool isLong() const
return true if option is long, false if option is short
void reset() override
reset is called every time a new path is about to be priced.
std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > underlyingInstruments_
std::vector< QuantLib::Date > contractExerciseDates_
Base class for wrapper of QL instrument, used to store "state" of trade under each scenario.
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23