QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
iborindex.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) 2000, 2001, 2002, 2003 RiskMap srl
5 Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 StatPro Italia srl
6 Copyright (C) 2009 Ferdinando Ametrano
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
24#include <utility>
25
26namespace QuantLib {
27
28 IborIndex::IborIndex(const std::string& familyName,
29 const Period& tenor,
30 Natural settlementDays,
31 const Currency& currency,
32 const Calendar& fixingCalendar,
33 BusinessDayConvention convention,
34 bool endOfMonth,
35 const DayCounter& dayCounter,
37 : InterestRateIndex(familyName, tenor, settlementDays, currency, fixingCalendar, dayCounter),
38 convention_(convention), termStructure_(std::move(h)), endOfMonth_(endOfMonth) {
40 }
41
42 Rate IborIndex::forecastFixing(const Date& fixingDate) const {
44 Date d2 = maturityDate(d1);
46 QL_REQUIRE(t>0.0,
47 "\n cannot calculate forward rate between " <<
48 d1 << " and " << d2 <<
49 ":\n non positive time (" << t <<
50 ") using " << dayCounter_.name() << " daycounter");
51 return forecastFixing(d1, d2, t);
52 }
53
54 Date IborIndex::maturityDate(const Date& valueDate) const {
56 tenor_,
59 }
60
61 ext::shared_ptr<IborIndex> IborIndex::clone(
62 const Handle<YieldTermStructure>& h) const {
63 return ext::make_shared<IborIndex>(
64 familyName(),
65 tenor(),
66 fixingDays(),
67 currency(),
70 endOfMonth(),
71 dayCounter(),
72 h);
73 }
74
75
76 OvernightIndex::OvernightIndex(const std::string& familyName,
77 Natural settlementDays,
78 const Currency& curr,
79 const Calendar& fixCal,
80 const DayCounter& dc,
82 : IborIndex(familyName, 1*Days, settlementDays, curr,
83 fixCal, Following, false, dc, h) {}
84
85 ext::shared_ptr<IborIndex> OvernightIndex::clone(
86 const Handle<YieldTermStructure>& h) const {
87 return ext::shared_ptr<IborIndex>(
89 fixingDays(),
90 currency(),
92 dayCounter(),
93 h));
94 }
95
96}
calendar class
Definition: calendar.hpp:61
Date advance(const Date &, Integer n, TimeUnit unit, BusinessDayConvention convention=Following, bool endOfMonth=false) const
Definition: calendar.cpp:130
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
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Definition: daycounter.hpp:128
Shared handle to an observable.
Definition: handle.hpp:41
base class for Inter-Bank-Offered-Rate indexes (e.g. Libor, etc.)
Definition: iborindex.hpp:35
Date maturityDate(const Date &valueDate) const override
Definition: iborindex.cpp:54
bool endOfMonth() const
Definition: iborindex.hpp:54
BusinessDayConvention convention_
Definition: iborindex.hpp:65
IborIndex(const std::string &familyName, const Period &tenor, Natural settlementDays, const Currency &currency, const Calendar &fixingCalendar, BusinessDayConvention convention, bool endOfMonth, const DayCounter &dayCounter, Handle< YieldTermStructure > h={})
Definition: iborindex.cpp:28
virtual ext::shared_ptr< IborIndex > clone(const Handle< YieldTermStructure > &forwarding) const
returns a copy of itself linked to a different forwarding curve
Definition: iborindex.cpp:61
Handle< YieldTermStructure > termStructure_
Definition: iborindex.hpp:66
BusinessDayConvention businessDayConvention() const
Definition: iborindex.hpp:103
Rate forecastFixing(const Date &fixingDate) const override
It can be overridden to implement particular conventions.
Definition: iborindex.cpp:42
base class for interest rate indexes
const DayCounter & dayCounter() const
Calendar fixingCalendar() const override
returns the calendar defining valid fixing dates
const Currency & currency() const
virtual Date valueDate(const Date &fixingDate) const
Date fixingDate(const Date &valueDate) const
std::string familyName() const
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
OvernightIndex(const std::string &familyName, Natural settlementDays, const Currency &currency, const Calendar &fixingCalendar, const DayCounter &dayCounter, const Handle< YieldTermStructure > &h={})
Definition: iborindex.cpp:76
ext::shared_ptr< IborIndex > clone(const Handle< YieldTermStructure > &h) const override
returns a copy of itself linked to a different forwarding curve
Definition: iborindex.cpp:85
const DefaultType & t
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
BusinessDayConvention
Business Day conventions.
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Rate
interest rates
Definition: types.hpp:70
base class for Inter-Bank-Offered-Rate indexes
Definition: any.hpp:35
STL namespace.
Interest-rate term structure.