econometron.Models.VectorAutoReg.VARIMA
classin theeconometron.Models.VectorAutoRegmodule- 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
TransformTSclass. - Applications in DSGE: Used to estimate empirical dynamics of macroeconomic variables or compare with DSGE model simulations.
Class Definition
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:
| Name | Type | Description | Default |
|---|---|---|---|
data | pd.DataFrame or np.ndarray | Input time series data. | None |
max_p | int | Maximum AR order. | 5 |
max_d | int | Maximum differencing order. | 2 |
max_q | int | Maximum MA order. | 5 |
columns | Optional[List[str]] | Columns to use (default: all numeric). | None |
forecast_h | int | Forecast horizon. | 6 |
plot | bool | Plot results. | True |
check_stationarity | bool | Check for stationarity. | True |
bootstrap_n | int | Number of bootstrap samples for CIs. | 1000 |
criterion | str | Model selection criterion (‘AIC’ or ‘BIC’). | ‘AIC’ |
ci_alpha | float | Significance level for CIs (0 to 1). | 0.05 |
Key | Optional[str] | Model identifier. | None |
Threshold | float | Threshold for significant parameters. | 0.8 |
orth | bool | Orthogonalize residuals. | False |
log_data | bool | Apply log transformation for non-positive data. | True |
enforce_stab_inver | bool | Enforce 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.ndarrayinput topd.DataFrame. - Initializes
TransformTSwith differencing method, applying stationarity checks and optional log transformation. - Stores original data and differencing orders from
TransformTS. - Updates
max_dif required differencing exceeds the specified value. - Initializes the parent
VARMAclass with differenced data, passing relevant parameters. - Sets
structural_id=Falsesince VARIMA handles integration explicitly.
- Converts
Explanation:
- Prepares non-stationary data by differencing to achieve stationarity, then delegates VARMA modeling to the parent class.
- The
TransformTSclass 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:
pythondata = 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.fitmethod to differenced data and storing results.Parameters:
Name Type Description Default pOptional[int] AR order (default: selected via criterion). None qOptional[int] MA order (default: selected via criterion). None outputbool Print results and diagnostics. True Returns:
dict: Model fit results (fromVARMA.fit), including parameters, residuals, and diagnostics.
Mechanics:
- Calls
VARMA.fitwith the differenced data, passingp,q, andverbose=False. - Stores the result in
self.best_model, including optimalself.best_pandself.best_q. - Updates
self.diff_ordersfromTransformTS. - If
output=True, logs the model order (e.g., VARIMA(p,d,q)) and callstrns_infoto display transformation details.
- Calls
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
TransformTSto 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:
pythonresults = 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 fromTransformTS, 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.
- Calls
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:
pythoninfo = 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:
Name Type Description Default n_periodsint Number of forecast periods. 6 plotbool Plot forecasts with confidence intervals. True tolfloat Numerical stability tolerance. 1e-6 Returns:
dict: Containspoint(point forecasts),ci_lower, andci_upper(confidence intervals) aspd.DataFrames in the original scale.
Mechanics:
- Checks if a model is fitted (
self.best_modelexists). - Calls
VARMA.predictto generate forecasts in the differenced scale, obtainingpoint,ci_lower, andci_upperDataFrames. - 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.
- Retrieves the differencing order ( d ) and log transformation status from
- 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.
- Checks if a model is fitted (
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:
pythonforecasts = 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:
Name Type Description Default n_periodsint Number of periods to simulate. 100 plotbool Plot simulated series. True tolfloat Numerical stability tolerance. 1e-6 Returns:
np.ndarray: Simulated series of shape(n_periods, K)in the original scale.
Mechanics:
- Calls
VARMA.simulateto 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.
- Calls
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:
pythonsim_data = varima.simulate(n_periods=50) print(sim_data.shape)
Notes
Integration with DSGE Models:
- The
VARIMAclass is used ineconometron.models.nonlinear_dsgeto 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.
- The
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
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)