general-equilibrium-model-builder

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

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.
本技能可帮助经济学家构建、分析并数值求解 Walrasian General Equilibrium (GE,瓦尔拉斯一般均衡) 模型,既涵盖理论基础(存在性、唯一性、福利定理),也包含基于Julia的计算实现方案,用于求解均衡价格和资源分配。
当前适用范围:纯交换经济(无生产环节)。未来版本将扩展至生产经济、带不确定性的Arrow-Debreu模型以及动态模型。

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

步骤1:明确经济环境参数

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?
生成模型前,需要向用户确认以下信息:
  1. 商品数量 ($L$):经济系统中共有多少种商品?
  2. 消费者数量 ($I$):经济系统中共有多少个主体?
  3. 偏好设置:采用什么效用函数?(Cobb-Douglas、CES、Leontief、拟线性)
  4. 禀赋设置:每个主体的初始禀赋向量是多少?
  5. 输出格式:仅输出理论推导、仅输出Julia代码,还是两者都输出?

Step 2: Set Up the Theoretical Framework

步骤2:搭建理论框架

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)$.
纯交换经济 $\mathcal{E}$ 的定义为:
$$\mathcal{E} = \left{ (u^i, \omega^i)_{i=1}^{I} \right}$$
其中:
  • $u^i: \mathbb{R}^L_+ \to \mathbb{R}$ 是消费者$i$的效用函数
  • $\omega^i \in \mathbb{R}^L_+$ 是消费者$i$的禀赋向量
  • $L$ 是商品数量
  • $I$ 是消费者数量
消费者问题:给定价格 $p \in \mathbb{R}^L_{++}$,消费者$i$的最优决策问题为:
$$\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$$
求解该问题可得到马歇尔需求 $x^i(p, p \cdot \omega^i)$。

Step 3: Define Walrasian Equilibrium

步骤3:定义瓦尔拉斯均衡

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$.
定义(瓦尔拉斯均衡):当资源分配 $(x^{*1}, \ldots, x^{I})$ 和价格向量 $p^ \in \mathbb{R}^L_{++}$ 满足以下两个条件时,即构成瓦尔拉斯均衡:
  1. 效用最大化:对每个消费者$i$,$x^{i}$都是价格$p^$下消费者问题的最优解
  2. 市场出清:$\sum_{i=1}^{I} x^{*i} = \sum_{i=1}^{I} \omega^i$
等价表述为:超额需求函数 $z(p) = \sum_{i=1}^{I} [x^i(p) - \omega^i]$ 满足 $z(p^*) = 0$。

Step 4: State Key Theoretical Results

步骤4:列出核心理论结论

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.
根据场景需要可包含以下定理:
定理(瓦尔拉斯法则):对任意价格向量$p$: $$p \cdot z(p) = 0$$
解释:超额需求的总价值始终为0(所有消费者的预算约束都是紧的)。
定理(第一福利定理):任何瓦尔拉斯均衡的资源分配都是帕累托有效的。
定理(第二福利定理):在凸性假设下,任何帕累托有效的资源分配都可以通过适当的一次性转移支付,对应为一个瓦尔拉斯均衡。
定理(存在性 - Debreu, 1959):在标准假设下(偏好连续、严格凸、严格单调,禀赋严格为正),瓦尔拉斯均衡必然存在。

Step 5: Generate Julia Code for Computation

步骤5:生成Julia计算代码

Use Julia with the following structure:
julia
undefined
使用如下结构的Julia代码:
julia
undefined

============================================

============================================

General Equilibrium Solver in Julia

General Equilibrium Solver in Julia

Pure Exchange Economy

Pure Exchange Economy

============================================

============================================

using LinearAlgebra using NLsolve using Plots
using LinearAlgebra using NLsolve using Plots

Define the economy structure

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
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

Cobb-Douglas utility: u(x) = ∏ x_l^α_l

function utility_cobb_douglas(x, α) return prod(x .^ α) end
function utility_cobb_douglas(x, α) return prod(x .^ α) end

Marshallian demand for Cobb-Douglas preferences

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
function demand_cobb_douglas(p, wealth, α) # x_l = (α_l / sum(α)) * (wealth / p_l) α_normalized = α / sum(α) return α_normalized .* wealth ./ p end

Excess demand function

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
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)

Solve for equilibrium prices (normalize p_1 = 1)

Uses log-price parameterization to ensure prices remain strictly positive

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
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

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
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

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
undefined
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
undefined

Step 6: Provide Complete Example

步骤6:提供完整示例

julia
undefined
julia
undefined

============================================

============================================

Example: 2×2 Pure Exchange Economy

Example: 2×2 Pure Exchange Economy

============================================

============================================

Two consumers, two goods

Two consumers, two goods

Consumer 1: u(x,y) = x^0.6 * y^0.4, endowment (4, 1)

Consumer 1: u(x,y) = x^0.6 * y^0.4, endowment (4, 1)

Consumer 2: u(x,y) = x^0.3 * y^0.7, endowment (1, 4)

Consumer 2: u(x,y) = x^0.3 * y^0.7, endowment (1, 4)

economy = PureExchangeEconomy( 2, # 2 goods 2, # 2 consumers [4.0 1.0; 1.0 4.0], # Endowment matrix [[0.6, 0.4], [0.3, 0.7]], # Cobb-Douglas parameters :cobb_douglas )
economy = PureExchangeEconomy( 2, # 2 goods 2, # 2 consumers [4.0 1.0; 1.0 4.0], # Endowment matrix [[0.6, 0.4], [0.3, 0.7]], # Cobb-Douglas parameters :cobb_douglas )

Solve for equilibrium

Solve for equilibrium

p_star = solve_equilibrium(economy) println("Equilibrium prices: p = ", p_star)
p_star = solve_equilibrium(economy) println("Equilibrium prices: p = ", p_star)

Compute allocations

Compute allocations

x_star = equilibrium_allocations(p_star, economy) println("Consumer 1 allocation: ", x_star[1, :]) println("Consumer 2 allocation: ", x_star[2, :])
x_star = equilibrium_allocations(p_star, economy) println("Consumer 1 allocation: ", x_star[1, :]) println("Consumer 2 allocation: ", x_star[2, :])

Verify market clearing

Verify market clearing

total_endowment = sum(economy.endowments, dims=1) total_allocation = sum(x_star, dims=1) println("Market clearing check: ", isapprox(total_endowment, total_allocation))
total_endowment = sum(economy.endowments, dims=1) total_allocation = sum(x_star, dims=1) println("Market clearing check: ", isapprox(total_endowment, total_allocation))

Check Pareto efficiency (MRS equality)

Check Pareto efficiency (MRS equality)

mrs = check_pareto_efficiency(x_star, economy) println("MRS values (should be equal): ", mrs)
undefined
mrs = check_pareto_efficiency(x_star, economy) println("MRS values (should be equal): ", mrs)
undefined

Step 7: Visualize with Edgeworth Box

步骤7:埃奇沃思盒可视化

julia
undefined
julia
undefined

============================================

============================================

Edgeworth Box Visualization

Edgeworth Box Visualization

============================================

============================================

function plot_edgeworth_box(economy::PureExchangeEconomy, p_star, x_star) # Total endowment defines box dimensions ω_total = vec(sum(economy.endowments, dims=1))
# Create plot
plt = plot(
    xlim=(0, ω_total[1]),
    ylim=(0, ω_total[2]),
    xlabel="Good 1",
    ylabel="Good 2",
    title="Edgeworth Box",
    legend=:topright,
    aspect_ratio=:equal
)

# Plot endowment point
ω1 = economy.endowments[1, :]
scatter!([ω1[1]], [ω1[2]], label="Endowment", markersize=8, color=:red)

# Plot equilibrium allocation
scatter!([x_star[1, 1]], [x_star[1, 2]], label="Equilibrium", markersize=8, color=:green)

# Plot budget line through endowment
# p_1 * x_1 + p_2 * x_2 = p_1 * ω_1 + p_2 * ω_2
wealth1 = dot(p_star, ω1)
x1_range = range(0, ω_total[1], length=100)
x2_budget = (wealth1 .- p_star[1] .* x1_range) ./ p_star[2]
plot!(x1_range, x2_budget, label="Budget line", color=:blue, linewidth=2)

# Plot contract curve (locus of Pareto efficient allocations)
# For Cobb-Douglas, contract curve: x_2^1 / x_1^1 = (α_2^1/α_1^1) / (α_2^2/α_1^2) * (ω_2 - x_2^1) / (ω_1 - x_1^1)

return plt
end
function plot_edgeworth_box(economy::PureExchangeEconomy, p_star, x_star) # Total endowment defines box dimensions ω_total = vec(sum(economy.endowments, dims=1))
# Create plot
plt = plot(
    xlim=(0, ω_total[1]),
    ylim=(0, ω_total[2]),
    xlabel="Good 1",
    ylabel="Good 2",
    title="Edgeworth Box",
    legend=:topright,
    aspect_ratio=:equal
)

# Plot endowment point
ω1 = economy.endowments[1, :]
scatter!([ω1[1]], [ω1[2]], label="Endowment", markersize=8, color=:red)

# Plot equilibrium allocation
scatter!([x_star[1, 1]], [x_star[1, 2]], label="Equilibrium", markersize=8, color=:green)

# Plot budget line through endowment
# p_1 * x_1 + p_2 * x_2 = p_1 * ω_1 + p_2 * ω_2
wealth1 = dot(p_star, ω1)
x1_range = range(0, ω_total[1], length=100)
x2_budget = (wealth1 .- p_star[1] .* x1_range) ./ p_star[2]
plot!(x1_range, x2_budget, label="Budget line", color=:blue, linewidth=2)

# Plot contract curve (locus of Pareto efficient allocations)
# For Cobb-Douglas, contract curve: x_2^1 / x_1^1 = (α_2^1/α_1^1) / (α_2^2/α_1^2) * (ω_2 - x_2^1) / (ω_1 - x_1^1)

return plt
end

Generate the plot

Generate the plot

plt = plot_edgeworth_box(economy, p_star, x_star) savefig(plt, "edgeworth_box.png")
undefined
plt = plot_edgeworth_box(economy, p_star, x_star) savefig(plt, "edgeworth_box.png")
undefined

Example Prompts

示例调用提示

Users might invoke this skill with prompts like:
  • "Set up a 2-good, 3-consumer pure exchange economy with CES preferences"
  • "Derive the Walrasian equilibrium conditions for a Cobb-Douglas economy"
  • "Write Julia code to solve for equilibrium prices in my exchange economy"
  • "Prove the First Welfare Theorem for a pure exchange economy"
  • "Plot an Edgeworth box showing the contract curve and equilibrium"
  • "Compute comparative statics: how does equilibrium change if endowments shift?"
用户可以通过以下提示调用本技能:
  • "搭建一个包含2种商品、3个消费者、采用CES偏好的纯交换经济模型"
  • "推导Cobb-Douglas经济的瓦尔拉斯均衡条件"
  • "编写Julia代码求解我的交换经济的均衡价格"
  • "证明纯交换经济的第一福利定理"
  • "绘制埃奇沃思盒,展示契约曲线和均衡点"
  • "计算比较静态结果:禀赋变化时均衡会如何变动?"

Requirements

依赖要求

Software

软件版本

  • Julia 1.9+
  • Julia 1.9+

Packages

依赖包

julia
using Pkg
Pkg.add(["NLsolve", "LinearAlgebra", "Plots", "ForwardDiff"])
PackagePurpose
NLsolve
Nonlinear equation solver for excess demand = 0
LinearAlgebra
Vector/matrix operations
Plots
Visualization (Edgeworth box, etc.)
ForwardDiff
Automatic differentiation for Jacobians
julia
using Pkg
Pkg.add(["NLsolve", "LinearAlgebra", "Plots", "ForwardDiff"])
包名用途
NLsolve
求解超额需求=0的非线性方程组
LinearAlgebra
向量/矩阵运算
Plots
可视化(埃奇沃思盒等)
ForwardDiff
雅可比矩阵自动微分

Mathematical Background

数学背景

Assumptions for Existence

均衡存在性假设

Standard assumptions ensuring equilibrium existence:
  1. Continuity: Each $u^i$ is continuous
  2. Strict Monotonicity: $x \gg y \Rightarrow u^i(x) > u^i(y)$
  3. Strict Convexity: $u^i$ is strictly quasiconcave
  4. Positive Endowments: $\omega^i \gg 0$ for all $i$
保证均衡存在的标准假设:
  1. 连续性:所有效用函数$u^i$都是连续的
  2. 严格单调性:$x \gg y \Rightarrow u^i(x) > u^i(y)$
  3. 严格凸性:效用函数$u^i$是严格拟凹的
  4. 正禀赋:对所有消费者$i$,都有$\omega^i \gg 0$

Properties of Excess Demand

超额需求的性质

Under standard assumptions, $z(p)$ satisfies:
  1. Continuity: $z$ is continuous
  2. Homogeneity of degree 0: $z(\lambda p) = z(p)$ for all $\lambda > 0$
  3. Walras' Law: $p \cdot z(p) = 0$
  4. Boundary behavior: If $p_l \to 0$, then $z_l(p) \to +\infty$
在标准假设下,$z(p)$满足:
  1. 连续性:$z$是连续函数
  2. 零次齐次性:对任意$\lambda > 0$,都有$z(\lambda p) = z(p)$
  3. 瓦尔拉斯法则:$p \cdot z(p) = 0$
  4. 边界行为:如果$p_l \to 0$,则$z_l(p) \to +\infty$

Numerical Solution Strategy

数值求解策略

  1. Normalize prices: Set $p_1 = 1$ (numeraire)
  2. Reduce dimension: Solve $z_2(p) = \cdots = z_L(p) = 0$ (Walras' Law gives $z_1 = 0$)
  3. Use Newton's method:
    NLsolve.jl
    with autodiff for Jacobian
  4. Handle boundaries: Ensure $p_l > 0$ during iteration
  1. 价格标准化:设置$p_1 = 1$(作为计价物)
  2. 降维求解:仅求解$z_2(p) = \cdots = z_L(p) = 0$(瓦尔拉斯法则保证$z_1 = 0$)
  3. 牛顿法求解:使用
    NLsolve.jl
    的自动微分功能计算雅可比矩阵
  4. 边界处理:迭代过程中保证$p_l > 0$

Best Practices

最佳实践

  1. Always verify market clearing after solving
  2. Check Walras' Law holds numerically ($p \cdot z \approx 0$)
  3. Verify Pareto efficiency by checking MRS equality across consumers
  4. Use multiple initial guesses if solver doesn't converge
  5. Normalize prices to avoid indeterminacy (homogeneity of degree 0)
  1. 求解完成后务必验证市场出清条件
  2. 数值验证瓦尔拉斯法则成立($p \cdot z \approx 0$)
  3. 通过验证不同消费者的边际替代率相等,确认帕累托效率
  4. 如果求解不收敛,尝试多个初始猜测值
  5. 标准化价格避免解的不确定性(零次齐次性导致)

Common Pitfalls

常见误区

  • ❌ Forgetting that prices are only determined up to a scalar (must normalize)
  • ❌ Not checking for corner solutions (zero consumption of some good)
  • ❌ Ignoring numerical precision issues near boundaries
  • ❌ Assuming uniqueness without verifying (multiple equilibria are possible)
  • ❌ Confusing Marshallian (uncompensated) and Hicksian (compensated) demands
  • ❌ 忘记价格只有相对值是确定的,必须进行标准化
  • ❌ 未检查角点解(部分商品消费量为0的情况)
  • ❌ 忽略边界附近的数值精度问题
  • ❌ 未经验证就假设均衡唯一(可能存在多个均衡)
  • ❌ 混淆马歇尔需求(未补偿)和希克斯需求(补偿)

Extensions (Future Versions)

扩展规划(未来版本)

  • Production economies: Firms with profit maximization
  • Arrow-Debreu securities: Contingent claims and uncertainty
  • Overlapping generations (OLG): Dynamic GE with generational overlap
  • Computable GE (CGE): Calibrated models for policy analysis
  • Incomplete markets: When not all contingencies can be traded
  • 生产经济:加入企业利润最大化行为
  • Arrow-Debreu证券:加入或有债权和不确定性
  • 世代交叠模型(OLG):带代际重叠的动态一般均衡模型
  • 可计算一般均衡(CGE):用于政策分析的校准模型
  • 不完全市场:无法交易所有或有债权的场景

References

参考文献

Textbooks

教材

  • Mas-Colell, Whinston, and Green (1995). Microeconomic Theory. Oxford University Press. Chapters 15-17.
  • Debreu, G. (1959). Theory of Value. Yale University Press.
  • Varian, H. (1992). Microeconomic Analysis. 3rd Edition. Chapters 17-18.
  • Mas-Colell, Whinston, and Green (1995). Microeconomic Theory. Oxford University Press. Chapters 15-17.
  • Debreu, G. (1959). Theory of Value. Yale University Press.
  • Varian, H. (1992). Microeconomic Analysis. 3rd Edition. Chapters 17-18.

Computational Resources

计算资源

Key Papers

核心论文

  • Arrow, K. J., & Debreu, G. (1954). Existence of an equilibrium for a competitive economy. Econometrica, 22(3), 265-290.
  • Scarf, H. (1967). The approximation of fixed points of a continuous mapping. SIAM Journal on Applied Mathematics, 15(5), 1328-1343.
  • Arrow, K. J., & Debreu, G. (1954). Existence of an equilibrium for a competitive economy. Econometrica, 22(3), 265-290.
  • Scarf, H. (1967). The approximation of fixed points of a continuous mapping. SIAM Journal on Applied Mathematics, 15(5), 1328-1343.

Changelog

更新日志

v1.0.0

v1.0.0

  • Initial release: Pure exchange economies with Cobb-Douglas preferences
  • Julia implementation with NLsolve
  • Edgeworth box visualization
  • Theoretical framework and welfare theorems
  • 初始版本:支持带Cobb-Douglas偏好的纯交换经济
  • 基于NLsolve的Julia实现
  • 埃奇沃思盒可视化功能
  • 理论框架与福利定理说明