psytest.utils.functions module#
psytest.utils.functions#
This module contains utility functions for the psytest package. It includes functions for generating random walks, simulating Markov processes, and calculating default parameters for bubble detection. It should NOT be used directly by users and is solely intended for internal use within the psytest package and testing purposes.
- psytest.utils.functions.r0_default(nobs: int) int [source]#
Calculates the default
r0
parameter following Phillips, Shi & Yu (2015) as a function of the number of observations.- Parameters:
- Returns:
default_r0 – The default
r0
parameter- Return type:
Notes
Following the original paper, we set the default
r0
parameter as:\[r_0 = 0.01 \times 0.08 \times \sqrt{n}\]where \(n\) is the number of observations.
- psytest.utils.functions.minlength_default(nobs: int, delta: float) int [source]#
Calculates the minimum bubble length based on the number of observations.
- Parameters:
- Returns:
minlength – Minimum bubble length
- Return type:
Notes
Following the original paper, we set the minimum bubble length as:
\[\text{min_length} = \delta\frac{\log(n)}{n}\]where \(n\) is the number of observations.
- psytest.utils.functions.random_walk(nreps: int, nobs: int) ndarray[tuple[int, ...], dtype[float64]] [source]#
Generates a monte carlo simulation of random walks.
- Parameters:
- Returns:
random_walk_matrix – Matrix of shape (
nreps
,nobs
) with the random walks.- Return type:
NDArray[float64]
Notes
\[RW_{i, t} = \sum_{s=1}^{t} \frac{\varepsilon_{i, s}}{\sqrt{n}}\]
- psytest.utils.functions.simulate_markov(nobs: int, p=0.975, beta_list: list[float] = [1.01, 1]) tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]]] [source]#
Simulates a two regime AR(1) process with a Markov switching beta.
- Parameters:
- Returns:
[list[float], list[float]] – the first one with the beta values and the second one with the simulated process values.
- Return type:
A tuple containing two lists
Notes
The process is defined as:
\[y_t = \beta_t y_{t-1} + \varepsilon_t\]where \(\varepsilon_t \sim \mathcal{N}(0, 1)\) and \(\beta_t\) is a Markov switching variable that takes values from
beta_list
. The transition probability is defined byp
, which is the probability of staying in the same regime.
- psytest.utils.functions.size_rgrid(r0: float, rstep: float) int [source]#
Calculates the size of the rgrid starting at
r0
and with steprstep
.- Parameters:
- Returns:
size – Size of the rgrid.
- Return type:
Notes
The size is calculated as:
\[\text{size} = \left\lfloor \frac{1 - r_0}{\text{rstep}} \right\rfloor + 1\]