Distributions¶
quantflow.utils.distributions.Distribution1D
pydantic-model
¶
Bases: Marginal1D
Base class for 1D distributions to be used as jump distributions in CompoundPoisson
sample
abstractmethod
¶
from_variance_and_asymmetry
classmethod
¶
asymmetry
¶
set_variance
¶
set_asymmetry
¶
call_option
¶
call_option(n=None, *, pricing_method=CARR_MADAN, cos_moneyness_std_precision=12, max_moneyness=1.5, max_frequency=None, alpha=None, simpson_rule=False, use_fft=False)
Price call options via one of the available Fourier-based methods, as a function of log-strike
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
pricing_method
|
Method to use for option pricing via Fourier transform of the call option price. Defaults to Lewis.
TYPE:
|
cos_moneyness_std_precision
|
Truncation parameter for COS: the integration interval is set to [-cos_moneyness_std_precisionstd, cos_moneyness_std_precisionstd].
TYPE:
|
max_moneyness
|
Maximum moneyness to calculate prices. The log-strike grid is set to [-max_moneynessstd, max_moneynessstd]. Used by Lewis and Carr & Madan methods only.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
alpha
|
Damping parameter for integrability of the Carr-Madan integrand, it is ignored if not applicable.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform rather than FRFT. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
call_option_carr_madan
¶
call_option_carr_madan(n=None, *, max_moneyness=1.5, max_frequency=None, alpha=None, simpson_rule=False, use_fft=False)
Call option price via Carr & Madan method
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_moneyness
|
Maximum moneyness to calculate prices. The log-strike grid is set to [-max_moneynessstd, max_moneynessstd].
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
alpha
|
Damping parameter for integrability of the Carr-Madan integrand. Defaults to call_option_carr_madan_alpha.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
call_option_carr_madan_alpha
¶
Option alpha to use for Carr & Madan transform to ensure integrability of the call option transform.
Defaults to 1.5, the value suggested in the original Carr & Madan paper.
Source code in quantflow/utils/marginal.py
call_option_cos
¶
Call option price via the COS method (Fang & Oosterlee 2008).
The call price at log-strike \(k\) is approximated by the cosine series
where the prime denotes a half weight on the \(j=0\) term, \([a,b]\) is the truncation interval, and \(V_j\) are the cosine payoff coefficients for the normalised call payoff \((e^y - 1)^+\) integrated over \([0, b]\). The \(e^k\) factor converts from strike-normalised to forward-space pricing.
Returns an OptionPricingCosResult with the precomputed coefficient vector. Use call_price to evaluate at arbitrary log-strikes in \(O(N)\) per strike.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of cosine series terms. Defaults to 128.
TYPE:
|
moneyness_std_precision
|
Truncation parameter: the integration interval is set to [-moneyness_std_precisionstd, moneyness_std_precisionstd].
TYPE:
|
Source code in quantflow/utils/marginal.py
call_option_lewis
¶
call_option_lewis(n=None, *, max_moneyness=1.5, max_frequency=None, simpson_rule=False, use_fft=False)
Call option price via the Lewis (2001) formula
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_moneyness
|
Maximum moneyness to calculate prices. The log-strike grid is set to [-max_moneynessstd, max_moneynessstd].
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
call_option_transform
¶
Call option transform
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points (possibly complex-shifted).
TYPE:
|
Source code in quantflow/utils/marginal.py
cdf
¶
Compute the cumulative distribution function
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Location in the stochastic process domain space. If a numpy array, the output should have the same shape as the input.
TYPE:
|
Source code in quantflow/utils/marginal.py
cdf_from_characteristic
¶
cdf_from_characteristic(n=None, *, max_frequency=None, simpson_rule=False, use_fft=False, frequency_n=None)
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
frequency_n
|
Number of points for the frequency grid. Overrides n if provided.
TYPE:
|
Source code in quantflow/utils/marginal.py
cdf_jacobian
¶
Jacobian of the cdf with respect to the parameters of the process. It is useful for optimization purposes if necessary.
Optional to implement, otherwise raises NotImplementedError if called.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Location in the state space of the process.
TYPE:
|
Source code in quantflow/utils/marginal.py
characteristic
abstractmethod
¶
Compute the characteristic function on frequency domain points \(u\)
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points.
TYPE:
|
characteristic_corrected
¶
Characteristic function corrected for the convexity of the log-price distribution
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points.
TYPE:
|
Source code in quantflow/utils/marginal.py
characteristic_df
¶
Compute the characteristic function with n discretization points and a max frequency
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
domain_range
¶
The space domain range for the random variable
This should be overloaded if required
frequency_range
¶
The frequency domain range for the characteristic function
This should be overloaded if required
| PARAMETER | DESCRIPTION |
|---|---|
max_frequency
|
Upper bound of the frequency grid. Defaults to 20 if None.
TYPE:
|
Source code in quantflow/utils/marginal.py
get_transform
¶
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points. Defaults to 128.
TYPE:
|
support
|
Function returning the space domain grid given the number of points.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
lewis_transform
¶
Lewis (2001) call option transform - no damping parameter required
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points.
TYPE:
|
mean
¶
Expected value
By default it uses the mean_from_characteristic method. This should be overloaded if a more efficient/analytical way of computing the mean is available.
Source code in quantflow/utils/marginal.py
mean_from_characteristic
¶
Calculate mean as first derivative of characteristic function at 0
| PARAMETER | DESCRIPTION |
|---|---|
d
|
Step size for finite-difference approximation of the derivative.
TYPE:
|
Source code in quantflow/utils/marginal.py
option_support
¶
Compute the x axis.
| PARAMETER | DESCRIPTION |
|---|---|
points
|
Number of support points.
TYPE:
|
max_log_strike
|
Maximum absolute log-strike.
TYPE:
|
Source code in quantflow/utils/marginal.py
option_time_value
¶
option_time_value(n=128, *, max_frequency=None, max_log_strike=1, alpha=1.1, simpson_rule=False, use_fft=False)
Option time value
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
max_log_strike
|
Maximum absolute log-strike for the output grid.
TYPE:
|
alpha
|
Contour shift parameter controlling the integration strip.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
option_time_value_transform
¶
Option time value transform
This transform does not require any additional correction since the integrand is already bounded for positive and negative moneyness
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points.
TYPE:
|
alpha
|
Contour shift parameter controlling the integration strip.
TYPE:
|
Source code in quantflow/utils/marginal.py
pdf
¶
Computes the probability density (or mass) function of the process.
It has a base implementation that computes the pdf from the cdf method, but a subclass should overload this method if a more optimized way of computing it is available.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Location in the stochastic process domain space. If a numpy array, the output should have the same shape as the input.
TYPE:
|
Source code in quantflow/utils/marginal.py
pdf_from_characteristic
¶
pdf_from_characteristic(n=None, *, max_frequency=None, simpson_rule=False, use_fft=False, frequency_n=None)
Compute the probability density function from the characteristic function.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points to use in the transform. If None, use 128.
TYPE:
|
max_frequency
|
The maximum frequency to use in the transform. If not provided, the value from the frequency_range method is used. Only needed for special cases/testing.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
frequency_n
|
Number of points for the frequency grid. Overrides n if provided.
TYPE:
|
Source code in quantflow/utils/marginal.py
pdf_jacobian
¶
Jacobian of the pdf with respect to the parameters of the process. It has a base implementation that computes it from the cdf_jacobian method, but a subclass should overload this method if a more optimized way of computing it is available.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Location in the state space of the process.
TYPE:
|
Source code in quantflow/utils/marginal.py
std
¶
std_validated
¶
Float standard deviation, raising if it is not finite or non-positive.
Used by the Fourier-based pricing methods to set the log-strike grid range; degenerate parameter samples (e.g. during calibration) can produce a non-finite std and would otherwise crash deep in the transform with a confusing error.
Source code in quantflow/utils/marginal.py
std_from_characteristic
¶
support
abstractmethod
¶
Compute the x axis.
| PARAMETER | DESCRIPTION |
|---|---|
points
|
Number of support points.
TYPE:
|
std_mult
|
Standard deviation multiplier for the support range.
TYPE:
|
Source code in quantflow/utils/marginal.py
variance
¶
Variance
By default it uses the variance_from_characteristic method. This should be overloaded if a more efficient/analytical way of computing the variance is available.
Source code in quantflow/utils/marginal.py
variance_from_characteristic
¶
Calculate variance as second derivative of characteristic function at 0
| PARAMETER | DESCRIPTION |
|---|---|
d
|
Step size for finite-difference approximation of the derivative.
TYPE:
|
Source code in quantflow/utils/marginal.py
quantflow.utils.distributions.Exponential
pydantic-model
¶
Bases: Distribution1D
The Exponential distribution is a continuous probability distribution that describes the time between events in a Poisson process.
It is a special case of the gamma distribution and is given by
Fields:
-
decay(float)
characteristic
¶
The characteristic function of the exponential distribution is given by
mean
¶
variance
¶
sample
¶
support
¶
pdf
¶
cdf
¶
The analytical CDF of the exponential distribution
call_option
¶
call_option(n=None, *, pricing_method=CARR_MADAN, cos_moneyness_std_precision=12, max_moneyness=1.5, max_frequency=None, alpha=None, simpson_rule=False, use_fft=False)
Price call options via one of the available Fourier-based methods, as a function of log-strike
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
pricing_method
|
Method to use for option pricing via Fourier transform of the call option price. Defaults to Lewis.
TYPE:
|
cos_moneyness_std_precision
|
Truncation parameter for COS: the integration interval is set to [-cos_moneyness_std_precisionstd, cos_moneyness_std_precisionstd].
TYPE:
|
max_moneyness
|
Maximum moneyness to calculate prices. The log-strike grid is set to [-max_moneynessstd, max_moneynessstd]. Used by Lewis and Carr & Madan methods only.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
alpha
|
Damping parameter for integrability of the Carr-Madan integrand, it is ignored if not applicable.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform rather than FRFT. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
call_option_carr_madan
¶
call_option_carr_madan(n=None, *, max_moneyness=1.5, max_frequency=None, alpha=None, simpson_rule=False, use_fft=False)
Call option price via Carr & Madan method
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_moneyness
|
Maximum moneyness to calculate prices. The log-strike grid is set to [-max_moneynessstd, max_moneynessstd].
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
alpha
|
Damping parameter for integrability of the Carr-Madan integrand. Defaults to call_option_carr_madan_alpha.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
call_option_carr_madan_alpha
¶
Option alpha to use for Carr & Madan transform to ensure integrability of the call option transform.
Defaults to 1.5, the value suggested in the original Carr & Madan paper.
Source code in quantflow/utils/marginal.py
call_option_cos
¶
Call option price via the COS method (Fang & Oosterlee 2008).
The call price at log-strike \(k\) is approximated by the cosine series
where the prime denotes a half weight on the \(j=0\) term, \([a,b]\) is the truncation interval, and \(V_j\) are the cosine payoff coefficients for the normalised call payoff \((e^y - 1)^+\) integrated over \([0, b]\). The \(e^k\) factor converts from strike-normalised to forward-space pricing.
Returns an OptionPricingCosResult with the precomputed coefficient vector. Use call_price to evaluate at arbitrary log-strikes in \(O(N)\) per strike.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of cosine series terms. Defaults to 128.
TYPE:
|
moneyness_std_precision
|
Truncation parameter: the integration interval is set to [-moneyness_std_precisionstd, moneyness_std_precisionstd].
TYPE:
|
Source code in quantflow/utils/marginal.py
call_option_lewis
¶
call_option_lewis(n=None, *, max_moneyness=1.5, max_frequency=None, simpson_rule=False, use_fft=False)
Call option price via the Lewis (2001) formula
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_moneyness
|
Maximum moneyness to calculate prices. The log-strike grid is set to [-max_moneynessstd, max_moneynessstd].
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
call_option_transform
¶
Call option transform
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points (possibly complex-shifted).
TYPE:
|
Source code in quantflow/utils/marginal.py
cdf_from_characteristic
¶
cdf_from_characteristic(n=None, *, max_frequency=None, simpson_rule=False, use_fft=False, frequency_n=None)
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
frequency_n
|
Number of points for the frequency grid. Overrides n if provided.
TYPE:
|
Source code in quantflow/utils/marginal.py
cdf_jacobian
¶
Jacobian of the cdf with respect to the parameters of the process. It is useful for optimization purposes if necessary.
Optional to implement, otherwise raises NotImplementedError if called.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Location in the state space of the process.
TYPE:
|
Source code in quantflow/utils/marginal.py
characteristic_corrected
¶
Characteristic function corrected for the convexity of the log-price distribution
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points.
TYPE:
|
Source code in quantflow/utils/marginal.py
characteristic_df
¶
Compute the characteristic function with n discretization points and a max frequency
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
domain_range
¶
The space domain range for the random variable
This should be overloaded if required
frequency_range
¶
The frequency domain range for the characteristic function
This should be overloaded if required
| PARAMETER | DESCRIPTION |
|---|---|
max_frequency
|
Upper bound of the frequency grid. Defaults to 20 if None.
TYPE:
|
Source code in quantflow/utils/marginal.py
get_transform
¶
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points. Defaults to 128.
TYPE:
|
support
|
Function returning the space domain grid given the number of points.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
lewis_transform
¶
Lewis (2001) call option transform - no damping parameter required
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points.
TYPE:
|
mean_from_characteristic
¶
Calculate mean as first derivative of characteristic function at 0
| PARAMETER | DESCRIPTION |
|---|---|
d
|
Step size for finite-difference approximation of the derivative.
TYPE:
|
Source code in quantflow/utils/marginal.py
option_support
¶
Compute the x axis.
| PARAMETER | DESCRIPTION |
|---|---|
points
|
Number of support points.
TYPE:
|
max_log_strike
|
Maximum absolute log-strike.
TYPE:
|
Source code in quantflow/utils/marginal.py
option_time_value
¶
option_time_value(n=128, *, max_frequency=None, max_log_strike=1, alpha=1.1, simpson_rule=False, use_fft=False)
Option time value
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
max_log_strike
|
Maximum absolute log-strike for the output grid.
TYPE:
|
alpha
|
Contour shift parameter controlling the integration strip.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
option_time_value_transform
¶
Option time value transform
This transform does not require any additional correction since the integrand is already bounded for positive and negative moneyness
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points.
TYPE:
|
alpha
|
Contour shift parameter controlling the integration strip.
TYPE:
|
Source code in quantflow/utils/marginal.py
pdf_from_characteristic
¶
pdf_from_characteristic(n=None, *, max_frequency=None, simpson_rule=False, use_fft=False, frequency_n=None)
Compute the probability density function from the characteristic function.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points to use in the transform. If None, use 128.
TYPE:
|
max_frequency
|
The maximum frequency to use in the transform. If not provided, the value from the frequency_range method is used. Only needed for special cases/testing.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
frequency_n
|
Number of points for the frequency grid. Overrides n if provided.
TYPE:
|
Source code in quantflow/utils/marginal.py
pdf_jacobian
¶
Jacobian of the pdf with respect to the parameters of the process. It has a base implementation that computes it from the cdf_jacobian method, but a subclass should overload this method if a more optimized way of computing it is available.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Location in the state space of the process.
TYPE:
|
Source code in quantflow/utils/marginal.py
std
¶
std_validated
¶
Float standard deviation, raising if it is not finite or non-positive.
Used by the Fourier-based pricing methods to set the log-strike grid range; degenerate parameter samples (e.g. during calibration) can produce a non-finite std and would otherwise crash deep in the transform with a confusing error.
Source code in quantflow/utils/marginal.py
std_from_characteristic
¶
variance_from_characteristic
¶
Calculate variance as second derivative of characteristic function at 0
| PARAMETER | DESCRIPTION |
|---|---|
d
|
Step size for finite-difference approximation of the derivative.
TYPE:
|
Source code in quantflow/utils/marginal.py
from_variance_and_asymmetry
classmethod
¶
asymmetry
¶
set_variance
¶
quantflow.utils.distributions.DoubleExponential
pydantic-model
¶
Bases: Exponential
The generalized double exponential distribution
This is also know as the Asymmetric Laplace distribution which is a continuous probability distribution with PDF
where \(m\) is the loc parameter,
\(\lambda\) is the decay parameter,
and \(\kappa\) is the asymmetric parameter.
The Asymmetric Laplace distribution is similar to the Gaussian/normal distribution, but is sharper at the peak, it has fatter tails and allow for skewness. It represents the difference between two independent, exponential random variables.
Fields:
kappa
pydantic-field
¶
asymmetric parameter \(\kappa\) - when \(\kappa=1\), the distribution is symmetric
from_variance_and_asymmetry
classmethod
¶
from_moments
classmethod
¶
Create a double exponential distribution from the mean, variance and asymmetry
| PARAMETER | DESCRIPTION |
|---|---|
mean
|
The mean of the distribution
TYPE:
|
variance
|
The variance of the distribution
TYPE:
|
kappa
|
The asymmetry parameter of the distribution, 1 for symmetric
TYPE:
|
Source code in quantflow/utils/distributions.py
characteristic
¶
Characteristic function of the double exponential distribution
Source code in quantflow/utils/distributions.py
mean
¶
variance
¶
pdf
¶
sample
¶
support
¶
asymmetry
¶
set_variance
¶
set_asymmetry
¶
call_option
¶
call_option(n=None, *, pricing_method=CARR_MADAN, cos_moneyness_std_precision=12, max_moneyness=1.5, max_frequency=None, alpha=None, simpson_rule=False, use_fft=False)
Price call options via one of the available Fourier-based methods, as a function of log-strike
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
pricing_method
|
Method to use for option pricing via Fourier transform of the call option price. Defaults to Lewis.
TYPE:
|
cos_moneyness_std_precision
|
Truncation parameter for COS: the integration interval is set to [-cos_moneyness_std_precisionstd, cos_moneyness_std_precisionstd].
TYPE:
|
max_moneyness
|
Maximum moneyness to calculate prices. The log-strike grid is set to [-max_moneynessstd, max_moneynessstd]. Used by Lewis and Carr & Madan methods only.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
alpha
|
Damping parameter for integrability of the Carr-Madan integrand, it is ignored if not applicable.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform rather than FRFT. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
call_option_carr_madan
¶
call_option_carr_madan(n=None, *, max_moneyness=1.5, max_frequency=None, alpha=None, simpson_rule=False, use_fft=False)
Call option price via Carr & Madan method
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_moneyness
|
Maximum moneyness to calculate prices. The log-strike grid is set to [-max_moneynessstd, max_moneynessstd].
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
alpha
|
Damping parameter for integrability of the Carr-Madan integrand. Defaults to call_option_carr_madan_alpha.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
call_option_carr_madan_alpha
¶
Option alpha to use for Carr & Madan transform to ensure integrability of the call option transform.
Defaults to 1.5, the value suggested in the original Carr & Madan paper.
Source code in quantflow/utils/marginal.py
call_option_cos
¶
Call option price via the COS method (Fang & Oosterlee 2008).
The call price at log-strike \(k\) is approximated by the cosine series
where the prime denotes a half weight on the \(j=0\) term, \([a,b]\) is the truncation interval, and \(V_j\) are the cosine payoff coefficients for the normalised call payoff \((e^y - 1)^+\) integrated over \([0, b]\). The \(e^k\) factor converts from strike-normalised to forward-space pricing.
Returns an OptionPricingCosResult with the precomputed coefficient vector. Use call_price to evaluate at arbitrary log-strikes in \(O(N)\) per strike.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of cosine series terms. Defaults to 128.
TYPE:
|
moneyness_std_precision
|
Truncation parameter: the integration interval is set to [-moneyness_std_precisionstd, moneyness_std_precisionstd].
TYPE:
|
Source code in quantflow/utils/marginal.py
call_option_lewis
¶
call_option_lewis(n=None, *, max_moneyness=1.5, max_frequency=None, simpson_rule=False, use_fft=False)
Call option price via the Lewis (2001) formula
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_moneyness
|
Maximum moneyness to calculate prices. The log-strike grid is set to [-max_moneynessstd, max_moneynessstd].
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
call_option_transform
¶
Call option transform
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points (possibly complex-shifted).
TYPE:
|
Source code in quantflow/utils/marginal.py
cdf
¶
The analytical CDF of the exponential distribution
cdf_from_characteristic
¶
cdf_from_characteristic(n=None, *, max_frequency=None, simpson_rule=False, use_fft=False, frequency_n=None)
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
frequency_n
|
Number of points for the frequency grid. Overrides n if provided.
TYPE:
|
Source code in quantflow/utils/marginal.py
cdf_jacobian
¶
Jacobian of the cdf with respect to the parameters of the process. It is useful for optimization purposes if necessary.
Optional to implement, otherwise raises NotImplementedError if called.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Location in the state space of the process.
TYPE:
|
Source code in quantflow/utils/marginal.py
characteristic_corrected
¶
Characteristic function corrected for the convexity of the log-price distribution
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points.
TYPE:
|
Source code in quantflow/utils/marginal.py
characteristic_df
¶
Compute the characteristic function with n discretization points and a max frequency
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
domain_range
¶
The space domain range for the random variable
This should be overloaded if required
frequency_range
¶
The frequency domain range for the characteristic function
This should be overloaded if required
| PARAMETER | DESCRIPTION |
|---|---|
max_frequency
|
Upper bound of the frequency grid. Defaults to 20 if None.
TYPE:
|
Source code in quantflow/utils/marginal.py
get_transform
¶
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points. Defaults to 128.
TYPE:
|
support
|
Function returning the space domain grid given the number of points.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
lewis_transform
¶
Lewis (2001) call option transform - no damping parameter required
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points.
TYPE:
|
mean_from_characteristic
¶
Calculate mean as first derivative of characteristic function at 0
| PARAMETER | DESCRIPTION |
|---|---|
d
|
Step size for finite-difference approximation of the derivative.
TYPE:
|
Source code in quantflow/utils/marginal.py
option_support
¶
Compute the x axis.
| PARAMETER | DESCRIPTION |
|---|---|
points
|
Number of support points.
TYPE:
|
max_log_strike
|
Maximum absolute log-strike.
TYPE:
|
Source code in quantflow/utils/marginal.py
option_time_value
¶
option_time_value(n=128, *, max_frequency=None, max_log_strike=1, alpha=1.1, simpson_rule=False, use_fft=False)
Option time value
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
max_log_strike
|
Maximum absolute log-strike for the output grid.
TYPE:
|
alpha
|
Contour shift parameter controlling the integration strip.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
option_time_value_transform
¶
Option time value transform
This transform does not require any additional correction since the integrand is already bounded for positive and negative moneyness
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points.
TYPE:
|
alpha
|
Contour shift parameter controlling the integration strip.
TYPE:
|
Source code in quantflow/utils/marginal.py
pdf_from_characteristic
¶
pdf_from_characteristic(n=None, *, max_frequency=None, simpson_rule=False, use_fft=False, frequency_n=None)
Compute the probability density function from the characteristic function.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points to use in the transform. If None, use 128.
TYPE:
|
max_frequency
|
The maximum frequency to use in the transform. If not provided, the value from the frequency_range method is used. Only needed for special cases/testing.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
frequency_n
|
Number of points for the frequency grid. Overrides n if provided.
TYPE:
|
Source code in quantflow/utils/marginal.py
pdf_jacobian
¶
Jacobian of the pdf with respect to the parameters of the process. It has a base implementation that computes it from the cdf_jacobian method, but a subclass should overload this method if a more optimized way of computing it is available.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Location in the state space of the process.
TYPE:
|
Source code in quantflow/utils/marginal.py
std
¶
std_validated
¶
Float standard deviation, raising if it is not finite or non-positive.
Used by the Fourier-based pricing methods to set the log-strike grid range; degenerate parameter samples (e.g. during calibration) can produce a non-finite std and would otherwise crash deep in the transform with a confusing error.
Source code in quantflow/utils/marginal.py
std_from_characteristic
¶
variance_from_characteristic
¶
Calculate variance as second derivative of characteristic function at 0
| PARAMETER | DESCRIPTION |
|---|---|
d
|
Step size for finite-difference approximation of the derivative.
TYPE:
|
Source code in quantflow/utils/marginal.py
quantflow.utils.distributions.Normal
pydantic-model
¶
Bases: Distribution1D
The normal distribution is a continuous probability distribution with PDF given by
Fields:
from_variance_and_asymmetry
classmethod
¶
The normal distribution is symmetric, so the asymmetry is ignored
characteristic
¶
mean
¶
variance
¶
sample
¶
support
¶
set_variance
¶
call_option
¶
call_option(n=None, *, pricing_method=CARR_MADAN, cos_moneyness_std_precision=12, max_moneyness=1.5, max_frequency=None, alpha=None, simpson_rule=False, use_fft=False)
Price call options via one of the available Fourier-based methods, as a function of log-strike
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
pricing_method
|
Method to use for option pricing via Fourier transform of the call option price. Defaults to Lewis.
TYPE:
|
cos_moneyness_std_precision
|
Truncation parameter for COS: the integration interval is set to [-cos_moneyness_std_precisionstd, cos_moneyness_std_precisionstd].
TYPE:
|
max_moneyness
|
Maximum moneyness to calculate prices. The log-strike grid is set to [-max_moneynessstd, max_moneynessstd]. Used by Lewis and Carr & Madan methods only.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
alpha
|
Damping parameter for integrability of the Carr-Madan integrand, it is ignored if not applicable.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform rather than FRFT. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
call_option_carr_madan
¶
call_option_carr_madan(n=None, *, max_moneyness=1.5, max_frequency=None, alpha=None, simpson_rule=False, use_fft=False)
Call option price via Carr & Madan method
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_moneyness
|
Maximum moneyness to calculate prices. The log-strike grid is set to [-max_moneynessstd, max_moneynessstd].
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
alpha
|
Damping parameter for integrability of the Carr-Madan integrand. Defaults to call_option_carr_madan_alpha.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
call_option_carr_madan_alpha
¶
Option alpha to use for Carr & Madan transform to ensure integrability of the call option transform.
Defaults to 1.5, the value suggested in the original Carr & Madan paper.
Source code in quantflow/utils/marginal.py
call_option_cos
¶
Call option price via the COS method (Fang & Oosterlee 2008).
The call price at log-strike \(k\) is approximated by the cosine series
where the prime denotes a half weight on the \(j=0\) term, \([a,b]\) is the truncation interval, and \(V_j\) are the cosine payoff coefficients for the normalised call payoff \((e^y - 1)^+\) integrated over \([0, b]\). The \(e^k\) factor converts from strike-normalised to forward-space pricing.
Returns an OptionPricingCosResult with the precomputed coefficient vector. Use call_price to evaluate at arbitrary log-strikes in \(O(N)\) per strike.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of cosine series terms. Defaults to 128.
TYPE:
|
moneyness_std_precision
|
Truncation parameter: the integration interval is set to [-moneyness_std_precisionstd, moneyness_std_precisionstd].
TYPE:
|
Source code in quantflow/utils/marginal.py
call_option_lewis
¶
call_option_lewis(n=None, *, max_moneyness=1.5, max_frequency=None, simpson_rule=False, use_fft=False)
Call option price via the Lewis (2001) formula
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_moneyness
|
Maximum moneyness to calculate prices. The log-strike grid is set to [-max_moneynessstd, max_moneynessstd].
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
call_option_transform
¶
Call option transform
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points (possibly complex-shifted).
TYPE:
|
Source code in quantflow/utils/marginal.py
cdf
¶
Compute the cumulative distribution function
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Location in the stochastic process domain space. If a numpy array, the output should have the same shape as the input.
TYPE:
|
Source code in quantflow/utils/marginal.py
cdf_from_characteristic
¶
cdf_from_characteristic(n=None, *, max_frequency=None, simpson_rule=False, use_fft=False, frequency_n=None)
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
frequency_n
|
Number of points for the frequency grid. Overrides n if provided.
TYPE:
|
Source code in quantflow/utils/marginal.py
cdf_jacobian
¶
Jacobian of the cdf with respect to the parameters of the process. It is useful for optimization purposes if necessary.
Optional to implement, otherwise raises NotImplementedError if called.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Location in the state space of the process.
TYPE:
|
Source code in quantflow/utils/marginal.py
characteristic_corrected
¶
Characteristic function corrected for the convexity of the log-price distribution
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points.
TYPE:
|
Source code in quantflow/utils/marginal.py
characteristic_df
¶
Compute the characteristic function with n discretization points and a max frequency
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
domain_range
¶
The space domain range for the random variable
This should be overloaded if required
frequency_range
¶
The frequency domain range for the characteristic function
This should be overloaded if required
| PARAMETER | DESCRIPTION |
|---|---|
max_frequency
|
Upper bound of the frequency grid. Defaults to 20 if None.
TYPE:
|
Source code in quantflow/utils/marginal.py
get_transform
¶
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points. Defaults to 128.
TYPE:
|
support
|
Function returning the space domain grid given the number of points.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
lewis_transform
¶
Lewis (2001) call option transform - no damping parameter required
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points.
TYPE:
|
mean_from_characteristic
¶
Calculate mean as first derivative of characteristic function at 0
| PARAMETER | DESCRIPTION |
|---|---|
d
|
Step size for finite-difference approximation of the derivative.
TYPE:
|
Source code in quantflow/utils/marginal.py
option_support
¶
Compute the x axis.
| PARAMETER | DESCRIPTION |
|---|---|
points
|
Number of support points.
TYPE:
|
max_log_strike
|
Maximum absolute log-strike.
TYPE:
|
Source code in quantflow/utils/marginal.py
option_time_value
¶
option_time_value(n=128, *, max_frequency=None, max_log_strike=1, alpha=1.1, simpson_rule=False, use_fft=False)
Option time value
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
max_log_strike
|
Maximum absolute log-strike for the output grid.
TYPE:
|
alpha
|
Contour shift parameter controlling the integration strip.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
option_time_value_transform
¶
Option time value transform
This transform does not require any additional correction since the integrand is already bounded for positive and negative moneyness
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points.
TYPE:
|
alpha
|
Contour shift parameter controlling the integration strip.
TYPE:
|
Source code in quantflow/utils/marginal.py
pdf
¶
Computes the probability density (or mass) function of the process.
It has a base implementation that computes the pdf from the cdf method, but a subclass should overload this method if a more optimized way of computing it is available.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Location in the stochastic process domain space. If a numpy array, the output should have the same shape as the input.
TYPE:
|
Source code in quantflow/utils/marginal.py
pdf_from_characteristic
¶
pdf_from_characteristic(n=None, *, max_frequency=None, simpson_rule=False, use_fft=False, frequency_n=None)
Compute the probability density function from the characteristic function.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points to use in the transform. If None, use 128.
TYPE:
|
max_frequency
|
The maximum frequency to use in the transform. If not provided, the value from the frequency_range method is used. Only needed for special cases/testing.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
frequency_n
|
Number of points for the frequency grid. Overrides n if provided.
TYPE:
|
Source code in quantflow/utils/marginal.py
pdf_jacobian
¶
Jacobian of the pdf with respect to the parameters of the process. It has a base implementation that computes it from the cdf_jacobian method, but a subclass should overload this method if a more optimized way of computing it is available.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Location in the state space of the process.
TYPE:
|
Source code in quantflow/utils/marginal.py
std
¶
std_validated
¶
Float standard deviation, raising if it is not finite or non-positive.
Used by the Fourier-based pricing methods to set the log-strike grid range; degenerate parameter samples (e.g. during calibration) can produce a non-finite std and would otherwise crash deep in the transform with a confusing error.
Source code in quantflow/utils/marginal.py
std_from_characteristic
¶
variance_from_characteristic
¶
Calculate variance as second derivative of characteristic function at 0
| PARAMETER | DESCRIPTION |
|---|---|
d
|
Step size for finite-difference approximation of the derivative.
TYPE:
|