Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
DoubleBarrierOptionWrapper Class Reference

#include <ored/portfolio/barrieroptionwrapper.hpp>

+ Inheritance diagram for DoubleBarrierOptionWrapper:
+ Collaboration diagram for DoubleBarrierOptionWrapper:

Public Member Functions

 DoubleBarrierOptionWrapper (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, DoubleBarrier::Type barrierType, Handle< Quote > spot, Real barrierLow, Real barrierHigh, Real rebate, const QuantLib::Currency ccy, const QuantLib::Date &startDate, const QuantLib::ext::shared_ptr< QuantLib::Index > &index, const QuantLib::Calendar &calendar, 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 checkBarrier (Real spot, bool isTouchingOnly) const override
 
bool exercise () const override
 
- Public Member Functions inherited from BarrierOptionWrapper
 BarrierOptionWrapper (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, Barrier::Type barrierType, Handle< Quote > spot, Real rebate, const QuantLib::Currency ccy, const QuantLib::Date &startDate, const QuantLib::ext::shared_ptr< QuantLib::Index > &index, const QuantLib::Calendar &calendar, 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 >())
 
const std::map< std::string, boost::any > & additionalResults () const override
 Return the additional results of this instrument. More...
 
virtual bool checkBarrier (Real, bool) const =0
 
- Public Member Functions inherited from 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. More...
 
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...
 
- 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...
 

Protected Attributes

Real barrierLow_
 
Real barrierHigh_
 
- Protected Attributes inherited from BarrierOptionWrapper
Handle< Quote > spot_
 
Barrier::Type barrierType_
 
Real rebate_
 
const QuantLib::Currency ccy_
 
const QuantLib::Date startDate_
 
QuantLib::ext::shared_ptr< QuantLib::Index > index_
 
QuantLib::Calendar calendar_
 
- Protected Attributes inherited from OptionWrapper
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_
 
- 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
 

Additional Inherited Members

- Protected Member Functions inherited from BarrierOptionWrapper
QuantLib::Real NPV () const override
 Return the NPV of this instrument. More...
 
- Protected Member Functions inherited from InstrumentWrapper
Real getTimedNPV (const QuantLib::ext::shared_ptr< QuantLib::Instrument > &instr) const
 

Detailed Description

Definition at line 103 of file barrieroptionwrapper.hpp.

Constructor & Destructor Documentation

◆ DoubleBarrierOptionWrapper()

DoubleBarrierOptionWrapper ( 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,
DoubleBarrier::Type  barrierType,
Handle< Quote >  spot,
Real  barrierLow,
Real  barrierHigh,
Real  rebate,
const QuantLib::Currency  ccy,
const QuantLib::Date &  startDate,
const QuantLib::ext::shared_ptr< QuantLib::Index > &  index,
const QuantLib::Calendar &  calendar,
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>() 
)

Definition at line 105 of file barrieroptionwrapper.hpp.

119 inst, isLongOption, exerciseDate, isPhysicalDelivery, undInst,
120 (barrierType == DoubleBarrier::Type::KnockOut ? Barrier::Type::UpOut : Barrier::Type::UpIn), spot, rebate,
121 ccy, startDate, index, calendar, multiplier, undMultiplier, additionalInstruments, additionalMultipliers),
122 barrierLow_(barrierLow), barrierHigh_(barrierHigh) {
123 QL_REQUIRE(barrierType == DoubleBarrier::Type::KnockOut || barrierType == DoubleBarrier::Type::KnockIn,
124 "Invalid barrier type " << barrierType << ". Only KnockOut and KnockIn are supported.");
125 QL_REQUIRE(barrierLow < barrierHigh, "barrierLow has to be less than barrierHigh");
126 }
BarrierOptionWrapper(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, Barrier::Type barrierType, Handle< Quote > spot, Real rebate, const QuantLib::Currency ccy, const QuantLib::Date &startDate, const QuantLib::ext::shared_ptr< QuantLib::Index > &index, const QuantLib::Calendar &calendar, 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 >())
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
bool isPhysicalDelivery() const
return true for physical delivery, false for cash settlement
Calendar calendar
Definition: utilities.cpp:441

Member Function Documentation

◆ checkBarrier()

bool checkBarrier ( Real  spot,
bool  isTouchingOnly 
) const
overridevirtual

Implements BarrierOptionWrapper.

Definition at line 174 of file barrieroptionwrapper.cpp.

174 {
175 if (isTouchingOnly)
176 return close_enough(spot, barrierLow_) || close_enough(spot, barrierHigh_);
177 else
178 return spot <= barrierLow_ || spot >= barrierHigh_;
179}
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exercise()

bool exercise ( ) const
overridevirtual

Implements OptionWrapper.

Definition at line 181 of file barrieroptionwrapper.cpp.

181 {
182 bool trigger = false;
183 Date today = Settings::instance().evaluationDate();
184
185 // check historical fixings - only check if the instrument is not calculated
186 // really only needs to be checked if evaluation date changed
187 if (!instrument_->isCalculated()) {
188 if (startDate_ != Date() && startDate_ < today) {
189 QL_REQUIRE(index_, "no index provided");
190 QL_REQUIRE(calendar_ != Calendar(), "no calendar provided");
191
192
193 QuantLib::ext::shared_ptr<QuantExt::EqFxIndexBase> eqfxIndex =
194 QuantLib::ext::dynamic_pointer_cast<QuantExt::EqFxIndexBase>(index_);
195
196 if (eqfxIndex) {
197 Date d = calendar_.adjust(startDate_);
198 while (d < today && !trigger) {
199 Real fixing = eqfxIndex->pastFixing(d);
200 if (fixing == Null<Real>()) {
201 StructuredMessage(
203 "Missing fixing for index " + index_->name() + " on " + ore::data::to_string(d) +
204 ", Skipping this date, assuming no trigger",
205 std::map<std::string, std::string>({{"exceptionType", "Invalid or missing fixings"}}))
206 .log();
207 } else {
208 const bool isTouchingOnly = false;
209 trigger = checkBarrier(fixing, isTouchingOnly);
210 }
211 d = calendar_.advance(d, 1, Days);
212 }
213 }
214 }
215 }
216
217 // check todays spot, if triggered today set the exerciseDate, may have to pay a rebate
218 if (!trigger) {
219 const bool isTouchingOnly = false;
220 trigger = checkBarrier(spot_->value(), isTouchingOnly);
221 exerciseDate_ = today;
222 }
223
224 exercised_ = trigger;
225 return trigger;
226}
QuantLib::ext::shared_ptr< QuantLib::Index > index_
bool checkBarrier(Real spot, bool isTouchingOnly) const override
QuantLib::ext::shared_ptr< QuantLib::Instrument > instrument_
QuantLib::Date exerciseDate_
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:

Member Data Documentation

◆ barrierLow_

Real barrierLow_
protected

Definition at line 132 of file barrieroptionwrapper.hpp.

◆ barrierHigh_

Real barrierHigh_
protected

Definition at line 133 of file barrieroptionwrapper.hpp.