QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
generalizedornsteinuhlenbeckprocess.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2010 SunTrust Bank
5 Copyright (C) 2010 Cavit Hafizoglu
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21#include <ql/experimental/shortrate/generalizedornsteinuhlenbeckprocess.hpp>
22#include <utility>
23
24namespace QuantLib {
25
27 ext::function<Real(Time)> speed, ext::function<Real(Time)> vol, Real x0, Real level)
28 : x0_(x0), level_(level), speed_(std::move(speed)), volatility_(std::move(vol)) {
29
30 QL_REQUIRE(x0 >= 0.0, "negative initial data given");
31 QL_REQUIRE(level >= 0.0, "negative level given");
32 }
33
35 return x0_;
36 }
37
39 return speed_(t) * (level_ - x);;
40 }
41
43 return volatility_(t);
44 }
45
47 Time t, Real x0, Time dt) const {
48 return level_ + (x0 - level_) * std::exp(-speed_(t)*dt);
49 }
50
52 Time t, Real x0, Time dt) const {
53 return std::sqrt(variance(t,x0,dt));
54 }
55
57 Time t, Real, Time dt) const {
58 Real speed = speed_(t);
59 Volatility vol = volatility_(t);
60
61 if (speed < std::sqrt(QL_EPSILON)) {
62 // algebraic limit for small speed
63 return vol*vol*dt;
64 } else {
65 return 0.5*vol*vol/speed*(1.0 - std::exp(-2.0*speed*dt));
66 }
67 }
68
69
71 return speed_(t);
72 }
73
75 return volatility_(t);
76 }
77
79 return level_;
80 }
81
82}
83
Real diffusion(Time t, Real x) const override
returns the diffusion part of the equation, i.e.
Real stdDeviation(Time t0, Real x0, Time dt) const override
Real drift(Time t, Real x) const override
returns the drift part of the equation, i.e.
Real expectation(Time t0, Real x0, Time dt) const override
GeneralizedOrnsteinUhlenbeckProcess(ext::function< Real(Time)> speed, ext::function< Real(Time)> vol, Real x0=0.0, Real level=0.0)
Real x0() const override
returns the initial value of the state variable
Real variance(Time t0, Real x0, Time dt) const override
#define QL_EPSILON
Definition: qldefines.hpp:178
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real Volatility
volatility
Definition: types.hpp:78
Definition: any.hpp:35
STL namespace.