/usr/include/ql/index.hpp is in libquantlib0-dev 1.4-2+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
Copyright (C) 2003, 2004, 2005, 2006 StatPro Italia srl
Copyright (C) 2007, 2008 Ferdinando Ametrano
Copyright (C) 2007 Chiara Fornarola
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<quantlib-dev@lists.sf.net>. The license is also available online at
<http://quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
/*! \file index.hpp
\brief virtual base class for indexes
*/
#ifndef quantlib_index_hpp
#define quantlib_index_hpp
#include <ql/time/calendar.hpp>
#include <ql/math/comparison.hpp>
#include <ql/indexes/indexmanager.hpp>
namespace QuantLib {
//! purely virtual base class for indexes
/*! \warning this class performs no check that the
provided/requested fixings are for dates in the past,
i.e. for dates less than or equal to the evaluation
date. It is up to the client code to take care of
possible inconsistencies due to "seeing in the
future"
*/
class Index : public Observable {
public:
virtual ~Index() {}
//! Returns the name of the index.
/*! \warning This method is used for output and comparison
between indexes. It is <b>not</b> meant to be
used for writing switch-on-type code.
*/
virtual std::string name() const = 0;
//! returns the calendar defining valid fixing dates
virtual Calendar fixingCalendar() const = 0;
//! returns TRUE if the fixing date is a valid one
virtual bool isValidFixingDate(const Date& fixingDate) const = 0;
//! returns the fixing at the given date
/*! the date passed as arguments must be the actual calendar
date of the fixing; no settlement days must be used.
*/
virtual Real fixing(const Date& fixingDate,
bool forecastTodaysFixing = false) const = 0;
//! returns the fixing TimeSeries
const TimeSeries<Real>& timeSeries() const {
return IndexManager::instance().getHistory(name());
}
//! stores the historical fixing at the given date
/*! the date passed as arguments must be the actual calendar
date of the fixing; no settlement days must be used.
*/
virtual void addFixing(const Date& fixingDate,
Real fixing,
bool forceOverwrite = false);
//! stores historical fixings from a TimeSeries
/*! the dates in the TimeSeries must be the actual calendar
dates of the fixings; no settlement days must be used.
*/
void addFixings(const TimeSeries<Real>& t,
bool forceOverwrite = false);
//! stores historical fixings at the given dates
/*! the dates passed as arguments must be the actual calendar
dates of the fixings; no settlement days must be used.
*/
template <class DateIterator, class ValueIterator>
void addFixings(DateIterator dBegin, DateIterator dEnd,
ValueIterator vBegin,
bool forceOverwrite = false) {
std::string tag = name();
TimeSeries<Real> h = IndexManager::instance().getHistory(tag);
bool missingFixing, validFixing;
bool noInvalidFixing = true, noDuplicatedFixing = true;
Date invalidDate, duplicatedDate;
Real nullValue = Null<Real>();
Real invalidValue = Null<Real>();
Real duplicatedValue = Null<Real>();
while (dBegin != dEnd) {
validFixing = isValidFixingDate(*dBegin);
Real currentValue = h[*dBegin];
missingFixing = forceOverwrite || currentValue == nullValue;
if (validFixing) {
if (missingFixing)
h[*(dBegin++)] = *(vBegin++);
else if (close(currentValue,*(vBegin))) {
++dBegin;
++vBegin;
} else {
noDuplicatedFixing = false;
duplicatedDate = *(dBegin++);
duplicatedValue = *(vBegin++);
}
} else {
noInvalidFixing = false;
invalidDate = *(dBegin++);
invalidValue = *(vBegin++);
}
}
IndexManager::instance().setHistory(tag, h);
QL_REQUIRE(noInvalidFixing,
"At least one invalid fixing provided: " <<
invalidDate.weekday() << " " << invalidDate <<
", " << invalidValue);
QL_REQUIRE(noDuplicatedFixing,
"At least one duplicated fixing provided: " <<
duplicatedDate << ", " << duplicatedValue <<
" while " << h[duplicatedDate] <<
" value is already present");
}
//! clears all stored historical fixings
void clearFixings();
};
}
#endif
|