QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
interestrateindex.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2006, 2011 Ferdinando Ametrano
5 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
6 Copyright (C) 2003, 2004, 2005, 2006, 2007 StatPro Italia srl
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
23#include <ql/settings.hpp>
24#include <sstream>
25#include <utility>
26
27namespace QuantLib {
28
30 const Period& tenor,
31 Natural fixingDays,
32 Currency currency,
33 Calendar fixingCalendar,
34 DayCounter dayCounter)
35 : familyName_(std::move(familyName)), tenor_(tenor), fixingDays_(fixingDays),
36 currency_(std::move(currency)), dayCounter_(std::move(dayCounter)),
37 fixingCalendar_(std::move(fixingCalendar)) {
38 // tenor_.normalize() does too much; we want to leave days alone
39 if (tenor.units() == Months && tenor.length() % 12 == 0)
40 tenor_ = Period(tenor.length() / 12, Years);
41
42 std::ostringstream out;
43 out << familyName_;
44 if (tenor_ == 1*Days) {
45 if (fixingDays_==0)
46 out << "ON";
47 else if (fixingDays_==1)
48 out << "TN";
49 else if (fixingDays_==2)
50 out << "SN";
51 else
53 } else {
55 }
56 out << " " << dayCounter_.name();
57 name_ = out.str();
58
59 registerWith(Settings::instance().evaluationDate());
61 }
62
64 bool forecastTodaysFixing) const {
65
67 "Fixing date " << fixingDate << " is not valid");
68
70
71 if (fixingDate>today ||
72 (fixingDate==today && forecastTodaysFixing))
74
75 if (fixingDate<today ||
76 Settings::instance().enforcesTodaysHistoricFixings()) {
77 // must have been fixed
78 // do not catch exceptions
79 Rate result = pastFixing(fixingDate);
80 QL_REQUIRE(result != Null<Real>(),
81 "Missing " << name() << " fixing for " << fixingDate);
82 return result;
83 }
84
85 try {
86 // might have been fixed
87 Rate result = pastFixing(fixingDate);
88 if (result!=Null<Real>())
89 return result;
90 else
91 ; // fall through and forecast
92 } catch (Error&) {
93 ; // fall through and forecast
94 }
96 }
97
98}
calendar class
Definition: calendar.hpp:61
Currency specification
Definition: currency.hpp:36
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
std::string name() const
Returns the name of the day counter.
Definition: daycounter.hpp:117
Base error class.
Definition: errors.hpp:39
virtual Rate forecastFixing(const Date &fixingDate) const =0
It can be overridden to implement particular conventions.
Rate fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override
returns the fixing at the given date
virtual Rate pastFixing(const Date &fixingDate) const
InterestRateIndex(std::string familyName, const Period &tenor, Natural settlementDays, Currency currency, Calendar fixingCalendar, DayCounter dayCounter)
std::string name() const override
Returns the name of the index.
bool isValidFixingDate(const Date &fixingDate) const override
returns TRUE if the fixing date is a valid one
Date fixingDate(const Date &valueDate) const
template class providing a null value for a given type.
Definition: null.hpp:76
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
TimeUnit units() const
Definition: period.hpp:51
Integer length() const
Definition: period.hpp:50
DateProxy & evaluationDate()
the date at which pricing is to be performed.
Definition: settings.hpp:147
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
detail::short_period_holder short_period(const Period &p)
output periods in short format (e.g. "2w")
Definition: period.cpp:446
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Rate
interest rates
Definition: types.hpp:70
base class for interest rate indexes
Definition: any.hpp:35
STL namespace.
global repository for run-time library settings