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
InstrumentWrapper Class Referenceabstract

Instrument Wrapper. More...

#include <ored/portfolio/instrumentwrapper.hpp>

+ Inheritance diagram for InstrumentWrapper:
+ Collaboration diagram for InstrumentWrapper:

Public Member Functions

 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

Real getTimedNPV (const QuantLib::ext::shared_ptr< QuantLib::Instrument > &instr) const
 

Protected Attributes

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

Instrument Wrapper.

Wrap Instrument base class Derived classes should

Definition at line 47 of file instrumentwrapper.hpp.

Constructor & Destructor Documentation

◆ InstrumentWrapper() [1/2]

Definition at line 24 of file instrumentwrapper.cpp.

24: instrument_(nullptr), multiplier_(1.0) {}
QuantLib::ext::shared_ptr< QuantLib::Instrument > instrument_

◆ InstrumentWrapper() [2/2]

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

Definition at line 26 of file instrumentwrapper.cpp.

31 QL_REQUIRE(additionalInstruments_.size() == additionalMultipliers_.size(),
32 "vector size mismatch, instruments (" << additionalInstruments_.size() << ") vs multipliers ("
33 << additionalMultipliers_.size() << ")");
34}
const std::vector< Real > & additionalMultipliers() const
const std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > & additionalInstruments() const
std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > additionalInstruments_
std::vector< Real > additionalMultipliers_

◆ ~InstrumentWrapper()

virtual ~InstrumentWrapper ( )
virtual

Definition at line 55 of file instrumentwrapper.hpp.

55{}

Member Function Documentation

◆ initialise()

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

Initialise with the given date grid.

Implemented in VanillaInstrument, BondPositionInstrumentWrapper, CompositeInstrumentWrapper, and OptionWrapper.

◆ reset()

virtual void reset ( )
pure virtual

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

Implemented in BondPositionInstrumentWrapper, CompositeInstrumentWrapper, VanillaInstrument, and OptionWrapper.

◆ NPV()

virtual QuantLib::Real NPV ( ) const
pure virtual

Return the NPV of this instrument.

Implemented in BarrierOptionWrapper, BondPositionInstrumentWrapper, CompositeInstrumentWrapper, VanillaInstrument, and OptionWrapper.

+ Here is the caller graph for this function:

◆ additionalResults()

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

Return the additional results of this instrument.

Implemented in BarrierOptionWrapper, BondPositionInstrumentWrapper, CompositeInstrumentWrapper, VanillaInstrument, and OptionWrapper.

◆ additionalInstrumentsNPV()

QuantLib::Real additionalInstrumentsNPV ( ) const

Definition at line 36 of file instrumentwrapper.cpp.

36 {
37 Real npv = 0.0;
38 for (QuantLib::Size i = 0; i < additionalInstruments_.size(); ++i)
40 return npv;
41}
virtual QuantLib::Real NPV() const =0
Return the NPV of this instrument.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateQlInstruments()

void updateQlInstruments ( )
virtual

call update on enclosed instrument(s)

Reimplemented in BondPositionInstrumentWrapper, CompositeInstrumentWrapper, and OptionWrapper.

Definition at line 43 of file instrumentwrapper.cpp.

43 {
44 // the instrument might contain nested lazy objects which we also want to be updated
45 instrument_->deepUpdate();
46 for (QuantLib::Size i = 0; i < additionalInstruments_.size(); ++i)
47 additionalInstruments_[i]->deepUpdate();
48}
+ Here is the caller graph for this function:

◆ isOption()

bool isOption ( )
virtual

is it an Option?

Reimplemented in CompositeInstrumentWrapper, and OptionWrapper.

Definition at line 50 of file instrumentwrapper.cpp.

50{ return false; }

◆ qlInstrument()

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

Inspectors.

The "QuantLib" 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 52 of file instrumentwrapper.cpp.

52 {
53 if (calculate && instrument_ != nullptr) {
55 }
56 return instrument_;
57}
Real getTimedNPV(const QuantLib::ext::shared_ptr< QuantLib::Instrument > &instr) const
+ Here is the call graph for this function:

◆ multiplier()

Real multiplier ( ) const

The multiplier

Definition at line 59 of file instrumentwrapper.cpp.

59{ return multiplier_; }

◆ multiplier2()

Real multiplier2 ( ) const
virtual

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

Reimplemented in OptionWrapper.

Definition at line 61 of file instrumentwrapper.cpp.

61{ return 1.0; }

◆ additionalInstruments()

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

additional instruments

Definition at line 63 of file instrumentwrapper.cpp.

63 {
65}

◆ additionalMultipliers()

const std::vector< Real > & additionalMultipliers ( ) const

multipliers for additional instruments

Definition at line 67 of file instrumentwrapper.cpp.

67{ return additionalMultipliers_; }

◆ getCumulativePricingTime()

boost::timer::nanosecond_type getCumulativePricingTime ( ) const

Get cumulative timing spent on pricing.

Definition at line 69 of file instrumentwrapper.cpp.

69{ return cumulativePricingTime_; }
boost::timer::nanosecond_type cumulativePricingTime_

◆ getNumberOfPricings()

std::size_t getNumberOfPricings ( ) const

Get number of pricings.

Definition at line 71 of file instrumentwrapper.cpp.

◆ resetPricingStats()

void resetPricingStats ( ) const

Reset pricing statistics.

Definition at line 73 of file instrumentwrapper.cpp.

73 {
76}

◆ getTimedNPV()

Real getTimedNPV ( const QuantLib::ext::shared_ptr< QuantLib::Instrument > &  instr) const
protected

Definition at line 78 of file instrumentwrapper.cpp.

78 {
79 if (instr == nullptr)
80 return 0.0;
81 if (instr->isCalculated() || instr->isExpired())
82 return instr->NPV();
83 boost::timer::cpu_timer timer_;
84 Real tmp = instr->NPV();
85 cumulativePricingTime_ += timer_.elapsed().wall;
87 return tmp;
88}
+ Here is the caller graph for this function:

Member Data Documentation

◆ instrument_

QuantLib::ext::shared_ptr<QuantLib::Instrument> instrument_
protected

Definition at line 109 of file instrumentwrapper.hpp.

◆ multiplier_

Real multiplier_
protected

Definition at line 110 of file instrumentwrapper.hpp.

◆ additionalInstruments_

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

Definition at line 111 of file instrumentwrapper.hpp.

◆ additionalMultipliers_

std::vector<Real> additionalMultipliers_
protected

Definition at line 112 of file instrumentwrapper.hpp.

◆ numberOfPricings_

std::size_t numberOfPricings_ = 0
mutableprotected

Definition at line 117 of file instrumentwrapper.hpp.

◆ cumulativePricingTime_

boost::timer::nanosecond_type cumulativePricingTime_ = 0
mutableprotected

Definition at line 118 of file instrumentwrapper.hpp.