Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
genericindex.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/genericindex.hpp
20 \brief generic index class for storing price histories
21 \ingroup indexes
22*/
23
24#pragma once
25
26#include <ql/index.hpp>
27#include <ql/time/calendars/nullcalendar.hpp>
28
29namespace QuantExt {
30
31//! Generic Index
32/*! \ingroup indexes */
33class GenericIndex : public QuantLib::Index {
34public:
35 explicit GenericIndex(const std::string& name, const QuantLib::Date& expiry = QuantLib::Date()) :
37 //! \name Index interface
38 //@{
39 std::string name() const override { return name_; }
40 const QuantLib::Date& expiry() const { return expiry_; }
41 QuantLib::Calendar fixingCalendar() const override { return QuantLib::NullCalendar(); }
42 bool isValidFixingDate(const QuantLib::Date& fixingDate) const override { return true; }
43 QuantLib::Real fixing(const QuantLib::Date& fixingDate, bool forecastTodaysFixing = false) const override {
44 if (expiry_ != QuantLib::Date() && fixingDate >= expiry_)
45 QL_FAIL("GenericIndex, fixingDate is after expiry");
46 QuantLib::Real tmp = timeSeries()[fixingDate];
47 QL_REQUIRE(tmp != QuantLib::Null<QuantLib::Real>(), "Missing " << name() << " fixing for " << fixingDate);
48 return tmp;
49 }
50
51private:
52 std::string name_;
53 QuantLib::Date expiry_;
54};
55
56} // namespace QuantExt
bool isValidFixingDate(const QuantLib::Date &fixingDate) const override
GenericIndex(const std::string &name, const QuantLib::Date &expiry=QuantLib::Date())
QuantLib::Real fixing(const QuantLib::Date &fixingDate, bool forecastTodaysFixing=false) const override
QuantLib::Date expiry_
std::string name() const override
QuantLib::Calendar fixingCalendar() const override
const QuantLib::Date & expiry() const