Skip to content

thangasival/tepi_pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TEPI Pipeline

Reproducible pipeline for computing the Tariff Exposure Propagation Index (TEPI) across the 2025–2026 U.S. tariff shock and reversal.

This codebase backs the IEOM Milwaukee 2026 paper:

A Tariff Exposure Propagation Index for Measuring Hidden Supply-Chain Vulnerability: Evidence from the 2025–2026 U.S. Shock and Reversal

What it does

The pipeline pulls public data (Census trade, BEA input-output, FRED freight, NY Fed GSCPI, SEC EDGAR, USITC tariff schedules, and equity returns), constructs a three-regime tariff panel (baseline, IEEPA, post-reversal/Section 122), computes TEPI at the BEA detailed industry level, runs three independent validations, and emits paper-ready tables and figures.

Quick start

# 1. Install
pip install -e .

# 2. Configure API keys (free) in config/api_keys.yaml
#    - census_api_key:    https://api.census.gov/data/key_signup.html
#    - fred_api_key:      https://fred.stlouisfed.org/docs/api/api_key.html
#    - sec_user_agent:    "Your Name your.email@example.org"

# 3. Run the full pipeline
python -m tepi run-all

# Or run individual stages
python -m tepi ingest      # Pull all raw data
python -m tepi transform   # Build crosswalk + 3-regime panel
python -m tepi index       # Compute TEPI
python -m tepi validate    # Run CAR / IP / 10-K validations
python -m tepi tables      # Build paper-ready tables and figures

Census ingest (large download)

The Census stage fetches ~4 365 API requests (45 months × 97 HS chapters). Run it separately with higher concurrency to finish in minutes instead of hours:

# Recommended: 25 concurrent requests — completes the full window in ~6 minutes
python -m tepi ingest-census --concurrency 25

# Fetch one year at a time (useful if the API is flaky)
python -m tepi ingest-census --year 2024 --concurrency 25

# Fetch a single month
python -m tepi ingest-census --year 2024 --month 6 --concurrency 25

# Re-fetch a month that came back empty or errored
python -m tepi ingest-census --year 2024 --month 6 --force --concurrency 25

Each completed month is saved as a checkpoint file under data/raw/census_imports/months/. If a run is interrupted, restarting picks up from where it left off — already-fetched months are skipped automatically.

Once Census is complete, run the remaining ingest stages (FRED, GSCPI, BEA):

python -m tepi ingest

Census will immediately skip because all checkpoints exist; FRED, GSCPI, and BEA then run normally.

All runs write a timestamped log file to logs/tepi_YYYYMMDD_HHMMSS.log in addition to console output. Use --log-dir to change the location.

Pipeline stages

  1. ingest — Pull HS-10 trade data (Census), tariff schedules (USITC + Federal Register), I-O tables (BEA), freight indices (FRED), GSCPI (NY Fed), 10-K filings (SEC EDGAR), and equity returns (yfinance).
  2. transform — Build HS→NAICS→BEA crosswalk, construct three-regime tariff panel, residualize controls.
  3. index — Compute D_it (direct), P_it (propagated), ρ_i (snapback), TEPI_it (composite).
  4. validate — Three independent tests: equity CARs around Feb 20 2026 ruling, industrial production response during IEEPA period, 10-K text exposure scoring. Plus services-sector falsification check.
  5. tables — Generate Tables 1–5 and Figures 1–4 in paper-ready formats (CSV, LaTeX, PNG, PDF).

Reproducibility

Every stage is idempotent and writes to data/processed/ with a manifest including data vintages, parameter values, and a content hash. Re-running without changes is a no-op. Re-running after upstream data revisions re-computes only the affected downstream stages.

Testing

pytest                    # Unit tests with mock data
pytest --integration      # Integration tests (needs API keys)

License

Code: MIT. Outputs (TEPI panel, crosswalk, replication bundle): CC-BY 4.0.

Releases

No releases published

Packages

 
 
 

Contributors