econometron.Models.VectorAutoReg.SVAR
classin theeconometron.Models.VectorAutoRegmodule
Overview
The SVAR class implements Structural Vector Autoregression, a powerful extension of the standard VAR model. While a VAR model is great for forecasting and describing the dynamic relationships between variables, an SVAR goes a step further by using economic theory to identify the underlying, independent structural shocks that drive the system.
This class inherits from the VAR class, meaning it has all the capabilities of a standard VAR model (lag selection, estimation, diagnostics, forecasting) and adds a crucial layer of structural identification on top. This allows you to move from correlation to a form of causal inference.
The main goal is to untangle the correlated error terms from the VAR (residuals) into economically meaningful, uncorrelated structural shocks (structural_shocks). This is achieved by imposing restrictions on the relationships between these shocks.
Class Definition
Because the SVAR class is a child of the VAR class, its initialization is identical. You create an instance with your time series data and the same configuration options as the VAR model.
- Initialization
from econometron.Models.VectorAutoReg.SVAR import SVAR
model = SVAR(data, max_p=2, criterion='AIC', method='chol')Parameters
The SVAR constructor accepts all the same parameters as the VAR class documentation (data, max_p, criterion, plot, etc.). There are no new parameters introduced at initialization. The key structural decisions are made later by calling the identify() method.
The Structural VAR Workflow: From VAR to SVAR
Working with an SVAR model follows a clear, logical sequence. You can't perform structural analysis until you have a well-specified underlying VAR model.
Fit a Standard VAR Model: The first step is always to estimate the reduced-form VAR. You do this by creating an
SVARobject and calling the.fit()method, which it inherits from theVARclass. This will automatically find the best lag order and estimate the VAR coefficients.Impose Identifying Restrictions: This is the core "structural" step. After fitting the VAR, you call the
identify()method. Here, you choose a scheme (like Cholesky, long-run restrictions, etc.) to impose your economic assumptions and uncover the structural shocks.Perform Structural Analysis: Once the model is identified, you can analyze the results. The
impulse_res()andFEVD()methods are now "supercharged" to show the effects of the identified structural shocks, not just statistical correlations. You can also use new methods likeshock_decomposition()to see how these shocks have historically influenced your variables.
Class Attributes
An SVAR object contains all the attributes of a fitted VAR model, plus several new ones that store the results of the structural identification.
| Attribute | Type | Description |
|---|---|---|
A, B | np.ndarray | The structural matrices that define the relationship between reduced-form residuals and structural shocks. |
A_inv_B | np.ndarray | The contemporaneous impact matrix, showing the immediate effect of a structural shock on the variables. |
identification_method | str | The method used for identification (e.g., 'chol', 'blanchard-quah', 'AB'). |
structural_shocks | np.ndarray | The time series of the estimated, uncorrelated structural shocks. |
Methods
New SVAR Methods
These methods are unique to the SVAR class and are used to perform the structural analysis.
identify(method='chol', A=None, B=None)
This is the most important method in the class. It imposes restrictions on the model to identify the structural shocks from the VAR residuals. You must call this method after fit() and before any structural analysis.
- Parameters:
method(str): The identification scheme.'chol': Cholesky decomposition. Imposes a recursive, lower-triangular structure. Assumes the first variable is not contemporaneously affected by shocks to other variables, the second is only affected by the first, and so on. The order of your data columns matters immensely!'blanchard-quah': Long-run restrictions. Assumes that certain shocks have no long-term effect on certain variables.'AB': Direct AB model. Allows you to specify theAandBmatrices manually based on your own economic theory.
A,B(np.ndarray): The specific matrices to use ifmethod='AB'.
shock_decomposition(h=10, plot=False)
Decomposes the historical time series of each variable into contributions from each identified structural shock, plus the effect of initial conditions. This is fantastic for historical storytelling (e.g., "how much of the 2008 recession was due to a demand shock vs. a supply shock?").
- Returns: An
np.ndarraycontaining the decomposition values.
Overridden Methods
These methods exist in the VAR class but are modified in the SVAR class to work with the identified structural shocks, giving them a causal interpretation.
impulse_res(h=10, ...)
Computes the Structural Impulse Response Functions (SIRFs). After identification, these plots show the dynamic response of each variable to a one-unit increase in an economically meaningful structural shock.
FEVD(h=10, ...)
Computes the Structural Forecast Error Variance Decomposition (SFEVD). It shows what percentage of the forecast uncertainty for each variable is explained by each structural shock at different time horizons.
Example Usage
Here’s a complete workflow for estimating and analyzing an SVAR model.
1. Generate Sample Data and Fit the VAR
First, we'll create some data and fit the underlying VAR model. This part is identical to using the VAR class.
import numpy as np
import pandas as pd
from svar_class import SVAR # Assuming the class is saved in svar_class.py
# --- Data Generation ---
np.random.seed(42)
n_obs = 300
# True VAR(1) process
data = np.zeros((n_obs, 2))
errors = np.random.randn(n_obs, 2)
for t in range(1, n_obs):
# Reduced-form errors (correlated)
u1 = errors[t, 0]
u2 = 0.5 * u1 + errors[t, 1] # u2 is correlated with u1
# Simple VAR dynamics
y1_lag = data[t-1, 0]
y2_lag = data[t-1, 1]
data[t, 0] = 0.7 * y1_lag - 0.2 * y2_lag + u1
data[t, 1] = 0.3 * y1_lag + 0.5 * y2_lag + u2
df = pd.DataFrame(data, columns=['Output_Growth', 'Inflation'])
# --- Step 1: Fit the VAR ---
# Initialize the SVAR object and fit the underlying VAR
svar_model = SVAR(df, max_p=3, criterion='AIC')
svar_model.fit() # This runs the standard VAR estimation2. Identify Structural Shocks
Now for the key step. We'll use a Cholesky decomposition, a common identification method. This assumes that Output_Growth shocks can affect Inflation in the same period, but Inflation shocks can only affect Output_Growth with a lag.
# --- Step 2: Impose Identifying Restrictions ---
print("\n--- Identifying with Cholesky Decomposition ---")
svar_model.identify(method='chol')
print("SVAR model identified successfully.")3. Perform Structural Analysis
With the model identified, we can now compute and plot the structural IRFs and FEVDs to understand the impact of our identified "Output Shock" and "Inflation Shock".
# --- Step 3: Structural Analysis ---
print("\n--- Computing Structural Impulse Responses ---")
# The IRFs now show the effect of identified structural shocks
svar_model.impulse_res(h=24, bootstrap=True)
print("\n--- Computing Structural FEVD ---")
svar_model.FEVD(h=24, plot=True)
print("\n--- Computing Historical Shock Decomposition ---")
svar_model.shock_decomposition(h=24, plot=True)