Skip to content

Core

stochPathSim.core.TimeGrid

An increasing set of simulation times starting at 0.

Parameters:

Name Type Description Default
times array_like

Strictly increasing times in years, starting at 0.

required

dt property

dt

Step lengths, one per step.

uniform classmethod

uniform(T, n_steps)

A grid of n_steps equal steps from 0 to T.

with_times classmethod

with_times(T, n_steps, extra_times)

A uniform grid refined so that it also contains extra_times.

index

index(t)

Index of the grid time equal to t (within 1e-12).

stochPathSim.core.SimulationResult dataclass

Simulated paths of one or more state variables on a common time grid.

Each entry of paths has shape (n_paths, n_times); column 0 holds the initial state at t = 0.

primary property

primary

Name of the main state variable (the first one).

terminal

terminal(name=None)

Values at the last grid time.

at

at(t, name=None)

Values at grid time t.

mean

mean(name=None)

Cross-sectional mean at each time.

std

std(name=None)

Cross-sectional sample standard deviation at each time.

quantile

quantile(q, name=None)

Cross-sectional quantile(s) at each time, q in [0, 1].

to_frame

to_frame(name=None, max_paths=None)

Paths as a pandas.DataFrame indexed by time, one column per path.

plot

plot(name=None, n_paths=30, ax=None, **kwargs)

Interactive Plotly chart of sample paths, the mean and the 1%-99% band.

ax is accepted for backward compatibility and ignored.

fan

fan(name=None, **kwargs)

Interactive fan chart of nested quantile bands.

distribution

distribution(t=None, name=None, **kwargs)

Interactive histogram of the values at time t (default: the horizon).

stochPathSim.core.StochasticProcess

Bases: ABC

A process that can be simulated on a time grid.

Subclasses set state_names and n_factors and implement :meth:_simulate, which receives standard normal draws of shape (n_paths, n_steps, n_factors) and returns one array per state variable of shape (n_paths, n_steps + 1).

simulate

simulate(T=1.0, n_steps=252, n_paths=10000, *, seed=None, antithetic=False, grid=None, normals=None)

Simulate paths.

Parameters:

Name Type Description Default
T (float, int)

Horizon in years and number of equal steps (ignored if grid is given).

1.0
n_steps (float, int)

Horizon in years and number of equal steps (ignored if grid is given).

1.0
n_paths int

Number of paths (ignored if normals is given).

10000
seed int or Generator

Seed for reproducible results.

None
antithetic bool

Use antithetic variates (n_paths must be even).

False
grid TimeGrid

Custom, possibly non-uniform, time grid.

None
normals ndarray

Pre-generated standard normals (n_paths, n_steps, n_factors), e.g. to drive several processes with common random numbers.

None

stochPathSim.core.random

Random number generation for path simulation.

make_rng

make_rng(seed=None)

Return a NumPy Generator; pass an int for reproducible results.

standard_normals

standard_normals(rng, n_paths, n_steps, n_factors=1, *, antithetic=False, correlation=None)

Independent (or correlated) standard normal draws.

Returns an array of shape (n_paths, n_steps, n_factors).

Parameters:

Name Type Description Default
antithetic bool

Pair every draw with its negative. n_paths must then be even.

False
correlation array_like

n_factors x n_factors correlation matrix applied through its Cholesky factor.

None

cholesky

cholesky(correlation, n_factors=None)

Lower Cholesky factor of a validated correlation matrix.

stochPathSim.core.quasirandom

Sobol quasi-Monte-Carlo normals, with optional Brownian-bridge ordering.

sobol_normals

sobol_normals(n_paths, n_steps, n_factors=1, *, seed=None, scramble=True, antithetic=False, brownian_bridge=False, grid=None, correlation=None)

Generate QMC normals accepted by StochasticProcess.simulate(normals=...).

n_paths must be a power of two (Sobol balance property). Scrambling is enabled by default; use independent seeds for confidence intervals across multiple QMC scrambles, NOT the pathwise sample standard error of one scrambled Sobol point set. With antithetic=True, half the samples are generated and their negatives are appended.

brownian_bridge=True maps early Sobol dimensions to long-horizon Brownian motions, reducing effective dimension for many path-dependent payoffs. grid selects the actual non-uniform Brownian bridge times; otherwise a unit-horizon uniform grid is used. With the bridge disabled, grid is only shape-validated and has no effect on the normals.

correlation applies Cholesky factor correlation to the output factors, after Brownian-bridge construction.

stochPathSim.curves.ZeroCurve

A continuously compounded zero curve.

Zero rates are interpolated between the pillars and held flat outside them, and discount factors are exp(-z(t) t).

Parameters:

Name Type Description Default
times array_like

Pillar times in years, strictly increasing and positive.

required
zero_rates array_like

Continuously compounded zero rates at the pillars.

required
interpolation ('monotone_cubic', 'linear')

"monotone_cubic" (PCHIP, the default) keeps instantaneous forward rates continuous between the pillars, which matters for curve-fitted short-rate models such as Hull-White, whose drift follows the forward curve. "linear" interpolates zero rates linearly; its forward curve jumps at every pillar.

"monotone_cubic"

flat classmethod

flat(rate)

A flat curve at a continuously compounded rate.

from_discount_factors classmethod

from_discount_factors(times, discount_factors, **kwargs)

Build a curve from discount factors P(0, t).

zero_rate

zero_rate(t)

Continuously compounded zero rate to time t.

discount

discount(t)

Discount factor P(0, t).

forward_rate

forward_rate(t, dt=1e-05)

Instantaneous forward rate f(0, t) = -d ln P(0, t) / dt.

forward_rate_between

forward_rate_between(t1, t2)

Simply compounded forward rate between t1 and t2.