QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
levyflightdistribution.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2015 Andres Hernandez
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
24#ifndef quantlib_levy_flight_distribution_hpp
25#define quantlib_levy_flight_distribution_hpp
26
27#include <ql/types.hpp>
28#include <ql/errors.hpp>
29#include <random>
30
31namespace QuantLib {
32
34
50 {
51 public:
53 {
54 public:
58 param_type(Real xm = 1.0, Real alpha = 1.0)
59 : xm_(xm), alpha_(alpha) { QL_REQUIRE(alpha_ > 0.0, "alpha must be larger than 0"); }
60
62 Real xm() const { return xm_; }
63
65 Real alpha() const { return alpha_; }
66
67 private:
70 };
71
73
74
77 explicit LevyFlightDistribution(Real xm = 1.0, Real alpha = 1.0)
78 : xm_(xm), alpha_(alpha) { QL_REQUIRE(alpha_ > 0.0, "alpha must be larger than 0"); }
79
81 explicit LevyFlightDistribution(const param_type& parm)
82 : xm_(parm.xm()), alpha_(parm.alpha()) {}
83
84 // compiler-generated copy ctor and assignment operator are fine
86
88
89
90 Real xm() const { return xm_; }
91
93 Real alpha() const { return alpha_; }
94
97 { return xm_; }
100 { return QL_MAX_REAL; }
101
103 param_type param() const { return {xm_, alpha_}; }
105
107 void param(const param_type& parm) {
108 xm_ = parm.xm();
109 alpha_ = parm.alpha();
110 }
111
115 void reset() { }
116
119 using std::pow;
120 if(x < xm_) return 0.0;
121 return alpha_*pow(xm_/x, alpha_)/x;
122 }
123
127 template<class Engine>
128 Real operator()(Engine& eng) const {
129 using std::pow;
130 return xm_*pow(std::uniform_real_distribution<Real>(0.0, 1.0)(eng), -1.0/alpha_);
131 }
132
136 template<class Engine>
137 Real operator()(Engine& eng, const param_type& parm) const {
138 return LevyFlightDistribution (parm)(eng);
139 }
140
141 private:
144 };
145
146}
147
148#endif
Real xm() const
Returns the xm parameter of the distribution.
Real alpha() const
Returns the alpha parameter of the distribution.
param_type param() const
Returns the parameters of the distribution.
Real operator()(Real x) const
Returns the value of the pdf for x.
void param(const param_type &parm)
Sets the parameters of the distribution.
Real operator()(Engine &eng, const param_type &parm) const
LevyFlightDistribution(const param_type &parm)
Constructs a LevyFlightDistribution from its parameters.
Real xm() const
Returns the xm parameter of the distribution.
LevyFlightDistribution(Real xm=1.0, Real alpha=1.0)
Real max BOOST_PREVENT_MACRO_SUBSTITUTION() const
Returns the largest value that the distribution can produce.
Real alpha() const
Returns the alpha parameter of the distribution.
Real min BOOST_PREVENT_MACRO_SUBSTITUTION() const
Returns the smallest value that the distribution can produce.
#define QL_MAX_REAL
Definition: qldefines.hpp:176
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35