Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
compositeinstrumentwrapper.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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
25 const std::vector<QuantLib::ext::shared_ptr<InstrumentWrapper>>& wrappers, const std::vector<Handle<Quote>>& fxRates,
26 const Date& valuationDate)
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}
39
40void CompositeInstrumentWrapper::initialise(const std::vector<QuantLib::Date>& dates) {
41 for (auto& w : wrappers_)
42 w->initialise(dates);
43};
44
46 for (auto& w : wrappers_) {
47 w->reset();
48 }
49}
50
51QuantLib::Real CompositeInstrumentWrapper::NPV() const {
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}
67
68const std::map<std::string, boost::any>& CompositeInstrumentWrapper::additionalResults() const {
69 additionalResults_.clear();
70 for (auto const& w : wrappers_) {
71 additionalResults_.insert(w->additionalResults().begin(), w->additionalResults().end());
72 }
73 return additionalResults_;
74}
75
77 for (auto& w : wrappers_) {
78 w->updateQlInstruments();
79 }
80}
81
83 for (const auto& w : wrappers_) {
84 if (w->isOption()) {
85 return true;
86 }
87 }
88 return false;
89}
90
91} // namespace data
92} // namespace ore
QuantLib::Real NPV() const override
Return the NPV of this instrument.
std::map< std::string, boost::any > additionalResults_
const std::map< std::string, boost::any > & additionalResults() const override
Return the additional results of this instrument.
void updateQlInstruments() override
call update on enclosed instrument(s)
CompositeInstrumentWrapper(const std::vector< QuantLib::ext::shared_ptr< InstrumentWrapper > > &wrappers, const std::vector< Handle< Quote > > &fxRates={}, const Date &valuationDate=Date())
std::vector< QuantLib::Handle< Quote > > fxRates_
void initialise(const std::vector< QuantLib::Date > &dates) override
Initialise with the given date grid.
std::vector< QuantLib::ext::shared_ptr< InstrumentWrapper > > wrappers_
void reset() override
reset is called every time a new path is about to be priced.
std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > additionalInstruments_
boost::timer::nanosecond_type cumulativePricingTime_
std::vector< Real > additionalMultipliers_
used to store multiple trade wrappers
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23