general-equilibrium-model-builder
Build and solve Walrasian general equilibrium models with theory derivations and Julia computation
What this skill does
# General Equilibrium Model Builder
## Purpose
This skill helps economists build, analyze, and numerically solve **Walrasian General Equilibrium (GE)** models. It covers both the theoretical foundations (existence, uniqueness, welfare theorems) and computational implementation in Julia for finding equilibrium prices and allocations.
**Current Scope**: Pure exchange economies (no production). Future versions will extend to production economies, Arrow-Debreu with uncertainty, and dynamic models.
## When to Use
- **Theory Development**: Formalizing a pure exchange GE model for a paper
- **Teaching**: Creating examples for microeconomic theory courses
- **Computation**: Numerically solving for equilibrium prices and allocations
- **Welfare Analysis**: Evaluating Pareto efficiency and social welfare
- **Comparative Statics**: Analyzing how equilibrium changes with parameters
## Instructions
### Step 1: Understand the Economic Environment
Before generating any model, ask the user:
1. **Number of goods** ($L$): How many commodities in the economy?
2. **Number of consumers** ($I$): How many agents?
3. **Preferences**: What utility functions? (Cobb-Douglas, CES, Leontief, quasilinear)
4. **Endowments**: What is each agent's initial endowment vector?
5. **Output format**: Theory derivation, Julia code, or both?
### Step 2: Set Up the Theoretical Framework
A **pure exchange economy** $\mathcal{E}$ is characterized by:
$$\mathcal{E} = \left\{ (u^i, \omega^i)_{i=1}^{I} \right\}$$
where:
- $u^i: \mathbb{R}^L_+ \to \mathbb{R}$ is consumer $i$'s utility function
- $\omega^i \in \mathbb{R}^L_+$ is consumer $i$'s endowment vector
- $L$ is the number of goods
- $I$ is the number of consumers
**Consumer's Problem**: Given prices $p \in \mathbb{R}^L_{++}$, consumer $i$ solves:
$$\max_{x^i \in \mathbb{R}^L_+} u^i(x^i) \quad \text{s.t.} \quad p \cdot x^i \leq p \cdot \omega^i$$
The solution yields the **Marshallian demand** $x^i(p, p \cdot \omega^i)$.
### Step 3: Define Walrasian Equilibrium
**Definition (Walrasian Equilibrium)**: An allocation $(x^{*1}, \ldots, x^{*I})$ and price vector $p^* \in \mathbb{R}^L_{++}$ constitute a Walrasian equilibrium if:
1. **Utility Maximization**: For each $i$, $x^{*i}$ solves consumer $i$'s problem at prices $p^*$
2. **Market Clearing**: $\sum_{i=1}^{I} x^{*i} = \sum_{i=1}^{I} \omega^i$
Equivalently, the **excess demand function** $z(p) = \sum_{i=1}^{I} [x^i(p) - \omega^i]$ satisfies $z(p^*) = 0$.
### Step 4: State Key Theoretical Results
Include the following theorems as appropriate:
**Theorem (Walras' Law)**: For any price vector $p$:
$$p \cdot z(p) = 0$$
*Interpretation*: The value of excess demand is always zero (budget constraints bind).
**Theorem (First Welfare Theorem)**: Every Walrasian equilibrium allocation is Pareto efficient.
**Theorem (Second Welfare Theorem)**: Under convexity assumptions, any Pareto efficient allocation can be supported as a Walrasian equilibrium with appropriate lump-sum transfers.
**Theorem (Existence - Debreu, 1959)**: Under standard assumptions (continuity, strict convexity, strict monotonicity of preferences, strictly positive endowments), a Walrasian equilibrium exists.
### Step 5: Generate Julia Code for Computation
Use Julia with the following structure:
```julia
# ============================================
# General Equilibrium Solver in Julia
# Pure Exchange Economy
# ============================================
using LinearAlgebra
using NLsolve
using Plots
# Define the economy structure
struct PureExchangeEconomy
n_goods::Int # Number of goods (L)
n_consumers::Int # Number of consumers (I)
endowments::Matrix{Float64} # I × L matrix of endowments
utility_params::Vector{Any} # Parameters for utility functions
utility_type::Symbol # :cobb_douglas, :ces, :leontief
end
# Cobb-Douglas utility: u(x) = ∏ x_l^α_l
function utility_cobb_douglas(x, α)
return prod(x .^ α)
end
# Marshallian demand for Cobb-Douglas preferences
function demand_cobb_douglas(p, wealth, α)
# x_l = (α_l / sum(α)) * (wealth / p_l)
α_normalized = α / sum(α)
return α_normalized .* wealth ./ p
end
# Excess demand function
function excess_demand(p, economy::PureExchangeEconomy)
z = zeros(economy.n_goods)
for i in 1:economy.n_consumers
ω_i = economy.endowments[i, :]
wealth_i = dot(p, ω_i)
if economy.utility_type == :cobb_douglas
α_i = economy.utility_params[i]
x_i = demand_cobb_douglas(p, wealth_i, α_i)
else
error("Unsupported utility_type: $(economy.utility_type). Only :cobb_douglas is currently implemented.")
end
z += x_i - ω_i
end
return z
end
# Solve for equilibrium prices (normalize p_1 = 1)
# Uses log-price parameterization to ensure prices remain strictly positive
function solve_equilibrium(economy::PureExchangeEconomy)
# Initial guess in log-space (log of ones = zeros)
p0 = zeros(economy.n_goods - 1)
# Excess demand for goods 2 to L (Walras' Law implies good 1 clears)
# Reparameterize using log-prices: x = log(p_rest), so p_rest = exp(x)
function excess_demand_reduced!(F, x)
p_rest = exp.(x) # Exponentiate to get positive prices
p = vcat(1.0, p_rest) # Numeraire p_1 = 1
z = excess_demand(p, economy)
F .= z[2:end]
end
# Solve z(p) = 0 in log-space
result = nlsolve(excess_demand_reduced!, p0, autodiff=:forward)
if converged(result)
p_rest_star = exp.(result.zero) # Convert back from log-space
p_star = vcat(1.0, p_rest_star)
return p_star
else
error("Equilibrium solver did not converge")
end
end
# Compute equilibrium allocations
function equilibrium_allocations(p_star, economy::PureExchangeEconomy)
allocations = zeros(economy.n_consumers, economy.n_goods)
for i in 1:economy.n_consumers
ω_i = economy.endowments[i, :]
wealth_i = dot(p_star, ω_i)
if economy.utility_type == :cobb_douglas
α_i = economy.utility_params[i]
allocations[i, :] = demand_cobb_douglas(p_star, wealth_i, α_i)
else
throw(ArgumentError("Unsupported utility_type: $(economy.utility_type) in equilibrium_allocations. Only :cobb_douglas is currently implemented."))
end
end
return allocations
end
# Check Pareto efficiency via MRS equality
function check_pareto_efficiency(allocations, economy::PureExchangeEconomy)
# Currently only supports 2-good economies
if economy.n_goods != 2
throw(ArgumentError("check_pareto_efficiency currently only supports 2-good economies. Got economy.n_goods = $(economy.n_goods)."))
end
if economy.utility_type == :cobb_douglas
# MRS_{12} = (α_1/α_2) * (x_2/x_1) should be equal for all consumers
epsilon = 1e-12 # Small threshold for near-zero detection
mrs_values = []
for i in 1:economy.n_consumers
α_i = economy.utility_params[i]
x_i = allocations[i, :]
# Guard against division by zero: check both x_i[1] and α_i[2]
if abs(x_i[1]) < epsilon || abs(α_i[2]) < epsilon
# Handle corner case: set sentinel value for zero/near-zero consumption
push!(mrs_values, Inf)
else
mrs_i = (α_i[1] / α_i[2]) * (x_i[2] / x_i[1])
push!(mrs_values, mrs_i)
end
end
return mrs_values
else
throw(ArgumentError("Unsupported utility type: $(economy.utility_type) in check_pareto_efficiency. Only :cobb_douglas is currently implemented."))
end
end
```
### Step 6: Provide Complete Example
```julia
# ============================================
# Example: 2×2 Pure Exchange Economy
# ============================================
# Two consumers, two goods
# ConsuRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.