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

Barrier Option Wrapper. More...

#include <ored/portfolio/barrieroptionwrapper.hpp>

+ Inheritance diagram for BarrierOptionWrapper:
+ Collaboration diagram for BarrierOptionWrapper:

Public Member Functions

 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...
 
virtual bool exercise () const =0
 
- 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 Member Functions

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
 

Protected Attributes

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
 

Detailed Description

Barrier Option Wrapper.

An Barrier Option Wrapper will exercise whenever the barrier is touched. If it is an 'out' option it will pay the rebate value when exercised

Definition at line 39 of file barrieroptionwrapper.hpp.

Constructor & Destructor Documentation

◆ 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>() 
)

Definition at line 41 of file barrieroptionwrapper.hpp.

54 : OptionWrapper(inst, isLongOption, std::vector<QuantLib::Date>(1, exerciseDate), isPhysicalDelivery,
55 std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>(1, undInst), multiplier, undMultiplier,
57 spot_(spot), barrierType_(barrierType), rebate_(rebate), ccy_(ccy), startDate_(startDate),
58 index_(index) {
59 calendar_ = index ? index->fixingCalendar() : calendar;
60 reset();
61 }
QuantLib::ext::shared_ptr< QuantLib::Index > index_
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
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.
bool isPhysicalDelivery() const
return true for physical delivery, false for cash settlement
void reset() override
reset is called every time a new path is about to be priced.
Calendar calendar
Definition: utilities.cpp:441
+ Here is the call graph for this function:

Member Function Documentation

◆ additionalResults()

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

Return the additional results of this instrument.

Implements InstrumentWrapper.

Definition at line 80 of file barrieroptionwrapper.cpp.

80 {
81 static std::map<std::string, boost::any> emptyMap;
82 NPV();
83 if (exercised_) {
84 if (!(barrierType_ == Barrier::DownOut || barrierType_ == Barrier::UpOut))
85 return activeUnderlyingInstrument_->additionalResults();
86 else
87 return emptyMap;
88 } else {
89 auto vanillaOption = QuantLib::ext::dynamic_pointer_cast<VanillaOption>(activeUnderlyingInstrument_);
90 if (vanillaOption) {
91 auto payoff = QuantLib::ext::dynamic_pointer_cast<StrikedTypePayoff>(vanillaOption->payoff());
92 if (payoff && ((barrierType_ == Barrier::DownOut && payoff->optionType() == Option::Put) ||
93 (barrierType_ == Barrier::UpOut && payoff->optionType() == Option::Call))) {
94 const bool isTouchingOnly = true;
95 if (checkBarrier(payoff->strike(), isTouchingOnly))
96 return emptyMap;
97 }
98 }
99
100 return instrument_->additionalResults();
101 }
102}
QuantLib::Real NPV() const override
Return the NPV of this instrument.
virtual bool checkBarrier(Real, bool) const =0
QuantLib::ext::shared_ptr< QuantLib::Instrument > instrument_
QuantLib::ext::shared_ptr< QuantLib::Instrument > activeUnderlyingInstrument_
+ Here is the call graph for this function:

◆ checkBarrier()

virtual bool checkBarrier ( Real  ,
bool   
) const
pure virtual

Implemented in SingleBarrierOptionWrapper, and DoubleBarrierOptionWrapper.

+ Here is the caller graph for this function:

◆ NPV()

Real NPV ( ) const
overrideprotectedvirtual

Return the NPV of this instrument.

Implements InstrumentWrapper.

Definition at line 40 of file barrieroptionwrapper.cpp.

40 {
41 Real addNPV = additionalInstrumentsNPV();
42
43 Date today = Settings::instance().evaluationDate();
44
45 // check the trigger on the first run, we only need to re check it if the
46 // instrument becomes un calculated. The trigger should only need to be rechecked
47 // for a change in valuation date or spot, and this ensures
48 if (!exercised_ || !instrument_->isCalculated()) {
49 exercise();
50 }
51
52 if (exercised_) {
53 Real npv;
54 if (barrierType_ == Barrier::DownOut || barrierType_ == Barrier::UpOut)
55 npv = (today == exerciseDate_) ? multiplier2() * rebate_ * undMultiplier_ : 0.0;
56 else
58
59 return npv + addNPV;
60 } else {
61 // if not exercised we just return the original option's NPV
63
64 // Handling the edge case where barrier = strike, is KO, and underlying is only ITM when inside KO barrier.
65 // NPV should then be zero, but the pricing engine might not necessarily be pricing it as zero at the boundary.
66 auto vanillaOption = QuantLib::ext::dynamic_pointer_cast<VanillaOption>(activeUnderlyingInstrument_);
67 if (vanillaOption) {
68 auto payoff = QuantLib::ext::dynamic_pointer_cast<StrikedTypePayoff>(vanillaOption->payoff());
69 if (payoff && ((barrierType_ == Barrier::DownOut && payoff->optionType() == Option::Put) ||
70 (barrierType_ == Barrier::UpOut && payoff->optionType() == Option::Call))) {
71 const bool isTouchingOnly = true;
72 if (checkBarrier(payoff->strike(), isTouchingOnly))
73 npv = 0;
74 }
75 }
76 return npv + addNPV;
77 }
78}
QuantLib::Real additionalInstrumentsNPV() const
Real getTimedNPV(const QuantLib::ext::shared_ptr< QuantLib::Instrument > &instr) const
QuantLib::Date exerciseDate_
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:

Member Data Documentation

◆ spot_

Handle<Quote> spot_
protected

Definition at line 68 of file barrieroptionwrapper.hpp.

◆ barrierType_

Barrier::Type barrierType_
protected

Definition at line 69 of file barrieroptionwrapper.hpp.

◆ rebate_

Real rebate_
protected

Definition at line 70 of file barrieroptionwrapper.hpp.

◆ ccy_

const QuantLib::Currency ccy_
protected

Definition at line 71 of file barrieroptionwrapper.hpp.

◆ startDate_

const QuantLib::Date startDate_
protected

Definition at line 72 of file barrieroptionwrapper.hpp.

◆ index_

QuantLib::ext::shared_ptr<QuantLib::Index> index_
protected

Definition at line 73 of file barrieroptionwrapper.hpp.

◆ calendar_

QuantLib::Calendar calendar_
protected

Definition at line 74 of file barrieroptionwrapper.hpp.