Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
compositevectorquote.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 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
19/*! \file quotes/compositevectorquote.hpp
20 \brief applies a function of a vector of quotes
21 \ingroup quotes
22*/
23
24#pragma once
25
26#include <ql/quote.hpp>
27
28namespace QuantExt {
29
30using namespace QuantLib;
31
32template <typename Function> class CompositeVectorQuote : public Quote, public Observer {
33public:
34 CompositeVectorQuote(std::vector<Handle<Quote>> q, Function f) : q_(std::move(q)), f_(f) {
35 for (auto const& q : q_)
36 registerWith(q);
37 }
38 Real value() const override {
39 std::vector<Real> v(q_.size());
40 std::transform(q_.begin(), q_.end(), v.begin(), [](const Handle<Quote>& q) { return q->value(); });
41 return f_(v);
42 }
43 bool isValid() const override {
44 return std::all_of(q_.begin(), q_.end(), [](const Handle<Quote>& q) { return q->isValid(); });
45 }
46 void update() override { notifyObservers(); }
47
48protected:
49 std::vector<Handle<Quote>> q_;
50 Function f_;
51};
52
53} // namespace QuantExt
CompositeVectorQuote(std::vector< Handle< Quote > > q, Function f)
std::vector< Handle< Quote > > q_