In this simulation, countries act as nodes in a network. When a critical node is blocked, the shock propagates. The most striking finding is the "reactive stock" effect: a country like France might have zero direct imports from the affected region, yet its reserves plummet because other nations scramble to increase their safety stocks, driving up global prices and accelerating stockouts across the board.
To replicate this kind of systemic analysis or build a similar visualization, you need a prompt that can handle complex network theory and translate numerical data into a functional frontend. Since the original tool was built using a Flask backend and a JS frontend (roughly 600 lines of code), I've engineered a prompt to help anyone build a similar "Shock Propagation" dashboard from scratch.
If you are trying to build a tool that maps how a failure in one node affects a global network, use this prompt structure. It forces the LLM to focus on the mathematical relationship between nodes rather than just making a pretty map.
Act as a Full-Stack Engineer and Data Scientist. I need to build a network visualization tool that simulates shock propagation across a bilateral trade network (based on the Eisenberg-Noe framework).
**Technical Requirements:**
1. Backend: Python Flask.
2. Frontend: JavaScript with D3.js or Cytoscape.js for network graphing.
3. Logic:
- Implement a node-link structure where nodes are countries and edges are trade volumes.
- Create a function `calculate_depletion(blocked_nodes, time_step)` that calculates how the removal of a node increases the "cost" or "depletion rate" of remaining nodes based on a safety-stock multiplier.
- Price dynamics must be sequential: Price increases only after a specific threshold of total network reserves is depleted.
**Data Structure:**
Use a JSON format for the trade matrix:
`{"source": "Country A", "target": "Country B", "volume": 100, "reserves": 500}`
**Deliverables:**
- A complete `app.py` for the Flask server.
- An `index.html` with the JS logic to render the network and animate the "shock" (changing node colors from green to red as reserves deplete).
- A specific function to handle the recursive propagation of the shock through the network.
Implementation Details & Logic
To make this work in a real-world scenario, the logic must move beyond simple subtraction. The "hidden" value in this model is the price dynamic. Here is how the backend should actually handle the state change to match the research:
Direct Shock: IfNode_Hormuz
is blocked, all edges connected to it are set tovolume = 0
.Indirect Shock: For all other nodes, the depletion rate becomes:
Current_Depletion = Base_Consumption + (Global_Shortfall * Panic_Coefficient)
.Price Trigger: The price doesn't spike instantly. It follows a step function:
If Total_Network_Reserves < Threshold_X, then Price = Price * 1.5
.For those implementing this, avoid using heavy libraries for the graph if you have more than 100 nodes; D3.js force-directed graphs can lag on mobile. Stick to a Canvas-based renderer if you're visualizing the entire UN Comtrade dataset.
The result of using the prompt above is a functional prototype where you can manually toggle "blockages" on a map and watch the reserve levels of non-connected countries drop in real-time, providing a practical tutorial on how systemic risk actually functions in global supply chains.
https://arxiv.org/abs/2607.17491
Next Preventing Duplicate Charges: My Idempotency Workflow →