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

Composite Instrument Wrapper. More...

#include <ored/portfolio/compositeinstrumentwrapper.hpp>

+ Inheritance diagram for CompositeInstrumentWrapper:
+ Collaboration diagram for CompositeInstrumentWrapper:

Public Member Functions

 CompositeInstrumentWrapper (const std::vector< QuantLib::ext::shared_ptr< InstrumentWrapper > > &wrappers, const std::vector< Handle< Quote > > &fxRates={}, const Date &valuationDate=Date())
 
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...
 
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...
 
- 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

bool isOption_
 
std::vector< QuantLib::ext::shared_ptr< InstrumentWrapper > > wrappers_
 
std::vector< QuantLib::Handle< Quote > > fxRates_
 
Date valuationDate_
 
std::map< std::string, boost::any > additionalResults_
 
- 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 InstrumentWrapper
Real getTimedNPV (const QuantLib::ext::shared_ptr< QuantLib::Instrument > &instr) const
 

Detailed Description

Composite Instrument Wrapper.

A Composite Instrument Wrapper will return the sum npv for all wrappers passed in. Notice that qlInstrument() will return a nullptr.

Definition at line 52 of file compositeinstrumentwrapper.hpp.

Constructor & Destructor Documentation

◆ CompositeInstrumentWrapper()

CompositeInstrumentWrapper ( const std::vector< QuantLib::ext::shared_ptr< InstrumentWrapper > > &  wrappers,
const std::vector< Handle< Quote > > &  fxRates = {},
const Date &  valuationDate = Date() 
)

Definition at line 24 of file compositeinstrumentwrapper.cpp.

27 : InstrumentWrapper(), wrappers_(wrappers), fxRates_(fxRates), valuationDate_(valuationDate) {
28
29 QL_REQUIRE(wrappers.size() > 0, "no instrument wrappers provided");
30 QL_REQUIRE(fxRates_.empty() || fxRates_.size() == wrappers_.size(), "unexpected number of fxRates provided");
31
32 for (const auto& w : wrappers_) {
33 auto tmp = w->additionalInstruments();
34 auto tmp2 = w->additionalMultipliers();
35 additionalInstruments_.insert(additionalInstruments_.end(), tmp.begin(), tmp.end());
36 additionalMultipliers_.insert(additionalMultipliers_.end(), tmp2.begin(), tmp2.end());
37 }
38}
std::vector< QuantLib::Handle< Quote > > fxRates_
std::vector< QuantLib::ext::shared_ptr< InstrumentWrapper > > wrappers_
std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > additionalInstruments_
std::vector< Real > additionalMultipliers_

Member Function Documentation

◆ initialise()

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

Initialise with the given date grid.

Implements InstrumentWrapper.

Definition at line 40 of file compositeinstrumentwrapper.cpp.

40 {
41 for (auto& w : wrappers_)
42 w->initialise(dates);
43};

◆ 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 45 of file compositeinstrumentwrapper.cpp.

45 {
46 for (auto& w : wrappers_) {
47 w->reset();
48 }
49}

◆ NPV()

QuantLib::Real NPV ( ) const
overridevirtual

Return the NPV of this instrument.

Implements InstrumentWrapper.

Definition at line 51 of file compositeinstrumentwrapper.cpp.

51 {
52 Date today = Settings::instance().evaluationDate();
53 if (valuationDate_ != Date()) {
54 QL_REQUIRE(today == valuationDate_, "today must be the expected valuation date for this trade");
55 }
56 Real npv = 0;
57 for (Size i = 0; i < wrappers_.size(); i++) {
58 npv += wrappers_[i]->NPV() * (fxRates_.empty() ? 1.0 : fxRates_[i]->value());
59 }
60 for (auto& w : wrappers_) {
61 numberOfPricings_ += w->getNumberOfPricings();
62 cumulativePricingTime_ += w->getCumulativePricingTime();
63 w->resetPricingStats();
64 }
65 return npv;
66}
boost::timer::nanosecond_type cumulativePricingTime_

◆ additionalResults()

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

Return the additional results of this instrument.

Implements InstrumentWrapper.

Definition at line 68 of file compositeinstrumentwrapper.cpp.

68 {
69 additionalResults_.clear();
70 for (auto const& w : wrappers_) {
71 additionalResults_.insert(w->additionalResults().begin(), w->additionalResults().end());
72 }
73 return additionalResults_;
74}
std::map< std::string, boost::any > additionalResults_

◆ updateQlInstruments()

void updateQlInstruments ( )
overridevirtual

call update on enclosed instrument(s)

Reimplemented from InstrumentWrapper.

Definition at line 76 of file compositeinstrumentwrapper.cpp.

76 {
77 for (auto& w : wrappers_) {
78 w->updateQlInstruments();
79 }
80}

◆ isOption()

bool isOption ( )
overridevirtual

is it an Option?

Reimplemented from InstrumentWrapper.

Definition at line 82 of file compositeinstrumentwrapper.cpp.

82 {
83 for (const auto& w : wrappers_) {
84 if (w->isOption()) {
85 return true;
86 }
87 }
88 return false;
89}

Member Data Documentation

◆ isOption_

bool isOption_
protected

Definition at line 65 of file compositeinstrumentwrapper.hpp.

◆ wrappers_

std::vector<QuantLib::ext::shared_ptr<InstrumentWrapper> > wrappers_
protected

Definition at line 66 of file compositeinstrumentwrapper.hpp.

◆ fxRates_

std::vector<QuantLib::Handle<Quote> > fxRates_
protected

Definition at line 67 of file compositeinstrumentwrapper.hpp.

◆ valuationDate_

Date valuationDate_
protected

Definition at line 68 of file compositeinstrumentwrapper.hpp.

◆ additionalResults_

std::map<std::string, boost::any> additionalResults_
mutableprotected

Definition at line 69 of file compositeinstrumentwrapper.hpp.