HoLeeProcess¶
- class samplepaths.diffusion.HoLeeProcess(*, drift=0.0, vol=1.0, t=1.0, rng=None)[source]¶
Bases:
GaussianNoiseHo-Lee process.
A model for the instantaneous interest rate without reversion to a mean (Ho and Lee, 1986). The process \(X_t\) satisfies the following stochastic differential equation with Wiener process \(W_t\):
\[dX_t = \theta_t dt + \sigma dW_t\]The drift \(\theta_t\) is a number or a function of time. As a function it lets the model reproduce the interest rates observed today for every maturity.
The noise is exact. The drift is added at every step with its value at the end of the step, which is exact for a constant drift.
sample()starts from 0.- Parameters:
drift (Callable[[float], float] | float) – the drift, or \(\theta_t\) above: a number or a function of the time
vol (float) – volatility coefficient of the process, or \(\sigma\) above
t (float) – the right hand endpoint of the time interval \([0,t]\) for the process
rng (Generator | None) – a custom random number generator
- sample(n)[source]¶
Generate a realization.
- Parameters:
n (int) – the number of increments to generate
- Returns:
the realization
- Return type:
NDArray[float64]
- sample_at(times)[source]¶
Generate a realization at specified times, starting from 0.
- Parameters:
times (ArrayLike) – a vector of increasing time values at which to generate the realization
- Returns:
the realization
- Return type:
NDArray[float64]
- property n: int¶
Number of increments of the most recent realization.
- Raises:
RuntimeError – if no realization has been generated yet
- property rng: Generator¶
Random number generator used by the process.
This is the generator passed at instantiation, or the package default
samplepaths.random.generatorwhen none was given.
- sample_at_with_initial(times, initial=0.0)[source]¶
Generate a realization at specified times from an initial value.
The noise is exact. The drift is added at every step with its value at the end of the step, which is exact for a constant drift.
- Parameters:
times (ArrayLike) – a vector of increasing time values at which to generate the realization
initial (float) – the value of the process at time zero
- Returns:
the realization
- Return type:
NDArray[float64]
- sample_paths(n, paths, workers=1)¶
Generate several independent realizations at once.
The realizations have the distribution of those of
sample(). Many processes generate them together, which is much faster than callingsample()repeatedly. For a given seed, the values differ from those of repeated calls tosample(), because the random numbers are drawn in a different order.With
workersgreater than one, the realizations are generated on that many threads, each with its own generator derived from the generator of the process. The result is reproducible for a given seed and number of workers, and differs between numbers of workers. Processes which generate their realizations one after the other ignoreworkers.
- set_times(n)¶
Generate the time values of n increments on [0, t].
- set_times_with_t(end_t, n)¶
Generate the time values of n increments on [0, end_t].
- property times: ndarray[tuple[Any, ...], dtype[float64]]¶
Time values of the most recent realization.
Holds
n + 1equally spaced values on the interval \([0,t]\).- Raises:
RuntimeError – if no realization has been generated yet