Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
irlgm1fstateprocess.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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 irlgm1fstateprocess.hpp
20 \brief ir LGM 1f model state process
21 \ingroup processes
22*/
23
24#ifndef quantext_irlgm1f_stateprocess_hpp
25#define quantext_irlgm1f_stateprocess_hpp
26
27#include <ql/stochasticprocess.hpp>
29
30namespace QuantExt {
31using namespace QuantLib;
32
33//! Ir Lgm 1f State Process
34/*! \ingroup processes
35 */
37public:
38 IrLgm1fStateProcess(const QuantLib::ext::shared_ptr<IrLgm1fParametrization>& parametrization);
39 //! \name StochasticProcess interface
40 //@{
41 Real x0() const override;
42 Real drift(Time t, Real x) const override;
43 Real diffusion(Time t, Real x) const override;
44 Real expectation(Time t0, Real x0, Time dt) const override;
45 Real stdDeviation(Time t0, Real x0, Time dt) const override;
46 Real variance(Time t0, Real x0, Time dt) const override;
47
48 // enables and resets the cache, once enabled the simulated times must stay the stame
49 void resetCache(const Size timeSteps) const;
50 //@}
51private:
52 const QuantLib::ext::shared_ptr<IrLgm1fParametrization> p_;
53 mutable bool cacheNotReady_d_ = true;
54 mutable bool cacheNotReady_v_ = true;
55 mutable Size timeStepsToCache_d_ = 0;
56 mutable Size timeStepsToCache_v_ = 0;
57 mutable Size timeStepCache_d_ = 0;
58 mutable Size timeStepCache_v_ = 0;
59 mutable std::vector<Real> cache_d_;
60 mutable std::vector<Real> cache_v_;
61};
62
63// inline
64
65inline Real IrLgm1fStateProcess::x0() const { return 0.0; }
66
67inline Real IrLgm1fStateProcess::drift(Time, Real) const { return 0.0; }
68
69inline Real IrLgm1fStateProcess::diffusion(Time t, Real) const {
70 if (cacheNotReady_d_) {
71 Real tmp = p_->alpha(t);
72 if (timeStepsToCache_d_ > 0) {
73 cache_d_.push_back(tmp);
74 if (cache_d_.size() == timeStepsToCache_d_)
75 cacheNotReady_d_ = false;
76 }
77 return tmp;
78 } else {
79 Real tmp = cache_d_[timeStepCache_d_++];
82 return tmp;
83 }
84}
85
86inline Real IrLgm1fStateProcess::expectation(Time, Real x0, Time) const { return x0; }
87
88inline Real IrLgm1fStateProcess::variance(Time t0, Real, Time dt) const {
89 if (cacheNotReady_v_) {
90 Real tmp = p_->zeta(t0 + dt) - p_->zeta(t0);
91 if (timeStepsToCache_v_ > 0) {
92 cache_v_.push_back(tmp);
93 if (cache_v_.size() == timeStepsToCache_v_)
94 cacheNotReady_v_ = false;
95 }
96 return tmp;
97 } else {
98 Real tmp = cache_v_[timeStepCache_v_++];
101 return tmp;
102 }
103}
104
105inline Real IrLgm1fStateProcess::stdDeviation(Time t0, Real x0, Time dt) const {
106 return std::sqrt(variance(t0, x0, dt));
107}
108
109inline void IrLgm1fStateProcess::resetCache(const Size timeSteps) const {
112 cache_d_.clear();
113 cache_v_.clear();
114 p_->update();
115}
116
117} // namespace QuantExt
118
119#endif
Real diffusion(Time t, Real x) const override
Real stdDeviation(Time t0, Real x0, Time dt) const override
Real drift(Time t, Real x) const override
const QuantLib::ext::shared_ptr< IrLgm1fParametrization > p_
Real expectation(Time t0, Real x0, Time dt) const override
void resetCache(const Size timeSteps) const
Real variance(Time t0, Real x0, Time dt) const override
Interest Rate Linear Gaussian Markov 1 factor parametrization.