Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
compositeindex.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 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 qle/indexes/compositeindex.hpp
20 \brief index representing a weighted sum of underlying indices
21 \ingroup indexes
22*/
23
24#pragma once
25
27
28#include <ql/currency.hpp>
29#include <ql/handle.hpp>
30#include <ql/index.hpp>
31
32namespace QuantExt {
33using namespace QuantLib;
34
35class CompositeIndex : public Index, public Observer {
36public:
37 /*! fxConversion can be an empty vector or its length should match indices. For components that
38 do not require a conversion, a nullptr should be given, otherwise a FxIndex with domestic ccy
39 equal to the target currency of the index */
40 CompositeIndex(const std::string& name, const std::vector<QuantLib::ext::shared_ptr<QuantLib::Index>>& indices,
41 const std::vector<Real>& weights, const std::vector<QuantLib::ext::shared_ptr<FxIndex>>& fxConversion = {});
42
43 //! Index interface
44 std::string name() const override;
45 Calendar fixingCalendar() const override;
46 bool isValidFixingDate(const Date& fixingDate) const override;
47 Real fixing(const Date& fixingDate, bool forecastTodaysFixing = false) const override;
48 bool allowsNativeFixings() override { return false; }
49
50 //! Observer interface
51 void update() override { notifyObservers(); }
52
53 //! Inspectors
54 const std::vector<QuantLib::ext::shared_ptr<QuantLib::Index>>& indices() const { return indices_; }
55 const std::vector<Real>& weights() const { return weights_; }
56 const std::vector<QuantLib::ext::shared_ptr<FxIndex>>& fxConversion() const { return fxConversion_; }
57
58 /*! Collect dividends from equity underlying indices, apply weighting, fx conversion (if any) and return
59 the sum. Notice that the endDate is capped at today, as in EquityIndex::dividendsBetweenDates.
60 This only applies to underlying equity indices, for other index types zero dividends are returned */
61 Real dividendsBetweenDates(const Date& startDate, const Date& endDate = Date::maxDate()) const;
62 std::vector<std::pair<QuantLib::Date, std::string>> dividendFixingDates(const Date& startDate, const Date& endDate = Date::maxDate());
63
64private:
65 std::string name_;
66 std::vector<QuantLib::ext::shared_ptr<QuantLib::Index>> indices_;
67 std::vector<Real> weights_;
68 std::vector<QuantLib::ext::shared_ptr<FxIndex>> fxConversion_;
69 //
71};
72
73} // namespace QuantExt
const std::vector< QuantLib::ext::shared_ptr< QuantLib::Index > > & indices() const
Inspectors.
bool allowsNativeFixings() override
std::vector< QuantLib::ext::shared_ptr< QuantLib::Index > > indices_
std::vector< QuantLib::ext::shared_ptr< FxIndex > > fxConversion_
std::vector< std::pair< QuantLib::Date, std::string > > dividendFixingDates(const Date &startDate, const Date &endDate=Date::maxDate())
void update() override
Observer interface.
Calendar fixingCalendar() const override
const std::vector< QuantLib::ext::shared_ptr< FxIndex > > & fxConversion() const
const std::vector< Real > & weights() const
std::string name() const override
Index interface.
std::vector< Real > weights_
Real dividendsBetweenDates(const Date &startDate, const Date &endDate=Date::maxDate()) const
bool isValidFixingDate(const Date &fixingDate) const override
Real fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override
FX index class.