Spacial Equilibrium Model
Contents
Spacial Equilibrium Model¶
Randall Romero Aguilar, PhD
This demo is based on the original Matlab demo accompanying the Computational Economics and Finance 2001 textbook by Mario Miranda and Paul Fackler.
Original (Matlab) CompEcon file: demslv14.m
Running this file requires the Python version of CompEcon. This can be installed with pip by running
!pip install compecon --upgrade
Last updated: 2022-Sept-05
About¶
See textbook page 56 for description
Demand and supply equations
Country |
Demand |
Supply |
---|---|---|
1 |
p = 42 - 2q |
p = 9 + 1q |
2 |
p = 54 - 3q |
p = 3 + 2q |
3 |
p = 51 - 1q |
p = 18 + 1q |
Transportation costs:
From |
To country 1 |
To country 2 |
To country 3 |
---|---|---|---|
Country 1 |
0 |
3 |
9 |
Country 2 |
3 |
0 |
3 |
Country 3 |
6 |
3 |
0 |
import numpy as np
from compecon import MCP
np.set_printoptions(precision=4, suppress=True)
A = np.array
as_ = A([9, 3, 18])
bs = A([1, 2, 1])
ad = A([42, 54, 51])
bd = A([2, 3, 1])
c = A([[0, 3, 9], [3, 0, 3],[6, 3, 0]])
def market(x):
quantities = x.reshape((3,3))
ps = as_ + bs * quantities.sum(0)
pd = ad - bd * quantities.sum(1)
ps, pd = np.meshgrid(ps, pd)
fval = (pd - ps - c).flatten()
return fval
a = np.zeros(9)
b = np.full(9, np.inf)
Market = MCP(market, a, b)
x0 = np.zeros(9)
x = Market.zero(x0, transform='minmax')
quantities = x.reshape(3,3)
prices = as_ + bs * quantities.sum(0)
exports = quantities.sum(0) - quantities.sum(1)
print('Quantities = \n', quantities)
print('Prices = \n', prices)
print('Net exports =\n', exports)
Quantities =
[[ 9. -0. 0. ]
[ 1.6347 7.3653 0. ]
[ 4.3653 4.6347 12. ]]
Prices =
[24. 27. 30.]
Net exports =
[ 6. 3. -9.]
In autarky¶
quantities = (ad - as_) / (bs + bd)
prices = as_ + bs * quantities
print('Quantities = \n', quantities)
print('Prices = \n', prices)
Quantities =
[11. 10.2 16.5]
Prices =
[20. 23.4 34.5]