Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | List of all members
OptionWrapper Class Referenceabstract

Option Wrapper. More...

#include <ored/portfolio/optionwrapper.hpp>

+ Inheritance diagram for OptionWrapper:
+ Collaboration diagram for OptionWrapper:

Public Member Functions

 OptionWrapper (const QuantLib::ext::shared_ptr< QuantLib::Instrument > &inst, const bool isLongOption, const std::vector< QuantLib::Date > &exerciseDate, const bool isPhysicalDelivery, const std::vector< 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 >())
 Constructor. More...
 
- Public Member Functions inherited from InstrumentWrapper
 InstrumentWrapper ()
 
 InstrumentWrapper (const QuantLib::ext::shared_ptr< QuantLib::Instrument > &inst, const Real multiplier=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 >())
 
virtual ~InstrumentWrapper ()
 
virtual void initialise (const std::vector< QuantLib::Date > &dates)=0
 Initialise with the given date grid. More...
 
virtual void reset ()=0
 reset is called every time a new path is about to be priced. More...
 
virtual QuantLib::Real NPV () const =0
 Return the NPV of this instrument. More...
 
virtual const std::map< std::string, boost::any > & additionalResults () const =0
 Return the additional results of this instrument. More...
 
QuantLib::Real additionalInstrumentsNPV () const
 
virtual void updateQlInstruments ()
 call update on enclosed instrument(s) More...
 
virtual bool isOption ()
 is it an Option? More...
 
QuantLib::ext::shared_ptr< QuantLib::Instrument > qlInstrument (const bool calculate=false) const
 Inspectors. More...
 
Real multiplier () const
 
virtual Real multiplier2 () const
 
const std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > & additionalInstruments () const
 
const std::vector< Real > & additionalMultipliers () const
 
boost::timer::nanosecond_type getCumulativePricingTime () const
 Get cumulative timing spent on pricing. More...
 
std::size_t getNumberOfPricings () const
 Get number of pricings. More...
 
void resetPricingStats () const
 Reset pricing statistics. More...
 

InstrumentWrapper interface

bool isLong_
 
bool isPhysicalDelivery_
 
std::vector< QuantLib::Date > contractExerciseDates_
 
std::vector< QuantLib::Date > effectiveExerciseDates_
 
std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > underlyingInstruments_
 
QuantLib::ext::shared_ptr< QuantLib::Instrument > activeUnderlyingInstrument_
 
Real undMultiplier_
 
bool exercised_
 
bool exercisable_
 
QuantLib::Date exerciseDate_
 
void initialise (const std::vector< QuantLib::Date > &dates) override
 Initialise with the given date grid. More...
 
void reset () override
 reset is called every time a new path is about to be priced. More...
 
QuantLib::Real NPV () const override
 Return the NPV of this instrument. More...
 
Real multiplier2 () const override
 
const std::map< std::string, boost::any > & additionalResults () const override
 Return the additional results of this instrument. More...
 
void updateQlInstruments () override
 call update on enclosed instrument(s) More...
 
bool isOption () override
 is it an Option? More...
 
const std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > & underlyingInstruments () const
 return the underlying instruments More...
 
const QuantLib::ext::shared_ptr< QuantLib::Instrument > & activeUnderlyingInstrument (const bool calculate=false) const
 
bool isLong () const
 return true if option is long, false if option is short More...
 
bool isExercised () const
 return true if option is exercised More...
 
bool isPhysicalDelivery () const
 return true for physical delivery, false for cash settlement More...
 
Real underlyingMultiplier () const
 the underlying multiplier More...
 
const QuantLib::Date & exerciseDate () const
 the (actual) date the option was exercised More...
 
void enableExercise ()
 disable exercise decisions More...
 
void disableExercise ()
 enable exercise decisions More...
 
virtual bool exercise () const =0
 

Additional Inherited Members

- Protected Member Functions inherited from InstrumentWrapper
Real getTimedNPV (const QuantLib::ext::shared_ptr< QuantLib::Instrument > &instr) const
 
- Protected Attributes inherited from InstrumentWrapper
QuantLib::ext::shared_ptr< QuantLib::Instrument > instrument_
 
Real multiplier_
 
std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > additionalInstruments_
 
std::vector< Real > additionalMultipliers_
 
std::size_t numberOfPricings_ = 0
 
boost::timer::nanosecond_type cumulativePricingTime_ = 0
 

Detailed Description

Option Wrapper.

Wrapper Class for Options Prices underlying instrument if option has been exercised Handles Physical and Cash Settlement

Definition at line 39 of file optionwrapper.hpp.

Constructor & Destructor Documentation

◆ OptionWrapper()

OptionWrapper ( const QuantLib::ext::shared_ptr< QuantLib::Instrument > &  inst,
const bool  isLongOption,
const std::vector< QuantLib::Date > &  exerciseDate,
const bool  isPhysicalDelivery,
const std::vector< 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>() 
)

Constructor.

Definition at line 29 of file optionwrapper.cpp.

38 activeUnderlyingInstrument_(undInst.at(0)), undMultiplier_(undMultiplier), exercised_(false), exercisable_(true),
39 exerciseDate_(Date()) {
40 QL_REQUIRE(exerciseDate.size() == undInst.size(), "number of exercise dates ("
41 << exerciseDate.size()
42 << ") must be equal to underlying instrument vector size ("
43 << undInst.size() << ")");
44}
const std::vector< Real > & additionalMultipliers() const
const std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > & additionalInstruments() const
const QuantLib::Date & exerciseDate() const
the (actual) date the option was exercised
QuantLib::Date exerciseDate_
std::vector< QuantLib::Date > effectiveExerciseDates_
QuantLib::ext::shared_ptr< QuantLib::Instrument > activeUnderlyingInstrument_
bool isPhysicalDelivery() const
return true for physical delivery, false for cash settlement
std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > underlyingInstruments_
std::vector< QuantLib::Date > contractExerciseDates_
+ Here is the call graph for this function:

Member Function Documentation

◆ initialise()

void initialise ( const std::vector< QuantLib::Date > &  dates)
overridevirtual

Initialise with the given date grid.

Implements InstrumentWrapper.

Definition at line 46 of file optionwrapper.cpp.

46 {
47 // set "effective" exercise dates which get used to determine exercise during cube valuation
48 // this is necessary since there is no guarantee that actual exercise dates are included in
49 // the valuation date grid
50 Date today = Settings::instance().evaluationDate();
51 for (Size i = 0; i < contractExerciseDates_.size(); ++i) {
52 effectiveExerciseDates_[i] = Null<Date>();
53 if (contractExerciseDates_[i] > today && contractExerciseDates_[i] <= dateGrid.back()) {
54 // Find the effective exercise date in our grid. We simulate the exercise just after the actual
55 // exercise.This ensures that the QL instrument's NPV is a proper continuation value, i.e.
56 // does not contain the possibility of exercising in to the underlying on the current exercise
57 // date and can therefore it be used as such in the exercise decision made in the exercise()
58 // method of derived classes.
59 auto it = std::lower_bound(dateGrid.begin(), dateGrid.end(), contractExerciseDates_[i]);
61 }
62 }
63}

◆ reset()

void reset ( )
overridevirtual

reset is called every time a new path is about to be priced.

For path dependent Wrappers, this is when internal state should be reset

Implements InstrumentWrapper.

Definition at line 65 of file optionwrapper.cpp.

65 {
66 exercised_ = false;
67 exerciseDate_ = Date();
68}
+ Here is the caller graph for this function:

◆ NPV()

Real NPV ( ) const
overridevirtual

Return the NPV of this instrument.

Implements InstrumentWrapper.

Definition at line 70 of file optionwrapper.cpp.

70 {
71 Real addNPV = additionalInstrumentsNPV();
72
73 Date today = Settings::instance().evaluationDate();
74 if (!exercised_) {
75 for (Size i = 0; i < effectiveExerciseDates_.size(); ++i) {
76 if (today == effectiveExerciseDates_[i]) {
77 if (exercise()) {
78 exercised_ = true;
79 exerciseDate_ = today;
80 }
81 }
82 }
83 }
84 if (exercised_) {
85 // if exercised, return underlying npv for physical settlement and also for
86 // cash settlement if we are still on the exercise date (since the cash
87 // settlement takes place strictly after the exercise date usually)
88 // FIXME: we assume that the settlement date lies strictly after the exercise
89 // date, but before or on the next simulation date. Check this explicitly
90 // by introducing the cash settlement date into the option wrapper (note
91 // that we will probably need an effective cash settlement date then to
92 // maintain the relative position to the effective exercise date).
93 Real npv = (isPhysicalDelivery_ || today == exerciseDate_)
95 : 0.0;
96 return npv + addNPV;
97 } else {
98 // if not exercised we just return the original option's NPV
100 return npv + addNPV;
101 }
102}
QuantLib::Real additionalInstrumentsNPV() const
Real getTimedNPV(const QuantLib::ext::shared_ptr< QuantLib::Instrument > &instr) const
QuantLib::ext::shared_ptr< QuantLib::Instrument > instrument_
virtual bool exercise() const =0
Real multiplier2() const override
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ multiplier2()

Real multiplier2 ( ) const
overridevirtual

multiplier to be applied on top of multiplier(), e.g. -1 for short options

Reimplemented from InstrumentWrapper.

Definition at line 57 of file optionwrapper.hpp.

57{ return (isLong_ ? 1.0 : -1.0); }
+ Here is the caller graph for this function:

◆ additionalResults()

const std::map< std::string, boost::any > & additionalResults ( ) const
overridevirtual

Return the additional results of this instrument.

Implements InstrumentWrapper.

Definition at line 104 of file optionwrapper.cpp.

104 {
105 static std::map<std::string, boost::any> emptyMap;
106 NPV();
107 if (exercised_) {
108 if (activeUnderlyingInstrument_ != nullptr)
109 return activeUnderlyingInstrument_->additionalResults();
110 else
111 return emptyMap;
112 } else {
113 return instrument_->additionalResults();
114 }
115}
QuantLib::Real NPV() const override
Return the NPV of this instrument.
+ Here is the call graph for this function:

◆ updateQlInstruments()

void updateQlInstruments ( )
overridevirtual

call update on enclosed instrument(s)

Reimplemented from InstrumentWrapper.

Definition at line 59 of file optionwrapper.hpp.

59 {
60 for (QuantLib::Size i = 0; i < underlyingInstruments_.size(); ++i)
61 underlyingInstruments_[i]->update();
63 }
virtual void updateQlInstruments()
call update on enclosed instrument(s)
+ Here is the call graph for this function:

◆ isOption()

bool isOption ( )
overridevirtual

is it an Option?

Reimplemented from InstrumentWrapper.

Definition at line 64 of file optionwrapper.hpp.

64{ return true; }

◆ underlyingInstruments()

const std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > & underlyingInstruments ( ) const

return the underlying instruments

Definition at line 68 of file optionwrapper.hpp.

68 {
70 }

◆ activeUnderlyingInstrument()

const QuantLib::ext::shared_ptr< QuantLib::Instrument > & activeUnderlyingInstrument ( const bool  calculate = false) const

return the active underlying instrument Pass true if you trigger a calculation on the returned instrument and want to record the timing for that calculation. If in doubt whether a calculation is triggered, pass false.

Definition at line 75 of file optionwrapper.hpp.

75 {
76 if (calculate && activeUnderlyingInstrument_ != nullptr) {
78 }
80 }
+ Here is the call graph for this function:

◆ isLong()

bool isLong ( ) const

return true if option is long, false if option is short

Definition at line 83 of file optionwrapper.hpp.

83{ return isLong_; }

◆ isExercised()

bool isExercised ( ) const

return true if option is exercised

Definition at line 86 of file optionwrapper.hpp.

86{ return exercised_; }

◆ isPhysicalDelivery()

bool isPhysicalDelivery ( ) const

return true for physical delivery, false for cash settlement

Definition at line 89 of file optionwrapper.hpp.

89{ return isPhysicalDelivery_; }

◆ underlyingMultiplier()

Real underlyingMultiplier ( ) const

the underlying multiplier

Definition at line 92 of file optionwrapper.hpp.

92{ return undMultiplier_; }

◆ exerciseDate()

const QuantLib::Date & exerciseDate ( ) const

the (actual) date the option was exercised

Definition at line 95 of file optionwrapper.hpp.

95{ return exerciseDate_; }
+ Here is the caller graph for this function:

◆ enableExercise()

void enableExercise ( )

disable exercise decisions

Definition at line 98 of file optionwrapper.hpp.

98{ exercisable_ = true; }

◆ disableExercise()

void disableExercise ( )

enable exercise decisions

Definition at line 101 of file optionwrapper.hpp.

101{ exercisable_ = false; }

◆ exercise()

virtual bool exercise ( ) const
pure virtual

Implemented in SingleBarrierOptionWrapper, DoubleBarrierOptionWrapper, EuropeanOptionWrapper, AmericanOptionWrapper, and BermudanOptionWrapper.

+ Here is the caller graph for this function:

Member Data Documentation

◆ isLong_

bool isLong_
protected

Definition at line 106 of file optionwrapper.hpp.

◆ isPhysicalDelivery_

bool isPhysicalDelivery_
protected

Definition at line 107 of file optionwrapper.hpp.

◆ contractExerciseDates_

std::vector<QuantLib::Date> contractExerciseDates_
protected

Definition at line 108 of file optionwrapper.hpp.

◆ effectiveExerciseDates_

std::vector<QuantLib::Date> effectiveExerciseDates_
protected

Definition at line 109 of file optionwrapper.hpp.

◆ underlyingInstruments_

std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument> > underlyingInstruments_
protected

Definition at line 110 of file optionwrapper.hpp.

◆ activeUnderlyingInstrument_

QuantLib::ext::shared_ptr<QuantLib::Instrument> activeUnderlyingInstrument_
mutableprotected

Definition at line 111 of file optionwrapper.hpp.

◆ undMultiplier_

Real undMultiplier_
protected

Definition at line 112 of file optionwrapper.hpp.

◆ exercised_

bool exercised_
mutableprotected

Definition at line 113 of file optionwrapper.hpp.

◆ exercisable_

bool exercisable_
protected

Definition at line 114 of file optionwrapper.hpp.

◆ exerciseDate_

QuantLib::Date exerciseDate_
mutableprotected

Definition at line 115 of file optionwrapper.hpp.