regime_switching¶
Defined in fynance.research
- regime_switching(n, *, regimes=((0.0, 0.01), (0.0, 0.03)), p_switch=0.02, s0=100.0, seed=None)[source]
Markov regime-switching price path.
At each step the active regime switches (to a uniformly-drawn regime) with probability
p_switch; log-returns are then drawn from the active regime’s(mu, sigma). The varying volatility makes it a natural input forfynance.detect_regimes.- Parameters:
- nint
Number of observations (path length).
- regimestuple of (float, float)
(mu, sigma)per regime.- p_switchfloat
Per-step probability of switching regime.
- s0float
Initial price.
- seedint, optional
Seed for reproducibility.
Noneis nondeterministic.
- Returns:
- fynance.core.PriceSeries
Price path of length
n.
Examples
>>> import numpy as np >>> from fynance.research import regime_switching >>> a, b = regime_switching(5, seed=3), regime_switching(5, seed=3) >>> bool(np.allclose(a.to_numpy(), b.to_numpy())) True