Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
modelimpliedpricetermstructure.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 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 modelimpliedpricetermstructure.hpp
20 \brief price term structure implied by a COM model
21 \ingroup models
22*/
23
24#pragma once
25
27
29#include <ql/math/comparison.hpp>
30
31namespace QuantExt {
32using namespace QuantLib;
33
34//! COM Implied Price Term Structure
35/*! The termstructure has the reference date of the model's
36 termstructure at construction, but you can vary this
37 as well as the state.
38 The purely time based variant is mainly there for
39 perfomance reasons, note that it does not provide the
40 full term structure interface and does not send
41 notifications on reference time updates.
42
43 \ingroup models
44 */
45
47public:
48 ModelImpliedPriceTermStructure(const QuantLib::ext::shared_ptr<CommodityModel>& model, const DayCounter& dc = DayCounter(),
49 const bool purelyTimeBased = false);
50
51 Date maxDate() const override;
52 Time maxTime() const override;
53
54 const Date& referenceDate() const override;
55
56 //! Price term structure interface
57 const QuantLib::Currency& currency() const override { return model_->currency(); }
58 std::vector<QuantLib::Date> pillarDates() const override { return std::vector<QuantLib::Date>(); }
59
60 virtual void referenceDate(const Date& d);
61 virtual void referenceTime(const Time t);
62 void state(const Array& s);
63 void move(const Date& d, const Array& s);
64 void move(const Time t, const Array& s);
65
66 virtual void update() override;
67
68protected:
69 Real priceImpl(Time t) const override;
70
71 const QuantLib::ext::shared_ptr<CommodityModel> model_;
72 const bool purelyTimeBased_;
75 Array state_;
76};
77
78// inline
79
81 // we don't care - let the underlying classes throw
82 // exceptions if applicable
83 return Date::maxDate();
84}
85
87 // see maxDate
88 return QL_MAX_REAL;
89}
90
92 QL_REQUIRE(!purelyTimeBased_, "reference date not available for purely "
93 "time based term structure");
94 return referenceDate_;
95}
96
98 QL_REQUIRE(!purelyTimeBased_, "reference date not available for purely "
99 "time based term structure");
100 referenceDate_ = d;
101 update();
102}
103
104
106 QL_REQUIRE(purelyTimeBased_, "reference time can only be set for purely "
107 "time based term structure");
108 relativeTime_ = t;
109 notifyObservers();
110}
111
112inline void ModelImpliedPriceTermStructure::state(const Array& s) {
113 state_ = s;
114 notifyObservers();
115}
116
117inline void ModelImpliedPriceTermStructure::move(const Date& d, const Array& s) {
118 state_ = s;
119 referenceDate(d);
120}
121
122inline void ModelImpliedPriceTermStructure::move(const Time t, const Array& s) {
123 state_ = s;
124 referenceTime(t);
125 notifyObservers();
126}
127
129 if (!purelyTimeBased_) {
130 relativeTime_ = dayCounter().yearFraction(model_->termStructure()->referenceDate(), referenceDate_);
131 }
132 notifyObservers();
133}
134
136 QL_REQUIRE(t >= 0.0, "negative time (" << t << ") given");
137 return model_->forwardPrice(relativeTime_, relativeTime_ + t, state_);
138}
139
140} // namespace QuantExt
const QuantLib::ext::shared_ptr< CommodityModel > model_
const QuantLib::Currency & currency() const override
Price term structure interface.
std::vector< QuantLib::Date > pillarDates() const override
The pillar dates for the PriceTermStructure.
Commodity model base class.
Term structure of prices.