Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
instrumentwrapper.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
20
21namespace ore {
22namespace data {
23
24InstrumentWrapper::InstrumentWrapper() : instrument_(nullptr), multiplier_(1.0) {}
25
26InstrumentWrapper::InstrumentWrapper(const QuantLib::ext::shared_ptr<QuantLib::Instrument>& inst, const Real multiplier,
27 const std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>& additionalInstruments,
28 const std::vector<Real>& additionalMultipliers)
29 : instrument_(inst), multiplier_(multiplier), additionalInstruments_(additionalInstruments),
30 additionalMultipliers_(additionalMultipliers) {
31 QL_REQUIRE(additionalInstruments_.size() == additionalMultipliers_.size(),
32 "vector size mismatch, instruments (" << additionalInstruments_.size() << ") vs multipliers ("
33 << additionalMultipliers_.size() << ")");
34}
35
37 Real npv = 0.0;
38 for (QuantLib::Size i = 0; i < additionalInstruments_.size(); ++i)
40 return npv;
41}
42
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}
49
50bool InstrumentWrapper::isOption() { return false; }
51
52QuantLib::ext::shared_ptr<QuantLib::Instrument> InstrumentWrapper::qlInstrument(const bool calculate) const {
53 if (calculate && instrument_ != nullptr) {
55 }
56 return instrument_;
57}
58
60
61Real InstrumentWrapper::multiplier2() const { return 1.0; }
62
63const std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>& InstrumentWrapper::additionalInstruments() const {
65}
66
67const std::vector<Real>& InstrumentWrapper::additionalMultipliers() const { return additionalMultipliers_; }
68
69boost::timer::nanosecond_type InstrumentWrapper::getCumulativePricingTime() const { return cumulativePricingTime_; }
70
72
76}
77
78Real InstrumentWrapper::getTimedNPV(const QuantLib::ext::shared_ptr<QuantLib::Instrument>& instr) const {
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}
89
90VanillaInstrument::VanillaInstrument(const QuantLib::ext::shared_ptr<QuantLib::Instrument>& inst, const Real multiplier,
91 const std::vector<QuantLib::ext::shared_ptr<QuantLib::Instrument>>& additionalInstruments,
92 const std::vector<Real>& additionalMultipliers)
93 : InstrumentWrapper(inst, multiplier, additionalInstruments, additionalMultipliers) {}
94
95QuantLib::Real VanillaInstrument::NPV() const {
97}
98
99const std::map<std::string, boost::any>& VanillaInstrument::additionalResults() const {
100 static std::map<std::string, boost::any> empty;
101 if (instrument_ == nullptr)
102 return empty;
104 return instrument_->additionalResults();
105}
106
107} // namespace data
108} // namespace ore
const std::vector< Real > & additionalMultipliers() const
virtual Real multiplier2() const
std::size_t getNumberOfPricings() const
Get number of pricings.
virtual QuantLib::Real NPV() const =0
Return the NPV of this instrument.
virtual bool isOption()
is it an Option?
virtual void updateQlInstruments()
call update on enclosed instrument(s)
const std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > & additionalInstruments() const
std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > additionalInstruments_
boost::timer::nanosecond_type cumulativePricingTime_
QuantLib::Real additionalInstrumentsNPV() const
boost::timer::nanosecond_type getCumulativePricingTime() const
Get cumulative timing spent on pricing.
Real getTimedNPV(const QuantLib::ext::shared_ptr< QuantLib::Instrument > &instr) const
std::vector< Real > additionalMultipliers_
void resetPricingStats() const
Reset pricing statistics.
QuantLib::ext::shared_ptr< QuantLib::Instrument > instrument_
QuantLib::ext::shared_ptr< QuantLib::Instrument > qlInstrument(const bool calculate=false) const
Inspectors.
VanillaInstrument(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 >())
QuantLib::Real NPV() const override
Return the NPV of this instrument.
const std::map< std::string, boost::any > & additionalResults() const override
Return the additional results of this instrument.
Base class for wrapper of QL instrument, used to store "state" of trade under each scenario.
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23