@@ -249,10 +249,10 @@ class ExchangeEconomy:
249
249
if np.min(b / np.max(Pi @ e)) <= 1.5:
250
250
raise Exception('set bliss points further away')
251
251
252
- if Ws== None:
252
+ if Ws == None:
253
253
Ws = np.zeros(m)
254
254
else:
255
- if sum(Ws)!= 0:
255
+ if sum(Ws) != 0:
256
256
raise Exception('invalid wealth distribution')
257
257
258
258
self.Pi, self.bs, self.es, self.Ws, self.n, self.m = Pi, bs, es, Ws, n, m
@@ -272,16 +272,16 @@ class ExchangeEconomy:
272
272
273
273
# compute price vector with mu=1 and renormalize
274
274
p = Pi.T @ b - Pi.T @ Pi @ e
275
- p = p/ p[0]
275
+ p = p / p[0]
276
276
277
277
# compute marg util of wealth
278
278
mu_s = []
279
279
c_s = []
280
280
A = p.T @ slope_dc @ p
281
281
282
282
for i in range(m):
283
- mu_i = (-Ws[i] + p.T @ (Pi_inv @ bs[i] - es[i]))/ A
284
- c_i = Pi_inv @ bs[i] - mu_i* slope_dc @ p
283
+ mu_i = (-Ws[i] + p.T @ (Pi_inv @ bs[i] - es[i])) / A
284
+ c_i = Pi_inv @ bs[i] - mu_i * slope_dc @ p
285
285
mu_s.append(mu_i)
286
286
c_s.append(c_i)
287
287
@@ -305,11 +305,11 @@ class ExchangeEconomy:
305
305
Pi = np.array([[1, 0],
306
306
[0, 1]])
307
307
308
- bs = [np.array([5, 5]), # first consumer's bliss points
309
- np.array([5, 5])] # second consumer's bliss points
308
+ bs = [np.array([5, 5]), # first consumer's bliss points
309
+ np.array([5, 5])] # second consumer's bliss points
310
310
311
- es = [np.array([0, 2]), # first consumer's endowment
312
- np.array([2, 0])] # second consumer's endowment
311
+ es = [np.array([0, 2]), # first consumer's endowment
312
+ np.array([2, 0])] # second consumer's endowment
313
313
314
314
example = ExchangeEconomy(Pi, bs, es)
315
315
p, c_s, mu_s = example.competitive_equilibrium()
@@ -321,12 +321,11 @@ print('Competitive equilibrium allocation:', c_s)
321
321
What happens if the first consumer likes the first good more and the second consumer likes the second good more?
322
322
323
323
``` {code-cell} ipython3
324
- bs = [np.array([6, 5]), # first consumer's bliss points
325
- np.array([5, 6])] # second consumer's bliss points
326
-
327
- es = [np.array([0, 2]), # first consumer's endowment
328
- np.array([2, 0])] # second consumer's endowment
324
+ bs = [np.array([6, 5]), # first consumer's bliss points
325
+ np.array([5, 6])] # second consumer's bliss points
329
326
327
+ es = [np.array([0, 2]), # first consumer's endowment
328
+ np.array([2, 0])] # second consumer's endowment
330
329
331
330
example = ExchangeEconomy(Pi, bs, es)
332
331
p, c_s, mu_s = example.competitive_equilibrium()
@@ -338,12 +337,11 @@ print('Competitive equilibrium allocation:', c_s)
338
337
Let the first consumer be poorer.
339
338
340
339
``` {code-cell} ipython3
341
- bs = [np.array([5, 5]), # first consumer's bliss points
342
- np.array([5, 5])] # second consumer's bliss points
343
-
344
- es = [np.array([0.5, 0.5]), # first consumer's endowment
345
- np.array([1, 1])] # second consumer's endowment
340
+ bs = [np.array([5, 5]), # first consumer's bliss points
341
+ np.array([5, 5])] # second consumer's bliss points
346
342
343
+ es = [np.array([0.5, 0.5]), # first consumer's endowment
344
+ np.array([1, 1])] # second consumer's endowment
347
345
348
346
example = ExchangeEconomy(Pi, bs, es)
349
347
p, c_s, mu_s = example.competitive_equilibrium()
@@ -355,12 +353,11 @@ print('Competitive equilibrium allocation:', c_s)
355
353
Now let's construct an autarky (i.e, no-trade) equilibrium.
356
354
357
355
``` {code-cell} ipython3
358
- bs = [np.array([4, 6]), # first consumer's bliss points
359
- np.array([6, 4])] # second consumer's bliss points
360
-
361
- es = [np.array([0, 2]), # first consumer's endowment
362
- np.array([2, 0])] # second consumer's endowment
356
+ bs = [np.array([4, 6]), # first consumer's bliss points
357
+ np.array([6, 4])] # second consumer's bliss points
363
358
359
+ es = [np.array([0, 2]), # first consumer's endowment
360
+ np.array([2, 0])] # second consumer's endowment
364
361
365
362
example = ExchangeEconomy(Pi, bs, es)
366
363
p, c_s, mu_s = example.competitive_equilibrium()
@@ -372,11 +369,11 @@ print('Competitive equilibrium allocation:', c_s)
372
369
Now let's redistribute endowments before trade.
373
370
374
371
``` {code-cell} ipython3
375
- bs = [np.array([5, 5]), # first consumer's bliss points
376
- np.array([5, 5])] # second consumer's bliss points
372
+ bs = [np.array([5, 5]), # first consumer's bliss points
373
+ np.array([5, 5])] # second consumer's bliss points
377
374
378
- es = [np.array([1, 1]), # first consumer's endowment
379
- np.array([1, 1])] # second consumer's endowment
375
+ es = [np.array([1, 1]), # first consumer's endowment
376
+ np.array([1, 1])] # second consumer's endowment
380
377
381
378
Ws = [0.5, -0.5]
382
379
example = ExchangeEconomy(Pi, bs, es, Ws)
@@ -397,9 +394,9 @@ beta = 0.95
397
394
Pi = np.array([[1, 0],
398
395
[0, np.sqrt(beta)]])
399
396
400
- bs = [np.array([5, np.sqrt(beta)* 5])]
397
+ bs = [np.array([5, np.sqrt(beta) * 5])]
401
398
402
- es = [np.array([1,1])]
399
+ es = [np.array([1, 1])]
403
400
404
401
example = ExchangeEconomy(Pi, bs, es)
405
402
p, c_s, mu_s = example.competitive_equilibrium()
@@ -419,10 +416,10 @@ We use the tricks described above to interpret $c_1, c_2$ as "Arrow securities"
419
416
prob = 0.7
420
417
421
418
Pi = np.array([[np.sqrt(prob), 0],
422
- [0, np.sqrt(1- prob)]])
419
+ [0, np.sqrt(1 - prob)]])
423
420
424
- bs = [np.array([np.sqrt(prob)* 5, np.sqrt(1- prob)* 5]),
425
- np.array([np.sqrt(prob)* 5, np.sqrt(1- prob)* 5])]
421
+ bs = [np.array([np.sqrt(prob) * 5, np.sqrt(1 - prob) * 5]),
422
+ np.array([np.sqrt(prob) * 5, np.sqrt(1 - prob) * 5])]
426
423
427
424
es = [np.array([1, 0]),
428
425
np.array([0, 1])]
@@ -464,13 +461,13 @@ class ProductionEconomy:
464
461
Compute a competitive equilibrium of the production economy
465
462
"""
466
463
Pi, b, h, mu, J = self.Pi, self.b, self.h, self.mu, self.J
467
- H = .5*(J+ J.T)
464
+ H = .5 * (J + J.T)
468
465
469
466
# allocation
470
- c = inv(Pi.T@ Pi + mu* H) @ (Pi.T@ b - mu* h)
467
+ c = inv(Pi.T @ Pi + mu * H) @ (Pi.T @ b - mu * h)
471
468
472
469
# price
473
- p = 1/ mu * (Pi.T@ b - Pi.T@Pi@ c)
470
+ p = 1 / mu * (Pi.T @ b - Pi.T @ Pi @ c)
474
471
475
472
# check non-satiation
476
473
if any(Pi @ c - b >= 0):
@@ -483,13 +480,13 @@ class ProductionEconomy:
483
480
Compute the equilibrium price and allocation when there is a monopolist supplier
484
481
"""
485
482
Pi, b, h, mu, J = self.Pi, self.b, self.h, self.mu, self.J
486
- H = .5*(J+ J.T)
483
+ H = .5 * (J + J.T)
487
484
488
485
# allocation
489
- q = inv(mu* H + 2* Pi.T@ Pi)@ (Pi.T@ b - mu* h)
486
+ q = inv(mu * H + 2 * Pi.T @ Pi) @ (Pi.T @ b - mu * h)
490
487
491
488
# price
492
- p = 1/ mu * (Pi.T@ b - Pi.T@Pi@ q)
489
+ p = 1 / mu * (Pi.T @ b - Pi.T @ Pi @ q)
493
490
494
491
if any(Pi @ q - b >= 0):
495
492
raise Exception('invalid result: set bliss points further away')
@@ -500,21 +497,21 @@ class ProductionEconomy:
500
497
"""
501
498
Compute consumer and producer surplus for single good case
502
499
"""
503
- if self.n!= 1:
500
+ if self.n != 1:
504
501
raise Exception('not single good')
505
502
h, J, Pi, b, mu = self.h.item(), self.J.item(), self.Pi.item(), self.b.item(), self.mu
506
503
H = J
507
504
508
505
# supply/demand curve coefficients
509
506
s0, s1 = h, H
510
- d0, d1 = 1/ mu * Pi * b, 1/ mu * Pi**2
507
+ d0, d1 = 1 / mu * Pi * b, 1 / mu * Pi**2
511
508
512
509
# competitive equilibrium
513
510
c, p = self.competitive_equilibrium()
514
511
515
512
# calculate surplus
516
- c_surplus = d0* c - .5*d1* c**2 - p* c
517
- p_surplus = p* c - s0* c - .5*s1* c**2
513
+ c_surplus = d0 * c - .5 * d1 * c**2 - p * c
514
+ p_surplus = p * c - s0 * c - .5 * s1 * c**2
518
515
519
516
return c_surplus, p_surplus
520
517
@@ -536,21 +533,21 @@ def plot_competitive_equilibrium(PE):
536
533
c, p = c.item(), p.item()
537
534
538
535
# inverse supply/demand curve
539
- supply_inv = lambda x: h + H* x
540
- demand_inv = lambda x: 1/mu* (Pi* b - Pi*Pi* x)
536
+ supply_inv = lambda x: h + H * x
537
+ demand_inv = lambda x: 1 / mu * (Pi * b - Pi * Pi * x)
541
538
542
- xs = np.linspace(0, 2* c, 100)
539
+ xs = np.linspace(0, 2 * c, 100)
543
540
ps = np.ones(100) * p
544
541
supply_curve = supply_inv(xs)
545
- demand_curve = demand_inv(xs)
542
+ demand_curve = demand_inv(xs)
546
543
547
544
# plot
548
- plt.figure(figsize=[7,5])
545
+ plt.figure(figsize=[7, 5])
549
546
plt.plot(xs, supply_curve, label='Supply', color='#020060')
550
547
plt.plot(xs, demand_curve, label='Demand', color='#600001')
551
548
552
- plt.fill_between(xs[xs<= c], demand_curve[xs<= c], ps[xs<= c], label='Consumer surplus', color='#EED1CF')
553
- plt.fill_between(xs[xs<= c], supply_curve[xs<= c], ps[xs<= c], label='Producer surplus', color='#E6E6F5')
549
+ plt.fill_between(xs[xs <= c], demand_curve[xs <= c], ps[xs <= c], label='Consumer surplus', color='#EED1CF')
550
+ plt.fill_between(xs[xs <= c], supply_curve[xs <= c], ps[xs <= c], label='Producer surplus', color='#E6E6F5')
554
551
555
552
plt.vlines(c, 0, p, linestyle="dashed", color='black', alpha=0.7)
556
553
plt.hlines(p, 0, c, linestyle="dashed", color='black', alpha=0.7)
@@ -580,10 +577,10 @@ To do this we
580
577
* do experiments in which we shift $b$ and watch what happens to $p, c$.
581
578
582
579
``` {code-cell} ipython3
583
- Pi = np.array([[1]]) # the matrix now is a singleton
584
- b = np.array([10])
585
- h = np.array([0.5])
586
- J = np.array([[1]])
580
+ Pi = np.array([[1]]) # the matrix now is a singleton
581
+ b = np.array([10])
582
+ h = np.array([0.5])
583
+ J = np.array([[1]])
587
584
mu = 1
588
585
589
586
PE = ProductionEconomy(Pi, b, h, J, mu)
@@ -648,13 +645,13 @@ This raises both the equilibrium price and quantity.
648
645
649
646
650
647
``` {code-cell} ipython3
651
- Pi = np.array([[1, 0],
652
- [0, 1]])
653
- b = np.array([10, 10])
648
+ Pi = np.array([[1, 0],
649
+ [0, 1]])
650
+ b = np.array([10, 10])
654
651
655
- h = np.array([0.5, 0.5])
656
- J = np.array([[1, 0.5],
657
- [0.5, 1]])
652
+ h = np.array([0.5, 0.5])
653
+ J = np.array([[1, 0.5],
654
+ [0.5, 1]])
658
655
mu = 1
659
656
660
657
PE = ProductionEconomy(Pi, b, h, J, mu)
@@ -750,24 +747,24 @@ def plot_monopoly(PE):
750
747
# compute
751
748
752
749
# inverse supply/demand curve
753
- marg_cost = lambda x: h + H* x
754
- marg_rev = lambda x: -2*1/mu*Pi*Pi* x + 1/mu*Pi* b
755
- demand_inv = lambda x: 1/mu* (Pi* b - Pi*Pi* x)
750
+ marg_cost = lambda x: h + H * x
751
+ marg_rev = lambda x: -2 * 1 / mu * Pi * Pi * x + 1 / mu * Pi * b
752
+ demand_inv = lambda x: 1 / mu * (Pi * b - Pi * Pi * x)
756
753
757
- xs = np.linspace(0, 2* c, 100)
754
+ xs = np.linspace(0, 2 * c, 100)
758
755
pms = np.ones(100) * pm
759
756
marg_cost_curve = marg_cost(xs)
760
757
marg_rev_curve = marg_rev(xs)
761
758
demand_curve = demand_inv(xs)
762
759
763
760
# plot
764
- plt.figure(figsize=[7,5])
761
+ plt.figure(figsize=[7, 5])
765
762
plt.plot(xs, marg_cost_curve, label='Marginal cost', color='#020060')
766
763
plt.plot(xs, marg_rev_curve, label='Marginal revenue', color='#E55B13')
767
764
plt.plot(xs, demand_curve, label='Demand', color='#600001')
768
765
769
- plt.fill_between(xs[xs<= q], demand_curve[xs<= q], pms[xs<= q], label='Consumer surplus', color='#EED1CF')
770
- plt.fill_between(xs[xs<= q], marg_cost_curve[xs<= q], pms[xs<= q], label='Producer surplus', color='#E6E6F5')
766
+ plt.fill_between(xs[xs <= q], demand_curve[xs <= q], pms[xs <= q], label='Consumer surplus', color='#EED1CF')
767
+ plt.fill_between(xs[xs <= q], marg_cost_curve[xs <= q], pms[xs <= q], label='Producer surplus', color='#E6E6F5')
771
768
772
769
plt.vlines(c, 0, p, linestyle="dashed", color='black', alpha=0.7)
773
770
plt.hlines(p, 0, c, linestyle="dashed", color='black', alpha=0.7)
@@ -790,13 +787,13 @@ def plot_monopoly(PE):
790
787
Let's study compare competitive equilibrium and monopoly outcomes in a multiple goods economy.
791
788
792
789
``` {code-cell} ipython3
793
- Pi = np.array([[1, 0],
794
- [0, 1.2]])
795
- b = np.array([10, 10])
790
+ Pi = np.array([[1, 0],
791
+ [0, 1.2]])
792
+ b = np.array([10, 10])
796
793
797
- h = np.array([0.5, 0.5])
798
- J = np.array([[1, 0.5],
799
- [0.5, 1]])
794
+ h = np.array([0.5, 0.5])
795
+ J = np.array([[1, 0.5],
796
+ [0.5, 1]])
800
797
mu = 1
801
798
802
799
PE = ProductionEconomy(Pi, b, h, J, mu)
@@ -813,7 +810,7 @@ print('Equilibrium with monopolist supplier allocation:', q)
813
810
#### A Single-Good Example
814
811
815
812
``` {code-cell} ipython3
816
- Pi = np.array([[1]]) # the matrix now is a singleton
813
+ Pi = np.array([[1]]) # the matrix now is a singleton
817
814
b = np.array([10])
818
815
h = np.array([0.5])
819
816
J = np.array([[1]])
0 commit comments