Interactive Macroeconomic Growth Engine: Dynamic Equilibria & Crises in WebAssembly
financial engineering

Interactive Macroeconomic Growth Engine: Dynamic Equilibria & Crises in WebAssembly

banner

Simulating Structural Macroeconomics Client-Side


Understanding how long-run economic anchors interact with short-run macroeconomic shocks is one of the most critical challenges in quantitative economics and strategic planning. Whether assessing fiscal impulses, productivity surges, or sudden capital flight, policy makers and financial analysts require models capable of capturing feedback loops across real and nominal sectors.

To explore these dynamics interactively, this project implements a complete, multi-tiered structural macroeconomic framework compiled into WebAssembly via Pyodide. By relying strictly on the Python standard library for the core mathematical engine and native HTML5 Canvas for real-time visualization, the simulation runs with zero external runtime dependencies directly within your browser.


Interactive Growth Macro Dashboard

Interactive Growth Macroeconomic Simulator
Full Screen Mode

Tip: You can follow the guided historical tours by clicking Start Tour or selecting any storyline at the top (US Tech Boom, Japan’s Lost Decade, Fiscal Deficit, or Tequila Crisis). Use the timeline scrubber at the bottom of the central chart to step through each period (\(t=1\) to \(t=20\)). For full-screen exploration, click the Full Screen Mode link in the dashboard header.



Theoretical Architecture & Model Ontology


The macroeconomic engine is structured around a six-level hierarchy that links micro-founded factor inputs with open-economy exchange rate dynamics and monetary policy:

1. Exogenous Inputs & Structural Parameters

The foundational layer establishes the structural properties of the economy:

  • Factor Shares: Capital share \(\alpha\), human capital share \(\beta\), and labor share \(\gamma\).
  • Growth Drivers: Technological discovery rate \(e_A\) and labor growth \(e_L\).
  • Policy Levers: Inflation target \(\pi^*\), monetary growth \(f_{p’}\), and investment share \(v\).

2. Long-Run Steady-State Anchors

The real economy is fundamentally anchored by physical capital accumulation and potential output trajectories:

  • Potential Output (\(y_s\)): Determined by the Solow-Swan steady-state capital stock.
  • Equilibrium Marginal Product of Capital (\(\rho^*\)): The long-run anchor for returns to capital.
  • NFA-Stabilizing Real Exchange Rate (\(\epsilon^*\)): The real exchange rate required to generate net exports (\(nx\)) to stabilize external debt/assets.

3. Factor Prices, Marginal Products & Taylor Rule

Factor prices are determined strictly by their real marginal productivities:

  • Marginal Product of Capital (\(\rho\)) and Real Wages (\(w\)): Derived from instantaneous capital and labor allocations.
  • Monetary Policy Rule: A Taylor rule adjusting nominal rates \(i\) based on deviations of inflation \(\pi\) from target \(\pi^*\) and the output gap \((y - y_s)/y_s\).
  • Zero Lower Bound (ZLB): Enforced as a strict non-negativity constraint (\(i \ge 0\)).

4. Money Demand, Liquidity & Seigniorage

The nominal economy balances liquidity preferences against price pressures:

  • Liquidity Preference (\(L(i)\)): Fraction of income held as money balances, inversely related to the nominal rate.
  • Seigniorage (\(S\)): Real purchasing power extracted by the government through currency expansion.
  • Boundary Guardrails: Detection of hyperinflationary feedback when real money demand collapses.

5. Aggregate Demand, IS Curve & Fiscal Multipliers

Short-run output deviations are governed by Keynesian aggregate demand:

  • Goods Market Equilibrium: Consumption (\(C\)), private investment (\(I\)), government spending (\(G\)), and net exports (\(NX\)).
  • IS Dynamics: Output growth deviations driven by the gap between the real interest rate and equilibrium capital returns.

6. International Adjustment & Exchange Rate Parity

Cross-border financial flows enforce open-economy arbitrage:

  • Uncovered Interest Rate Parity (UIP): Determines nominal exchange rate parity (\(e_{E}^h\)).
  • Real Exchange Rate Parity (\(e_{\epsilon}^h\)): Drives real terms-of-trade adjustments and risk premia during external shocks.


Historical Scenarios Explored


The dashboard comes pre-programmed with four interactive narratives demonstrating fundamental macroeconomic transitions:

  1. The US Tech Boom (Supply-Side Expansion):
    A persistent positive technology shock (\(e_A \uparrow\)) expands potential output (\(y_s\)). Increased productivity expands the economy without igniting inflation, leading to higher real wages and investment.
  2. Japan’s Lost Decade (Stagnation & ZLB):
    A collapse in productivity and investment demand pushes the natural rate into negative territory. Even as the central bank slashes interest rates to the Zero Lower Bound (\(i = 0%\)), demand remains depressed, highlighting liquidity trap dynamics.
  3. Fiscal Deficit & Crowding Out:
    A large unfinanced expansion in government spending (\(G \uparrow\)) boosts short-run output above potential, sparking demand-pull inflation. The monetary authority responds with rate hikes, which crowd out private investment and debt-to-GDP ratios spike.
  4. Tequila Crisis (Sudden Stop & Capital Outflow):
    Simulates rapid capital flight and sudden cessation of foreign financing. The exchange rate depreciates sharply, requiring emergency policy rate spikes to defend the currency at the cost of a severe contraction in output.


Zero-Dependency Client-Side Engineering


A core design objective of this project was achieving high computational performance with zero infrastructure overhead:

  • Pure Python Simulation: The simulation engine (core/engine.py) strictly relies on Python standard libraries (math, dataclasses, json). Because no heavy binary extensions (like NumPy or SciPy) are required, the Pyodide WebAssembly runtime initializes almost instantaneously in milliseconds.
  • Native HTML5 Canvas: Real-time phase diagrams, IS-LM curves, and time-series plots are rendered using native 2D Canvas contexts with sub-millisecond redraw cycles during timeline scrubbing.
  • Seamless Hugo Portability: The entire application is hosted statically under Hugo’s static/ asset directory, allowing version-controlled updates from the development environment to the live site.