Supplier Risk Radar: multi-regional supplier-risk analytics on CEPAL LAC-IOT 2011#1
Open
IMAbril wants to merge 6 commits into
Open
Supplier Risk Radar: multi-regional supplier-risk analytics on CEPAL LAC-IOT 2011#1IMAbril wants to merge 6 commits into
IMAbril wants to merge 6 commits into
Conversation
- config.py: bilingual (EN/ES) taxonomy of the 18 LAC countries and 40 sectors taken verbatim from the workbook Metadata sheet; focal-firm defaults (BRA, s30 Motor vehicles) and composite-score weights. - linalg.py: from-scratch LU with partial pivoting, vectorized elimination, hand-written forward/back substitution (no scipy/numpy solvers), matrix inverse and power method. Core algorithms reused from the group project "Grupo 10 - Algebra Lineal Computacional 2C 2024" (Abril Magali Ibarra, Santiago Roda), credited in the header. - io_model.py: loads LAC_IOT_2011, assembles the 720x720 multi-regional Z, technical coefficients A = Z diag(1/x) (with guards for negative statistical adjustments and effectively-zero outputs) and the Leontief inverse via the from-scratch engine; npz/json cache for fast startup. - scripts/build_cache.py validates the inverse against numpy (~4e-15) and checks productivity via spectral radius (0.56 < 1). - 24 tests passing (LU/inverse/power method vs numpy; pipeline sanity). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XaPtC5UKsvkXWiZcPuSyPR
- upstream_exposure: Leontief-inverse column of the focal industry split into direct / hidden higher-order requirements, with country/sector aggregations and a country x sector pivot for heatmaps. - hhi + concentration_summary: Herfindahl concentration of the upstream dependency by country, sector and individual supplier. - rasmussen_indices (backward/forward linkages, key-sector flag) and spectral_centrality via the from-scratch power method on A^T, validated against numpy eigendecomposition. - composite_risk_score: transparent weighted 0-100 blend of exposure, within-sector concentration, criticality and a country-risk proxy; criticality/country terms are relevance-gated by exposure so systemic hubs the firm does not buy from cannot top its supplier ranking. - 14 tests passing (bounds, scale-invariance, plausibility of the BRA motor-vehicles chain, weight sensitivity, zero-exposure gating). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XaPtC5UKsvkXWiZcPuSyPR
- demand_shock: multi-regional generalization of the TP's variacion_demanda/variacion_produccion_* — recovers final demand from d = (I-A)x and propagates dx = (I-A)^-1 dd across all 720 industries. - cost_shock: dual Leontief price model dp = (I-A^T)^-1 dv for unit-cost increases, solved with the from-scratch LU engine; focal_cost_impact helper reads the focal industry's cost pass-through. - supply_disruption: converts a capacity loss in one supplier industry into focal dependency, exposure-at-risk and economy-wide output at risk. - diversify: re-sources a fraction of the focal firm's direct input of a sector across alternative countries, rebuilds the Leontief inverse and reports before/after HHI and country exposure (input intensity kept). - 11 tests passing (linearity, additivity, cross-country propagation, cost pass-through bounds, HHI reduction, column-sum preservation). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XaPtC5UKsvkXWiZcPuSyPR
Five views over the cached 720x720 Leontief model: - Exposure map: KPI row (country/sector HHI, top-supplier and foreign shares), stacked direct-vs-hidden requirements of the top suppliers, and a country x sector heatmap of upstream exposure shares. - Criticality: Rasmussen backward/forward quadrant with the focal firm's top-20 suppliers emphasized against a de-emphasized field. - Disruption scenarios: cost (price model) or demand (quantity model) shocks with focal impact headline and most-impacted industries. - Diversification: re-source an input sector across countries and compare before/after HHI and country exposure (inverse rebuilt live). - Risk score: weight sliders and top-25 composite ranking with table. Full ES/EN toggle; single-accent palette with sequential blue ramp (validated with the dataviz palette checker); hover tooltips and table views on every chart. Verified headless via Playwright: all five tabs render without page errors in both languages. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XaPtC5UKsvkXWiZcPuSyPR
Narrative report answering the business questions end to end: model construction, upstream exposure map (46% of the focal firm's upstream pull is hidden higher-order requirements; Argentina is the top foreign dependency), concentration (country HHI 0.90) and Rasmussen/centrality criticality, disruption scenarios (+30% BRA steel cost -> +2.6% focal unit cost, two orders of magnitude above the same shock elsewhere; +10% demand -> 1.76 output multiplier), diversification (re-sourcing half of steel to ARG/MEX cuts country HHI 0.90 -> 0.80) and the composite supplier risk score. All cells executed, outputs committed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XaPtC5UKsvkXWiZcPuSyPR
- README.md: full EN/ES project description, quick start, layout and an authorship section crediting the group project "Grupo 10 - Algebra Lineal Computacional 2C 2024" (Abril Magali Ibarra, Santiago Roda) as the origin of the linear-algebra engine, and CEPAL/ECLAC as the data source. - docs/metodologia.md: bilingual methodology — data cleaning decisions, Leontief model and productivity condition (spectral radius 0.56), from-scratch engine provenance and validation, risk-metric formulas, scenario engine, limitations and reproducibility. - LICENSE: MIT with the engine-provenance and data-source notice. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XaPtC5UKsvkXWiZcPuSyPR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supplier Risk Radar
EN — Complete portfolio data product: supplier / supply-chain risk analytics for a focal firm (default: a Brazilian motor-vehicle manufacturer), quantifying its hidden upstream exposure across 18 LAC countries × 40 sectors using the CEPAL LAC-IOT 2011 input-output table and a from-scratch linear-algebra engine.
ES — Producto de datos completo: analítica de riesgo de proveedores / cadena de suministro para una empresa focal (por defecto, una automotriz brasileña), cuantificando su exposición upstream oculta a través de 18 países de ALC × 40 sectores con la matriz insumo-producto CEPAL LAC-IOT 2011 y un motor de álgebra lineal hecho desde cero.
What's included / Contenido
src/supplier_risk/linalg.py— from-scratch LU with partial pivoting (vectorized elimination), hand-written forward/back substitution (nonumpy.linalg.inv/solve, noscipy), matrix inverse and power method. Validated against numpy to ~4·10⁻¹⁵ at 720×720.src/supplier_risk/io_model.py— CEPAL workbook → 720×720 multi-regional Z, technical coefficients A = Z·diag(1/x), Leontief inverse, npz/json cache. Documented data-cleaning guards (negative statistical adjustments, effectively-zero outputs); productivity validated via spectral radius (0.56 < 1).src/supplier_risk/risk.py— upstream exposure (direct vs hidden), HHI concentration, Rasmussen backward/forward linkages, spectral centrality, composite 0–100 supplier risk score with exposure-gated systemic terms.src/supplier_risk/scenarios.py— demand shocks (Δx = (I−A)⁻¹Δd), dual Leontief price model for cost shocks (Δp = (I−Aᵀ)⁻¹Δv), supply disruption, diversification with inverse rebuild.app/dashboard.py— bilingual (EN/ES) Streamlit dashboard: exposure map, criticality quadrant, disruption simulator, diversification, risk-score explorer.notebooks/case_study.ipynb— executed bilingual case study. Headline findings: 46% of upstream pull is hidden; country HHI 0.90; +30% BRA steel cost → +2.6% focal unit cost; re-sourcing half of steel to ARG/MEX cuts HHI to 0.80.docs/metodologia.md, bilingual README, MIT LICENSE.Validation / Validación
pytest -q): engine vs numpy, PA=LU reconstruction, pipeline sanity, metric bounds, scenario linearity/additivity, economic plausibility of the BRA auto chain.scripts/build_cache.pyvalidates the from-scratch Leontief inverse againstnumpy.linalg.invon every build.Authorship / Autoría
The linear-algebra engine is adapted from the group academic project “Grupo 10 — Álgebra Lineal Computacional 2C 2024” (Abril Magali Ibarra, Santiago Roda), originally
calcularLU/inversaLU/metodoPotenciain imabril/matrices_insumo-producto. Data: CEPAL/ECLAC LAC-IOT 2011.🤖 Generated with Claude Code
https://claude.ai/code/session_01XaPtC5UKsvkXWiZcPuSyPR
Generated by Claude Code