{"id":29677579,"url":"https://github.com/chirindaopensource/non_linear_forecasting_backcasting","last_synced_at":"2026-04-11T09:43:22.236Z","repository":{"id":305171827,"uuid":"1022142212","full_name":"chirindaopensource/non_linear_forecasting_backcasting","owner":"chirindaopensource","description":"Python implementation of Gourieroux-Jasiak's (2025) mixed causal-noncausal VAR models. Features probabilistic forecasting, nonlinear innovation filtering, and state-dependent IRF analysis for financial time series with explosive dynamics. Enables robust risk assessment and structural analysis of speculative behavior.","archived":false,"fork":false,"pushed_at":"2025-07-18T16:23:29.000Z","size":91,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-11T09:42:50.588Z","etag":null,"topics":["bootstrap","bubble-analysis","financial-modeling","forecasting","jupyter-notebook","monte-carlo","nonlinear-modeling","numpy","pandas","python","quantitative-finance","research-implementation","risk-management","scipy","statistical-modeling","time-series","uncertainty-quantification","var-models"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chirindaopensource.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-18T14:22:54.000Z","updated_at":"2025-07-18T16:23:32.000Z","dependencies_parsed_at":"2025-07-21T23:00:28.481Z","dependency_job_id":null,"html_url":"https://github.com/chirindaopensource/non_linear_forecasting_backcasting","commit_stats":null,"previous_names":["chirindaopensource/non_linear_forecasting_backcasting"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chirindaopensource/non_linear_forecasting_backcasting","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chirindaopensource%2Fnon_linear_forecasting_backcasting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chirindaopensource%2Fnon_linear_forecasting_backcasting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chirindaopensource%2Fnon_linear_forecasting_backcasting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chirindaopensource%2Fnon_linear_forecasting_backcasting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chirindaopensource","download_url":"https://codeload.github.com/chirindaopensource/non_linear_forecasting_backcasting/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chirindaopensource%2Fnon_linear_forecasting_backcasting/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31676210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-11T08:18:19.405Z","status":"ssl_error","status_checked_at":"2026-04-11T08:17:08.892Z","response_time":54,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bootstrap","bubble-analysis","financial-modeling","forecasting","jupyter-notebook","monte-carlo","nonlinear-modeling","numpy","pandas","python","quantitative-finance","research-implementation","risk-management","scipy","statistical-modeling","time-series","uncertainty-quantification","var-models"],"created_at":"2025-07-23T01:00:54.264Z","updated_at":"2026-04-11T09:43:22.220Z","avatar_url":"https://github.com/chirindaopensource.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `README.md`\n\n# *Nonlinear Fore(Back)casting and Innovation Filtering for Causal-Noncausal VAR Models* Implementation\n\u003cbr\u003e\n\n\u003c!-- PROJECT SHIELDS --\u003e\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Python Version](https://img.shields.io/badge/python-3.9%2B-blue.svg)](https://www.python.org/downloads/)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Imports: isort](https://img.shields.io/badge/imports-isort-1674b1?style=flat\u0026labelColor=ef8336)](https://pycqa.github.io/isort/)\n[![Type Checking: mypy](https://img.shields.io/badge/type_checking-mypy-blue.svg)](http://mypy-lang.org/)\n[![Jupyter](https://img.shields.io/badge/Jupyter-%23F37626.svg?style=flat\u0026logo=Jupyter\u0026logoColor=white)](https://jupyter.org/)\n[![Pandas](https://img.shields.io/badge/pandas-%23150458.svg?style=flat\u0026logo=pandas\u0026logoColor=white)](https://pandas.pydata.org/)\n[![NumPy](https://img.shields.io/badge/numpy-%23013243.svg?style=flat\u0026logo=numpy\u0026logoColor=white)](https://numpy.org/)\n[![SciPy](https://img.shields.io/badge/SciPy-%230C55A5.svg?style=flat\u0026logo=scipy\u0026logoColor=white)](https://scipy.org/)\n[![Matplotlib](https://img.shields.io/badge/Matplotlib-%23ffffff.svg?style=flat\u0026logo=Matplotlib\u0026logoColor=black)](https://matplotlib.org/)\n[![Joblib](https://img.shields.io/badge/Joblib-darkgreen.svg?style=flat\u0026logo=python\u0026logoColor=white)](https://joblib.readthedocs.io/)\n[![Statsmodels](https://img.shields.io/badge/Statsmodels-blue.svg?style=flat\u0026logo=python\u0026logoColor=white)](https://www.statsmodels.org/)\n[![arXiv](https://img.shields.io/badge/arXiv-2205.09922-b31b1b.svg)](https://arxiv.org/abs/2205.09922)\n[![Research](https://img.shields.io/badge/Research-Quantitative%20Finance-green)](https://github.com/chirindaopensource/non_linear_forecasting_backcasting)\n[![Discipline](https://img.shields.io/badge/Discipline-Econometrics-blue)](https://github.com/chirindaopensource/non_linear_forecasting_backcasting)\n[![Methodology](https://img.shields.io/badge/Methodology-Noncausal%20Time%20Series-orange)](https://github.com/chirindaopensource/non_linear_forecasting_backcasting)\n[![Year](https://img.shields.io/badge/Year-2025-purple)](https://github.com/chirindaopensource/non_linear_forecasting_backcasting)\n\u003cbr\u003e\n\n**Repository:** https://github.com/chirindaopensource/non_linear_forecasting_backcasting\n\n**Owner:** 2025 Craig Chirinda (Open Source Projects)\n\nThis repository contains an **independent**, professional-grade Python implementation of the research methodology from the 2025 paper entitled **\"Nonlinear Fore(Back)casting and Innovation Filtering for Causal-Noncausal VAR Models\"** by:\n\n*   Christian Gourieroux\n*   Joann Jasiak\n\nThe project provides a complete, computationally tractable system for the quantitative analysis of dynamic systems prone to speculative bubbles and other forms of locally explosive behavior. It enables robust, state-dependent risk assessment, probabilistic forecasting, and structural \"what-if\" scenario analysis that accounts for both nonlinear dynamics and model estimation uncertainty.\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Theoretical Background](#theoretical-background)\n- [Features](#features)\n- [Methodology Implemented](#methodology-implemented)\n- [Core Components (Notebook Structure)](#core-components-notebook-structure)\n- [Key Callable: run_full_research_pipeline](#key-callable-run_full_research_pipeline)\n- [Prerequisites](#prerequisites)\n- [Installation](#installation)\n- [Input Data Structure](#input-data-structure)\n- [Usage](#usage)\n- [Output Structure](#output-structure)\n- [Project Structure](#project-structure)\n- [Customization](#customization)\n- [Contributing](#contributing)\n- [License](#license)\n- [Citation](#citation)\n- [Acknowledgments](#acknowledgments)\n\n## Introduction\n\nThis project provides a Python implementation of the advanced econometric framework presented in Gourieroux and Jasiak (2025). The core of this repository is the iPython Notebook `non_linear_forecasting_backcasting_draft.ipynb`, which contains a comprehensive suite of functions to estimate, forecast, and analyze mixed causal-noncausal Vector Autoregressive (VAR) models.\n\nStandard linear VAR models are purely causal and assume Gaussian errors, making them ill-suited for capturing the dynamics of financial and economic time series that exhibit bubbles, sudden crashes, or other forms of explosive behavior. The mixed causal-noncausal framework addresses this by allowing for roots of the VAR characteristic polynomial to lie both inside and outside the unit circle, generating a strictly stationary process with highly nonlinear, state-dependent dynamics.\n\nThis codebase enables researchers, quantitative analysts, and macroeconomists to:\n-   Rigorously estimate mixed VAR models using the semi-parametric Generalized Covariance (GCov) method.\n-   Generate full, non-Gaussian predictive densities for probabilistic forecasting.\n-   Quantify estimation uncertainty using a novel backward-bootstrap procedure to create confidence sets for prediction intervals.\n-   Filter the underlying nonlinear, structural innovations of the system.\n-   Conduct state-dependent Impulse Response Function (IRF) analysis to understand how the system responds to shocks in \"on-bubble\" versus \"off-bubble\" states.\n\n## Theoretical Background\n\nThe methodology implemented in this project is a direct translation of the unified framework presented in the source paper. It leverages the state-space representation of a VAR(p) process to separate its dynamics into stable (causal) and unstable (non-causal) components.\n\n### 1. The Mixed Causal-Noncausal VAR Model\n\nThe model is defined by the standard VAR(p) equation, but with a critical difference in its assumptions:\n$Y_t = \\Phi_1 Y_{t-1} + \\dots + \\Phi_p Y_{t-p} + \\epsilon_t$\nThe roots of the characteristic polynomial `det(I - \\sum \\Phi_i \\lambda^i) = 0` can be both inside (`causal`) and outside (`non-causal`) the unit circle. The errors `\\epsilon_t` are assumed to be i.i.d. and non-Gaussian.\n\n### 2. State-Space Decomposition and Predictive Density\n\nThe VAR(p) process is transformed into a VAR(1) in state-space using the companion matrix `\\Psi`. A **Jordan Decomposition** (`\\Psi = A J A^{-1}`) separates the system into latent causal (`Z_1`) and non-causal (`Z_2`) states. This separation is the key to the paper's central theoretical result: a closed-form expression for the one-step-ahead predictive density, given in **Equation 3.1**:\n$l(y | Y_T) = \\frac{l_2(A^2 \\tilde{y}_{T+1})}{l_2(A^2 \\tilde{Y}_T)} |\\det J_2| g(y - \\sum \\Phi_i Y_{T-i+1})$\n- `g` is the density of the error `\\epsilon_t`.\n- `l_2` is the stationary density of the non-causal state `Z_2`.\nThis density is nonlinear and state-dependent, allowing it to capture complex dynamics.\n\n### 3. Uncertainty Quantification via Backward Bootstrap\n\nTo account for estimation uncertainty, the framework uses a novel \"backward bootstrap\" procedure. Since the model is Markovian in both forward and reverse time, one can generate synthetic data paths by **backcasting** from the terminal observation `Y_T`. By re-estimating the model on many such paths, the sampling distribution of the prediction interval is obtained, which is then used to construct a robust **Confidence Set for the Prediction Interval (CSPI)**, as defined in **Equation 4.10**.\n\n### 4. Nonlinear Innovation Filtering and State-Dependent IRFs\n\nStandard VAR shocks are not meaningful in this context. The paper defines true, past-independent structural innovations `v_t` via the **Probability Integral Transform (PIT)**. This involves estimating the conditional CDF of the latent states and transforming it to a standard normal distribution.\n**Equation 5.5:** $v_{2,t} = \\Phi^{-1}[F_2(Z_{2,t}|Z_{t-1})]$\nSimulating the model forward using the inverse of this transformation allows for the computation of **state-dependent Impulse Response Functions (IRFs)**, which show how the system's response to a shock `\\delta` changes depending on its initial state (e.g., during a bubble).\n\n## Features\n\nThe `non_linear_forecasting_backcasting_draft.ipynb` notebook implements the full research pipeline:\n\n-   **Robust Data Pipeline:** Validation, cleaning, and preparation of time series data.\n-   **Advanced Estimator:** A complete implementation of the semi-parametric GCov estimator for VAR parameters.\n-   **Probabilistic Forecasting:** Functions to compute the full predictive density, point forecasts (mode), and prediction intervals.\n-   **Advanced Uncertainty Quantification:** A parallelized implementation of the backward bootstrap with SIR sampling to generate confidence sets.\n-   **Structural Analysis:** Functions to filter nonlinear innovations and simulate state-dependent IRFs.\n-   **Model Validation:** A full simulation study framework to assess the finite-sample properties of the pipeline.\n-   **Sensitivity Analysis:** Tools to conduct robustness checks on key model parameters.\n-   **Integrated Visualization:** A dedicated class for generating all key publication-quality plots.\n\n## Methodology Implemented\n\nThe codebase is a direct, one-to-one implementation of the paper's methodology:\n1.  **Data Preparation (Tasks 1-2):** Ingests and prepares data as per the paper's empirical application.\n2.  **Estimation (Tasks 3-5):** Implements the GCov estimator, Jordan decomposition, and non-parametric density estimation.\n3.  **Forecasting (Tasks 6-8):** Implements the predictive density formula and extracts point and interval forecasts.\n4.  **Uncertainty (Task 9):** Implements the full backward bootstrap with SIR sampling to compute confidence sets.\n5.  **Structural Analysis (Tasks 10-11):** Implements the Nadaraya-Watson estimator for innovation filtering and the inverse for IRF simulation.\n6.  **Validation \u0026 Orchestration (Tasks 12-17):** Provides high-level orchestrators for empirical analysis, simulation studies, robustness checks, and comparative analysis.\n\n## Core Components (Notebook Structure)\n\nThe `non_linear_forecasting_backcasting_draft.ipynb` notebook is structured as a series of modular, professional-grade functions, each corresponding to a specific task in the pipeline. Key functions include:\n\n-   **`validate_and_cleanse_data`**: The initial data quality gate.\n-   **`prepare_var_data`**: Transforms data to be stationary and demeaned.\n-   **`estimate_gcov_var`**: The core GCov estimation engine.\n-   **`compute_jordan_decomposition`**: Separates causal/non-causal dynamics.\n-   **`estimate_functional_components`**: Fits the non-parametric KDEs.\n-   **`compute_predictive_density`**: The engine for probabilistic forecasting.\n-   **`compute_point_forecast` \u0026 `compute_prediction_interval`**: Extracts forecast products.\n-   **`compute_bootstrap_confidence_set`**: The advanced uncertainty quantification engine.\n-   **`filter_nonlinear_innovations`**: Extracts structural shocks.\n-   **`simulate_irf`**: Simulates state-dependent IRFs.\n-   **`run_empirical_analysis`**: Orchestrates a full analysis of a single dataset.\n-   **`run_full_research_pipeline`**: The single, top-level entry point to the entire project.\n\n## Key Callable: run_full_research_pipeline\n\nThe central function in this project is `run_full_research_pipeline`. It orchestrates the entire analytical workflow from raw data to a final, comprehensive results dictionary.\n\n```python\ndef run_full_research_pipeline(\n    raw_df: pd.DataFrame,\n    study_params: Dict[str, Any]\n) -\u003e Dict[str, Any]:\n    \"\"\"\n    Executes a complete, end-to-end research pipeline for the mixed\n    causal-noncausal VAR model.\n    ... (full docstring is in the notebook)\n    \"\"\"\n    # ... (implementation is in the notebook)\n```\n\n## Prerequisites\n\n-   Python 3.9+\n-   Core dependencies: `pandas`, `numpy`, `scipy`, `matplotlib`, `seaborn`, `statsmodels`, `joblib`.\n\n## Installation\n\n1.  **Clone the repository:**\n    ```sh\n    git clone https://github.com/chirindaopensource/non_linear_forecasting_backcasting.git\n    cd non_linear_forecasting_backcasting\n    ```\n\n2.  **Create and activate a virtual environment (recommended):**\n    ```sh\n    python -m venv venv\n    source venv/bin/activate  # On Windows, use `venv\\Scripts\\activate`\n    ```\n\n3.  **Install Python dependencies from `requirements.txt`:**\n    ```sh\n    pip install -r requirements.txt\n    ```\n\n## Input Data Structure\n\nThe primary input is a `pandas.DataFrame` with a monthly `DatetimeIndex` and two columns: `\"real_oil_price\"` and `\"real_gdp\"`.\n\n**Example:**\n```\n                     real_gdp  real_oil_price\n2019-04-30  18958.789123       63.870000\n2019-05-31  19002.256789       60.210000\n2019-06-30  19045.724455       57.430000\n...                  ...             ...\n```\n\n## Usage\n\nThe entire pipeline is executed through the `run_full_research_pipeline` function. The user must provide the raw data and a comprehensive `study_params` dictionary that controls which analyses are run.\n\n```python\nimport pandas as pd\nimport numpy as np\n\n# 1. Load your data\n# raw_data_df = pd.read_csv(...)\n# For this example, we create synthetic data.\ndate_rng = pd.date_range(start='1986-01-01', end='2019-06-30', freq='M')\n# ... (data generation code) ...\nraw_data_df = pd.DataFrame(...)\n\n# 2. Define your configurations (see notebook for full example)\nstudy_params = {\n    \"run_empirical\": {\"enabled\": True, ...},\n    \"run_simulation\": {\"enabled\": False, ...},\n    # ... other sections ...\n}\n\n# 3. Run the master pipeline\n# from non_linear_forecasting_backcasting_draft import run_full_research_pipeline\n# final_results = run_full_research_pipeline(\n#     raw_df=raw_data_df,\n#     study_params=study_params\n# )\n\n# 4. Instantiate the visualizer and plot results\n# from non_linear_forecasting_backcasting_draft import ModelVisualizer\n# visualizer = ModelVisualizer(final_results['empirical_analysis'])\n# visualizer.plot_diagnostics()\n# visualizer.plot_irf(irf_date=pd.Timestamp('2008-06-30'))\n```\n\n## Output Structure\n\nThe `run_full_research_pipeline` function returns a deeply nested dictionary containing all data artifacts. Top-level keys include:\n\n-   `pipeline_configuration`: A copy of the input `study_params`.\n-   `empirical_analysis`: Results from the core analysis on the provided data.\n-   `simulation_study`: A DataFrame summarizing the Monte Carlo results.\n-   `robustness_checks`: DataFrames detailing the sensitivity analysis.\n-   `comparative_analysis`: A dictionary with forecast and metric DataFrames from the horse race.\n\n## Project Structure\n\n```\nnon_linear_forecasting_backcasting/\n│\n├── non_linear_forecasting_backcasting_draft.ipynb  # Main implementation notebook\n├── requirements.txt                                # Python package dependencies\n├── LICENSE                                         # MIT license file\n└── README.md                                       # This documentation file\n```\n\n## Customization\n\nThe pipeline is highly customizable via the `study_params` dictionary. Users can easily modify:\n-   The control flags (`run_empirical`, etc.) to enable or disable parts of the analysis.\n-   The VAR lag order `p_lags`.\n-   The GCov moment specifications `H_moment_lags` and `error_powers`.\n-   All simulation parameters (`S_bootstrap_replications`, `n_baseline_sims`, etc.).\n-   The specific dates for targeted forecasting and IRF analysis.\n\n## Contributing\n\nContributions are welcome. Please fork the repository, create a feature branch, and submit a pull request with a clear description of your changes. Adherence to PEP 8, type hinting, and comprehensive docstrings is required.\n\n## License\n\nThis project is licensed under the MIT License. See the `LICENSE` file for details.\n\n## Citation\n\nIf you use this code or the methodology in your research, please cite the original paper:\n\n```bibtex\n@article{gourieroux2022nonlinear,\n  title={Nonlinear Fore(Back)casting and Innovation Filtering for Causal-Noncausal VAR Models},\n  author={Gourieroux, Christian and Jasiak, Joann},\n  journal={arXiv preprint arXiv:2205.09922},\n  year={2022}\n}\n```\n\nFor the implementation itself, you may cite this repository:\n```\nChirinda, C. (2025). A Python Implementation of the Gourieroux-Jasiak (2025) Framework for Causal-Noncausal VAR Models. \nGitHub repository: https://github.com/chirindaopensource/non_linear_forecasting_backcasting\n```\n\n## Acknowledgments\n\n-   Credit to Christian Gourieroux and Joann Jasiak for their foundational theoretical and empirical work.\n-   Thanks to the developers of the `pandas`, `numpy`, `scipy`, `matplotlib`, `statsmodels`, and `joblib` libraries, which provide the essential toolkit for this implementation.\n\n--\n\nThis README was generated based on the structure and content of non_linear_forecasting_backcasting_draft.ipynb and follows best practices for research software documentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchirindaopensource%2Fnon_linear_forecasting_backcasting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchirindaopensource%2Fnon_linear_forecasting_backcasting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchirindaopensource%2Fnon_linear_forecasting_backcasting/lists"}