1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2004, 2005, 2006, 2007 StatPro Italia srl
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20#include <ql/math/comparison.hpp>
21#include <ql/termstructure.hpp>
22#include <utility>
23
24namespace QuantLib {
25
26 TermStructure::TermStructure(DayCounter dc)
27 : settlementDays_(Null<Natural>()), dayCounter_(std::move(dc)) {}
28
29 TermStructure::TermStructure(const Date& referenceDate, Calendar cal, DayCounter dc)
30 : calendar_(std::move(cal)), referenceDate_(referenceDate), settlementDays_(Null<Natural>()),
31 dayCounter_(std::move(dc)) {}
32
33 TermStructure::TermStructure(Natural settlementDays, Calendar cal, DayCounter dc)
34 : moving_(true), updated_(false), calendar_(std::move(cal)), settlementDays_(settlementDays),
35 dayCounter_(std::move(dc)) {
36 registerWith(h: Settings::instance().evaluationDate());
37 }
38
39 const Date& TermStructure::referenceDate() const {
40 if (!updated_) {
41 Date today = Settings::instance().evaluationDate();
42 referenceDate_ = calendar().advance(today, n: settlementDays(), unit: Days);
43 updated_ = true;
44 }
45 return referenceDate_;
46 }
47
48 void TermStructure::update() {
49 if (moving_)
50 updated_ = false;
51 notifyObservers();
52 }
53
54 void TermStructure::checkRange(const Date& d,
55 bool extrapolate) const {
56 QL_REQUIRE(d >= referenceDate(),
57 "date (" << d << ") before reference date (" <<
58 referenceDate() << ")");
59 QL_REQUIRE(extrapolate || allowsExtrapolation() || d <= maxDate(),
60 "date (" << d << ") is past max curve date ("
61 << maxDate() << ")");
62 }
63
64 void TermStructure::checkRange(Time t,
65 bool extrapolate) const {
66 QL_REQUIRE(t >= 0.0,
67 "negative time (" << t << ") given");
68 QL_REQUIRE(extrapolate || allowsExtrapolation()
69 || t <= maxTime() || close_enough(t, maxTime()),
70 "time (" << t << ") is past max curve time ("
71 << maxTime() << ")");
72 }
73
74}
75

source code of quantlib/ql/termstructure.cpp

Morty Proxy This is a proxified and sanitized view of the page, visit original site.