MarkovSwitchingDFM.fit#

MarkovSwitchingDFM.fit(*, max_iter=300)[source]#

Maximize the Kim-approximate likelihood from data-driven starts.

Starting values come from a principal-component pass – the factor space is cheap to locate; the switch is what the optimizer earns – and the parameters travel in unconstrained transforms, so the optimizer never sees a boundary. The search is L-BFGS-B with finite-difference gradients, which is where the running time goes.

Parameters:

max_iter (int) – Optimizer iteration cap.

Return type:

MarkovSwitchingDFMResult

Returns:

The fitted MarkovSwitchingDFMResult.

Raises:

NumericalError – If the likelihood cannot be evaluated at the starting point.

Example

A capped run returns with converged false and a lower likelihood than the full fit on the class Example; the fit is deterministic, so two calls agree exactly:

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> f = np.zeros(100)
>>> for t in range(1, 100):
...     low = t % 25 < 5
...     f[t] = (-1.5 if low else 0.5) + 0.6 * f[t - 1] + 0.5 * rng.standard_normal()
>>> x = np.outer(f, [1.0, 0.8, 1.2]) + 0.6 * rng.standard_normal((100, 3))
>>> model = MarkovSwitchingDFM(x)
>>> capped = model.fit(max_iter=5)
>>> capped.converged, capped.n_params, capped.factor.shape
(False, 11, (100,))
>>> capped.llf == model.fit(max_iter=5).llf
True