chainopy.markov_switching

Classes

MarkovSwitchingModel()

MarkovSwitchingModel estimates 1D target values given the current regime.

class chainopy.markov_switching.MarkovSwitchingModel[source]

MarkovSwitchingModel estimates 1D target values given the current regime. The regimes follow a first-order Markov process.

regimes

List of regimes identified in the training data.

Type:

list

num_regimes

Number of unique regimes.

Type:

int

models

Dictionary mapping regimes to their respective AutoReg models.

Type:

dict

num_models

Number of models, corresponding to the number of unique regimes.

Type:

int

__init__()[source]
evaluate(ts_test, ts_pred)[source]

Evaluates the accuracy of the model using the mean squared error metric.

Parameters:
  • ts_test (ndarray) – Real target values of the Time Series

  • ts_pred (ndarray) – Predicted target values of the Time Series

Returns:

float

Return type:

mean square error between ts_test and ts_pred

fit(ts_data, regime_sequence, lags=1)[source]

Trains and sets the models self.models and self._markov_chain attributes

Parameters:
  • ts_data (ndarray) – 1D Target values at different timepoints

  • regime_sequence (list) – Training data consisting of Regimes in chronological Order.

  • lags (int,) – Time lags to consider during autoregression

predict(start_regime, steps=1)[source]

Predicts the target values for a given number of steps into the future.

Parameters:
  • start_regime (str) – Regime at the start of the prediction.

  • steps (int, optional) – Number of steps into the future to predict, by default 1.

Return type:

Tuple[ndarray, ndarray]

Returns:

  • Tuple[np.ndarray, np.ndarray] (Tuple containing the array of predicted)

  • target values and the predicted regime sequence.