Metadata-Version: 2.4
Name: var-irf
Version: 0.1.0
Summary: Impulse Response Function (IRF) computation and plotting utilities built on statsmodels VAR
Author: VAR-IRF Maintainers
License: MIT License
        
        Copyright (c) 2025 Tianzhu Qin
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/TianzhuQin/Vector-Autoregression-Impulse-Response-Function
Project-URL: Repository, https://github.com/TianzhuQin/Vector-Autoregression-Impulse-Response-Function.git
Keywords: irf,var,econometrics,time-series,statsmodels,impulse-response
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.21
Requires-Dist: pandas>=1.3
Requires-Dist: statsmodels>=0.13
Requires-Dist: scipy>=1.7
Requires-Dist: matplotlib>=3.5
Dynamic: license-file

## VAR-IRF

Impulse Response Function (IRF) utilities for VAR models with plotting helpers. Extracted from the workflow in `test.ipynb`.

### Installation

```bash
pip install .
```

Once published to PyPI: `pip install var-irf`.

Repository: `https://github.com/TianzhuQin/Vector-Autoregression-Impulse-Response-Function`

### Method summary (from the notebook)

- Fit a VAR(p) with `statsmodels.tsa.api.VAR(df).fit(lags)`.
- Get IRF object via `fit(...).irf(h)`:
  - IRF values: cumulative `cum_effects` (or non-cumulative `irfs`).
  - Error bands:
    - Asymptotic (`asym`): build ±z·stderr from covariance.
    - Monte Carlo (`mc`): direct lower/upper intervals.
- Plotting:
  - Central IRF curve, gradient shaded bands, style options.

### Quick start

```python
import pandas as pd
import matplotlib.pyplot as plt
from var_irf import compute_irf, plot_irf

# df is a DataFrame with multiple series columns and a time index
result = compute_irf(df, lags=2, horizon=7, stderr_type="asym", orth=False)

fig, ax = plt.subplots(figsize=(10, 8))
plot_irf(result, "Series1", "Series2", ax=ax, direction="single", band="shaded", layout="overlay", shaded=True)
ax.axhline(0, color='r', linestyle='dashdot', linewidth=0.5)
plt.show()
```

### API

- `compute_irf(df, lags=2, horizon=7, stderr_type='asym'|'mc', orth=False, cumulative=True, ...)`:
  Fit a VAR and return IRF arrays and error information.
- `plot_irf(result, impulse, response, ax=None, direction='single'|'bi', band='shaded'|'interval', layout='overlay'|'side-by-side', shaded=True, ...)`:
  Plot using the result from `compute_irf` with three orthogonal switches:
  - direction: single A→B or bidirectional.
  - band: shaded (gradient) or interval (errorbar-like); set `shaded=False` for line-only.
  - layout: overlay in one axes or side-by-side two subplots.
- `plot_irf_from_dataframe(...)`：
  直接从 DataFrame 计算并绘图。

### License

MIT


