Skip to content

econometron.Models.VectorAutoReg.VARIMA

  • class in the econometron.Models.VectorAutoReg module
  • inherits from VARMA

Overview

The VARIMA class models multivariate time series with non-stationary components by applying differencing (integration) to achieve stationarity, then fitting a VARMA model to the differenced data. It supports forecasting, simulation, and visualization, with features like automatic lag selection, stationarity checks, and confidence intervals.

Key Concepts

  • VARIMA Model: Extends the VARMA model by incorporating differencing: [ \Delta^d Y_t = \Phi_1 \Delta^d Y_{t-1} + \dots + \Phi_p \Delta^d Y_{t-p} + \epsilon_t + \Theta_1 \epsilon_{t-1} + \dots + \Theta_q \epsilon_{t-q} ] where ( \Delta^d Y_t ) is the ( d )-th differenced series, ( \Phi_i ) are AR coefficients, ( \Theta_j ) are MA coefficients, and ( \epsilon_t ) is white noise.
  • Differencing: Removes trends or unit roots to make the series stationary, handled by the TransformTS class.
  • Applications in DSGE: Used to estimate empirical dynamics of macroeconomic variables or compare with DSGE model simulations.

Class Definition

python
from econometron.Models.VectorAutoReg.VARIMA import VARIMA

varima=VARIMA(data, max_p=5, max_d=2, max_q=5, columns=None, forecast_h=6, plot=True, check_stationarity=True, bootstrap_n=1000, criterion='AIC', ci_alpha=0.05, Key=None, Threshold=0.8, orth=False, log_data=True, enforce_stab_inver=False)

Parameters:

NameTypeDescriptionDefault
datapd.DataFrame or np.ndarrayInput time series data.None
max_pintMaximum AR order.5
max_dintMaximum differencing order.2
max_qintMaximum MA order.5
columnsOptional[List[str]]Columns to use (default: all numeric).None
forecast_hintForecast horizon.6
plotboolPlot results.True
check_stationarityboolCheck for stationarity.True
bootstrap_nintNumber of bootstrap samples for CIs.1000
criterionstrModel selection criterion (‘AIC’ or ‘BIC’).‘AIC’
ci_alphafloatSignificance level for CIs (0 to 1).0.05
KeyOptional[str]Model identifier.None
ThresholdfloatThreshold for significant parameters.0.8
orthboolOrthogonalize residuals.False
log_databoolApply log transformation for non-positive data.True
enforce_stab_inverboolEnforce stability/invertibility (not used).False
  • Attributes:

    • self.I (TransformTS): Instance for data transformation and stationarity checks.
    • self.original_data (pd.DataFrame): Original input data.
    • self.data (pd.DataFrame): Differenced (transformed) data.
    • self.diff_orders (dict): Differencing orders per column.
    • self.max_d (int): Maximum differencing order.
    • Inherits attributes from VARMA (e.g., best_model, best_p, best_q, columns).
  • Mechanics:

    • Converts np.ndarray input to pd.DataFrame.
    • Initializes TransformTS with differencing method, applying stationarity checks and optional log transformation.
    • Stores original data and differencing orders from TransformTS.
    • Updates max_d if required differencing exceeds the specified value.
    • Initializes the parent VARMA class with differenced data, passing relevant parameters.
    • Sets structural_id=False since VARIMA handles integration explicitly.
  • Explanation:

    • Prepares non-stationary data by differencing to achieve stationarity, then delegates VARMA modeling to the parent class.
    • The TransformTS class determines the necessary differencing order per variable, ensuring stationarity for VARMA estimation.
    • Supports flexible data handling (e.g., log transformation for non-positive data) and model selection.
  • Example:

    python
    data = pd.DataFrame(np.random.randn(100, 2).cumsum(axis=0), columns=['Y1', 'Y2'])
    varima = VARIMA(data, max_p=2, max_d=1, max_q=2, columns=['Y1', 'Y2'])

Methods:

fit(self, p=None, q=None, output=True)

  • Purpose: Fits the VARIMA model by applying the parent VARMA.fit method to differenced data and storing results.

  • Parameters:

    NameTypeDescriptionDefault
    pOptional[int]AR order (default: selected via criterion).None
    qOptional[int]MA order (default: selected via criterion).None
    outputboolPrint results and diagnostics.True
  • Returns:

    • dict: Model fit results (from VARMA.fit), including parameters, residuals, and diagnostics.
  • Mechanics:

    • Calls VARMA.fit with the differenced data, passing p, q, and verbose=False.
    • Stores the result in self.best_model, including optimal self.best_p and self.best_q.
    • Updates self.diff_orders from TransformTS.
    • If output=True, logs the model order (e.g., VARIMA(p,d,q)) and calls trns_info to display transformation details.
  • Mathematical Foundation:

    • Fits a VARMA(p,q) model to ( \Delta^d Y_t ): [ \Delta^d Y_t = \sum_{i=1}^p \Phi_i \Delta^d Y_{t-i} + \epsilon_t + \sum_{j=1}^q \Theta_j \epsilon_{t-j} ]
    • The differencing order ( d ) is determined by TransformTS to ensure stationarity.
  • Explanation:

    • Leverages the parent class for VARMA estimation while handling differencing transparently.
    • The output provides a summary of the model, including differencing orders, useful for DSGE model validation.
  • Example:

    python
    results = varima.fit(p=1, q=1)
    print(results)

Method: trns_info(self)

  • Purpose: Retrieves and displays transformation and stationarity information for each variable.

  • Returns:

    • dict: Transformation details from TransformTS, including differencing order and stationarity status.
  • Mechanics:

    • Calls self.I.trns_info() to get transformation details.
    • Prints a formatted summary for each column, including differencing order, log transformation status, and stationarity results.
    • Returns the transformation dictionary.
  • Explanation:

    • Provides transparency into the preprocessing steps (e.g., differencing, log transformation) applied to achieve stationarity.
    • Critical for understanding how non-stationary data is handled in DSGE applications.
  • Example:

    python
    info = varima.trns_info()
    # Output example:
    # Column: Y1
    #   Differencing Order: 1
    #   Log Transformed: False
    #   Stationary: True

Method: predict(self, n_periods=6, plot=True, tol=1e-6)

  • Purpose: Generates forecasts for the specified horizon, reversing differencing to return predictions in the original scale.

  • Parameters:

    NameTypeDescriptionDefault
    n_periodsintNumber of forecast periods.6
    plotboolPlot forecasts with confidence intervals.True
    tolfloatNumerical stability tolerance.1e-6
  • Returns:

    • dict: Contains point (point forecasts), ci_lower, and ci_upper (confidence intervals) as pd.DataFrames in the original scale.
  • Mechanics:

    • Checks if a model is fitted (self.best_model exists).
    • Calls VARMA.predict to generate forecasts in the differenced scale, obtaining point, ci_lower, and ci_upper DataFrames.
    • For each column:
      • Retrieves the differencing order ( d ) and log transformation status from self.I.
      • If log-transformed, exponentiates forecasts and confidence intervals.
      • If ( d = 0 ), uses differenced forecasts directly.
      • If ( d > 0 ), reverses differencing by cumulative summation: [ \hat{Y}{T+j} = \sum^j \Delta^d \hat{Y}{T+k} + Y + \sum_{m=1}^{d-1} \Delta^{d-m} Y_{T-m} ] using the last ( d ) values from the original data.
      • Applies the same process to confidence intervals.
    • Creates forecast DataFrames with appropriate indices (datetime if available, else integer).
    • If plot=True, generates subplots for each variable, showing historical data, forecasts, and confidence intervals.
  • Mathematical Foundation:

    • Forecasts in the differenced scale are generated by the VARMA model, then integrated to the original scale.
    • Confidence intervals are computed via bootstrap (inherited from VARMA) and similarly integrated.
  • Explanation:

    • Produces forecasts in the original scale, accounting for differencing and log transformations, making results interpretable for DSGE model variables.
    • Visualization aids in comparing forecasts to historical data, useful for economic analysis.
  • Example:

    python
    forecasts = varima.predict(n_periods=10)
    print(forecasts['point'])

Method: simulate(self, n_periods=100, plot=True, tol=1e-6)

  • Purpose: Simulates time series data from the fitted VARIMA model, returning results in the original scale.

  • Parameters:

    NameTypeDescriptionDefault
    n_periodsintNumber of periods to simulate.100
    plotboolPlot simulated series.True
    tolfloatNumerical stability tolerance.1e-6
  • Returns:

    • np.ndarray: Simulated series of shape (n_periods, K) in the original scale.
  • Mechanics:

    • Calls VARMA.simulate to generate simulations in the differenced scale.
    • For each column:
      • Applies exponentiation if log-transformed.
      • If ( d = 0 ), uses the simulated series directly.
      • If ( d > 0 ), reverses differencing by cumulative summation, incorporating the last ( d ) values from the original data.
    • Creates a DataFrame with appropriate indices for plotting.
    • If plot=True, generates subplots for each variable, showing simulated series.
  • Mathematical Foundation:

    • Simulations are generated from the VARMA model: [ \Delta^d Y_t = \sum_{i=1}^p \Phi_i \Delta^d Y_{t-i} + \epsilon_t + \sum_{j=1}^q \Theta_j \epsilon_{t-j} ]
    • Integration reverses differencing to obtain ( Y_t ).
  • Explanation:

    • Simulates possible future paths of the time series, useful for scenario analysis in DSGE models.
    • Visualization helps assess the model’s ability to replicate observed dynamics.
  • Example:

    python
    sim_data = varima.simulate(n_periods=50)
    print(sim_data.shape)

Notes

  • Integration with DSGE Models:

    • The VARIMA class is used in econometron.models.nonlinear_dsge to model empirical dynamics of macroeconomic variables (e.g., GDP, inflation) and compare with DSGE model predictions.
    • The differencing feature handles non-stationary series common in economic data.
  • Advantages:

    • Handles non-stationarity through automatic differencing.
    • Inherits robust VARMA estimation, including model selection and bootstrap confidence intervals.
    • Flexible data preprocessing (log transformation, stationarity checks).
  • Dependencies:

    • pandas: For data handling and indexing.
    • numpy: For numerical computations.
    • matplotlib.pyplot: For plotting.
    • econometron.Models.VectorAutoReg.VARMA: Parent class for VARMA modeling.
    • econometron.utils.data_preparation.process_timeseries.TransformTS: For differencing and stationarity checks.
  • Limitations:

    • Curse of Dimensionality: High-dimensional data increases computational cost.
    • Stationarity Assumption: Assumes differencing achieves stationarity, which may not hold for all series.
    • Log Transformation: May not be suitable for all data types.

Example Use Case

python
import pandas as pd
import numpy as np
from econometron.models.vectorautoreg import VARIMA

# Synthetic data
np.random.seed(42)
data = pd.DataFrame(np.random.randn(100, 2).cumsum(axis=0), columns=['GDP', 'Rate'], 
                    index=pd.date_range('2000-01-01', periods=100, freq='Q'))

# Initialize and fit VARIMA
varima = VARIMA(data, max_p=2, max_d=1, max_q=2, columns=['GDP', 'Rate'], forecast_h=10)
varima.fit()

# Transformation info
varima.trns_info()

# Forecast
forecasts = varima.predict(n_periods=10)

# Simulate
sim_data = varima.simulate(n_periods=50)