Skip to content

Wiener process

quantflow.sp.wiener.WienerProcess pydantic-model

Bases: StochasticProcess1D

Fields:

sigma pydantic-field

sigma = 1

volatility

sigma2 property

sigma2

characteristic_exponent

characteristic_exponent(t, u)
Source code in quantflow/sp/wiener.py
def characteristic_exponent(self, t: Vector, u: Vector) -> Vector:
    su = self.sigma * u
    return 0.5 * su * su * t

sample

sample(n, time_horizon=1, time_steps=100)
Source code in quantflow/sp/wiener.py
def sample(self, n: int, time_horizon: float = 1, time_steps: int = 100) -> Paths:
    paths = Paths.normal_draws(n, time_horizon, time_steps)
    return self.sample_from_draws(paths)

sample_from_draws

sample_from_draws(draws, *args)
Source code in quantflow/sp/wiener.py
def sample_from_draws(self, draws: Paths, *args: Paths) -> Paths:
    sdt = self.sigma * np.sqrt(draws.dt)
    paths = np.zeros(draws.data.shape)
    paths[1:] = np.cumsum(draws.data[:-1], axis=0)
    return Paths(t=draws.t, data=sdt * paths)

analytical_mean

analytical_mean(t)
Source code in quantflow/sp/wiener.py
def analytical_mean(self, t: FloatArrayLike) -> FloatArrayLike:
    return 0 * t

analytical_variance

analytical_variance(t)
Source code in quantflow/sp/wiener.py
def analytical_variance(self, t: FloatArrayLike) -> FloatArrayLike:
    return t * self.sigma2

analytical_pdf

analytical_pdf(t, x)
Source code in quantflow/sp/wiener.py
def analytical_pdf(self, t: FloatArrayLike, x: FloatArrayLike) -> FloatArrayLike:
    return norm.pdf(x, scale=self.analytical_std(t))

analytical_cdf

analytical_cdf(t, x)
Source code in quantflow/sp/wiener.py
def analytical_cdf(self, t: FloatArrayLike, x: FloatArrayLike) -> FloatArrayLike:
    return norm.cdf(x, scale=self.analytical_std(t))

characteristic

characteristic(t, u)

Characteristic function at time t for a given input parameter u

The characteristic function represents the Fourier transform of the probability density function

\[\begin{equation} \Phi = {\mathbb E} \left[e^{i u x_t}\right] = e^{-\phi(t, u)} \end{equation}\]

where \(\phi\) is the characteristic exponent, which can be more easily computed for many processes.

PARAMETER DESCRIPTION
t

Time horizon

TYPE: FloatArrayLike

u

Characteristic function input parameter

TYPE: Vector

Source code in quantflow/sp/base.py
def characteristic(
    self,
    t: Annotated[FloatArrayLike, Doc("Time horizon")],
    u: Annotated[Vector, Doc("Characteristic function input parameter")],
) -> Vector:
    r"""Characteristic function at time `t` for a given input parameter `u`

    The characteristic function represents the Fourier transform of the
    probability density function

    \begin{equation}
        \Phi = {\mathbb E} \left[e^{i u x_t}\right] = e^{-\phi(t, u)}
    \end{equation}

    where $\phi$ is the characteristic exponent, which can be more easily
    computed for many processes.
    """
    return np.exp(-self.characteristic_exponent(t, u))

convexity_correction

convexity_correction(t)

Convexity correction for the process

Source code in quantflow/sp/base.py
def convexity_correction(self, t: FloatArrayLike) -> Vector:
    """Convexity correction for the process"""
    return -self.characteristic_exponent(t, complex(0, -1)).real

analytical_std

analytical_std(t)

Analytical standard deviation of the process at time t

This has a closed form solution if the process has an analytical variance

Source code in quantflow/sp/base.py
def analytical_std(self, t: FloatArrayLike) -> FloatArrayLike:
    """Analytical standard deviation of the process at time `t`

    This has a closed form solution if the process has an analytical variance
    """
    return np.sqrt(self.analytical_variance(t))

marginal

marginal(t)

Marginal distribution of the process at time t

Source code in quantflow/sp/base.py
def marginal(self, t: FloatArrayLike) -> StochasticProcess1DMarginal:
    """Marginal distribution of the process at time `t`"""
    return StochasticProcess1DMarginal(process=self, t=t)

domain_range

domain_range()
Source code in quantflow/sp/base.py
def domain_range(self) -> Bounds:
    return default_bounds()

frequency_range

frequency_range(std, max_frequency=None)

Maximum frequency when calculating characteristic functions

Source code in quantflow/sp/base.py
def frequency_range(self, std: float, max_frequency: float | None = None) -> Bounds:
    """Maximum frequency when calculating characteristic functions"""
    if max_frequency is None:
        max_frequency = np.sqrt(40 / std / std)
    return Bounds(0, max_frequency)

support

support(mean, std, points)

Support of the process at time t

Source code in quantflow/sp/base.py
def support(self, mean: float, std: float, points: int) -> FloatArray:
    """Support of the process at time `t`"""
    bounds = self.domain_range()
    start = float(sigfig(bound_from_any(bounds.lb, mean - std)))
    end = float(sigfig(bound_from_any(bounds.ub, mean + std)))
    return np.linspace(start, end, points + 1)