my-markdown-library 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/F24LS_md/ Lecture 4 - Public.md +347 -0
  3. data/F24LS_md/Lecture 1 - Introduction and Overview.md +327 -0
  4. data/F24LS_md/Lecture 10 - Development_.md +631 -0
  5. data/F24LS_md/Lecture 11 - Econometrics.md +345 -0
  6. data/F24LS_md/Lecture 12 - Finance.md +692 -0
  7. data/F24LS_md/Lecture 13 - Environmental Economics.md +299 -0
  8. data/F24LS_md/Lecture 15 - Conclusion.md +272 -0
  9. data/F24LS_md/Lecture 2 - Demand.md +349 -0
  10. data/F24LS_md/Lecture 3 - Supply.md +329 -0
  11. data/F24LS_md/Lecture 5 - Production C-D.md +291 -0
  12. data/F24LS_md/Lecture 6 - Utility and Latex.md +440 -0
  13. data/F24LS_md/Lecture 7 - Inequality.md +607 -0
  14. data/F24LS_md/Lecture 8 - Macroeconomics.md +704 -0
  15. data/F24LS_md/Lecture 8 - Macro.md +700 -0
  16. data/F24LS_md/Lecture 9 - Game Theory_.md +436 -0
  17. data/F24LS_md/summary.yaml +105 -0
  18. data/F24Lec_MD/LecNB_summary.yaml +206 -0
  19. data/F24Lec_MD/lec01/lec01.md +267 -0
  20. data/F24Lec_MD/lec02/Avocados_demand.md +425 -0
  21. data/F24Lec_MD/lec02/Demand_Steps_24.md +126 -0
  22. data/F24Lec_MD/lec02/PriceElasticity.md +83 -0
  23. data/F24Lec_MD/lec02/ScannerData_Beer.md +171 -0
  24. data/F24Lec_MD/lec02/demand-curve-Fa24.md +213 -0
  25. data/F24Lec_MD/lec03/3.0-CubicCostCurve.md +239 -0
  26. data/F24Lec_MD/lec03/3.1-Supply.md +274 -0
  27. data/F24Lec_MD/lec03/3.2-sympy.md +332 -0
  28. data/F24Lec_MD/lec03/3.3a-california-energy.md +120 -0
  29. data/F24Lec_MD/lec03/3.3b-a-really-hot-tuesday.md +121 -0
  30. data/F24Lec_MD/lec04/lec04-CSfromSurvey-closed.md +335 -0
  31. data/F24Lec_MD/lec04/lec04-CSfromSurvey.md +331 -0
  32. data/F24Lec_MD/lec04/lec04-Supply-Demand-closed.md +519 -0
  33. data/F24Lec_MD/lec04/lec04-Supply-Demand.md +514 -0
  34. data/F24Lec_MD/lec04/lec04-four-plot-24.md +34 -0
  35. data/F24Lec_MD/lec04/lec04-four-plot.md +34 -0
  36. data/F24Lec_MD/lec05/Lec5-Cobb-Douglas.md +131 -0
  37. data/F24Lec_MD/lec05/Lec5-CobbD-AER1928.md +283 -0
  38. data/F24Lec_MD/lec06/6.1-Sympy-Differentiation.md +253 -0
  39. data/F24Lec_MD/lec06/6.2-3D-utility.md +287 -0
  40. data/F24Lec_MD/lec06/6.3-QuantEcon-Optimization.md +399 -0
  41. data/F24Lec_MD/lec06/6.4-latex.md +138 -0
  42. data/F24Lec_MD/lec06/6.5-Edgeworth.md +269 -0
  43. data/F24Lec_MD/lec07/7.1-inequality.md +283 -0
  44. data/F24Lec_MD/lec07/7.2-historical-inequality.md +237 -0
  45. data/F24Lec_MD/lec08/macro-fred-api.md +313 -0
  46. data/F24Lec_MD/lec09/lecNB-prisoners-dilemma.md +88 -0
  47. data/F24Lec_MD/lec10/Lec10.2-waterguard.md +401 -0
  48. data/F24Lec_MD/lec10/lec10.1-mapping.md +199 -0
  49. data/F24Lec_MD/lec11/11.1-slr.md +305 -0
  50. data/F24Lec_MD/lec11/11.2-mlr.md +171 -0
  51. data/F24Lec_MD/lec12/Lec12-4-PersonalFinance.md +590 -0
  52. data/F24Lec_MD/lec12/lec12-1_Interest_Payments.md +267 -0
  53. data/F24Lec_MD/lec12/lec12-2-stocks-options.md +235 -0
  54. data/F24Lec_MD/lec13/Co2_ClimateChange.md +139 -0
  55. data/F24Lec_MD/lec13/ConstructingMAC.md +213 -0
  56. data/F24Lec_MD/lec13/EmissionsTracker.md +170 -0
  57. data/F24Lec_MD/lec13/KuznetsHypothesis.md +219 -0
  58. data/F24Lec_MD/lec13/RoslingPlots.md +217 -0
  59. data/F24Lec_MD/lec15/vibecession.md +485 -0
  60. data/F24Textbook_MD/00-intro/index.md +292 -0
  61. data/F24Textbook_MD/01-demand/01-demand.md +152 -0
  62. data/F24Textbook_MD/01-demand/02-example.md +131 -0
  63. data/F24Textbook_MD/01-demand/03-log-log.md +284 -0
  64. data/F24Textbook_MD/01-demand/04-elasticity.md +248 -0
  65. data/F24Textbook_MD/01-demand/index.md +15 -0
  66. data/F24Textbook_MD/02-supply/01-supply.md +203 -0
  67. data/F24Textbook_MD/02-supply/02-eep147-example.md +86 -0
  68. data/F24Textbook_MD/02-supply/03-sympy.md +138 -0
  69. data/F24Textbook_MD/02-supply/04-market-equilibria.md +204 -0
  70. data/F24Textbook_MD/02-supply/index.md +16 -0
  71. data/F24Textbook_MD/03-public/govt-intervention.md +73 -0
  72. data/F24Textbook_MD/03-public/index.md +10 -0
  73. data/F24Textbook_MD/03-public/surplus.md +351 -0
  74. data/F24Textbook_MD/03-public/taxes-subsidies.md +282 -0
  75. data/F24Textbook_MD/04-production/index.md +15 -0
  76. data/F24Textbook_MD/04-production/production.md +178 -0
  77. data/F24Textbook_MD/04-production/shifts.md +296 -0
  78. data/F24Textbook_MD/05-utility/budget-constraints.md +166 -0
  79. data/F24Textbook_MD/05-utility/index.md +15 -0
  80. data/F24Textbook_MD/05-utility/utility.md +136 -0
  81. data/F24Textbook_MD/06-inequality/historical-inequality.md +253 -0
  82. data/F24Textbook_MD/06-inequality/index.md +15 -0
  83. data/F24Textbook_MD/06-inequality/inequality.md +226 -0
  84. data/F24Textbook_MD/07-game-theory/bertrand.md +257 -0
  85. data/F24Textbook_MD/07-game-theory/cournot.md +333 -0
  86. data/F24Textbook_MD/07-game-theory/equilibria-oligopolies.md +96 -0
  87. data/F24Textbook_MD/07-game-theory/expected-utility.md +61 -0
  88. data/F24Textbook_MD/07-game-theory/index.md +19 -0
  89. data/F24Textbook_MD/07-game-theory/python-classes.md +340 -0
  90. data/F24Textbook_MD/08-development/index.md +35 -0
  91. data/F24Textbook_MD/09-macro/CentralBanks.md +101 -0
  92. data/F24Textbook_MD/09-macro/Indicators.md +77 -0
  93. data/F24Textbook_MD/09-macro/fiscal_policy.md +36 -0
  94. data/F24Textbook_MD/09-macro/index.md +14 -0
  95. data/F24Textbook_MD/09-macro/is_curve.md +76 -0
  96. data/F24Textbook_MD/09-macro/phillips_curve.md +70 -0
  97. data/F24Textbook_MD/10-finance/index.md +10 -0
  98. data/F24Textbook_MD/10-finance/options.md +178 -0
  99. data/F24Textbook_MD/10-finance/value-interest.md +60 -0
  100. data/F24Textbook_MD/11-econometrics/index.md +16 -0
  101. data/F24Textbook_MD/11-econometrics/multivariable.md +218 -0
  102. data/F24Textbook_MD/11-econometrics/reading-econ-papers.md +25 -0
  103. data/F24Textbook_MD/11-econometrics/single-variable.md +483 -0
  104. data/F24Textbook_MD/11-econometrics/statsmodels.md +58 -0
  105. data/F24Textbook_MD/12-environmental/KuznetsHypothesis-Copy1.md +187 -0
  106. data/F24Textbook_MD/12-environmental/KuznetsHypothesis.md +187 -0
  107. data/F24Textbook_MD/12-environmental/MAC.md +254 -0
  108. data/F24Textbook_MD/12-environmental/index.md +36 -0
  109. data/F24Textbook_MD/LICENSE.md +11 -0
  110. data/F24Textbook_MD/intro.md +26 -0
  111. data/F24Textbook_MD/references.md +25 -0
  112. data/F24Textbook_MD/summary.yaml +414 -0
  113. metadata +155 -0
@@ -0,0 +1,514 @@
1
+ ---
2
+ title: "lec04-Supply-Demand"
3
+ type: lecture-notebook
4
+ week: 4
5
+ source_path: "/Users/ericvandusen/Documents/Data88E-ForTraining/F24Lec_NBs/lec04/lec04-Supply-Demand.ipynb"
6
+ ---
7
+
8
+ <table style="width: 100%;">
9
+ <tr style="background-color: transparent;"><td>
10
+ <img src="https://data-88e.github.io/assets/images/blue_text.png" width="250px" style="margin-left: 0;" />
11
+ </td><td>
12
+ <p style="text-align: right; font-size: 10pt;"><strong>Economic Models</strong>, Fall 2024<br>
13
+ Dr. Eric Van Dusen <br>
14
+ </p></td></tr>
15
+ </table>
16
+
17
+ ```python
18
+ import sympy
19
+ solve = lambda x,y: sympy.solve(x-y)[0] if len(sympy.solve(x-y))==1 else "Not Single Solution"
20
+ import matplotlib.pyplot as plt
21
+ plt.style.use('ggplot')
22
+ %matplotlib inline
23
+
24
+ from ipywidgets import interact, interactive, fixed, interact_manual
25
+ import ipywidgets as widgets
26
+ from IPython.display import display
27
+ #import nbinteract as nbi
28
+ import numpy as np
29
+
30
+ import warnings
31
+ warnings.filterwarnings('ignore')
32
+ ```
33
+
34
+ # Supply, Demand, and Equilibrium
35
+
36
+ ## Set-up
37
+
38
+ With this notebook, we are going to plot and solve equations, hopefully giving some more hands on exposure to the materials that you've already seen in class.
39
+
40
+ We have already covered
41
+ - sympy
42
+ - getting slope and intercept for deman curve
43
+ - solving for equilibrium
44
+
45
+ ## Solving Equations with SymPy
46
+
47
+ In order to treat variables like the symbols you would using pen and paper, we have to declare them as such first. We are going to use the inverse forms, so our equations will both be a function of quantity. We create a variable for quantity below.
48
+
49
+ ```python
50
+ Q = sympy.Symbol("Q")
51
+ ```
52
+
53
+ Now when we call this variable, we can see that it is a symbolic variable, and not some other Python type.
54
+
55
+ We cn decplare an upward sloping supply curve with a name, `supply`.
56
+
57
+ ```python
58
+ supply = 3*Q + 4
59
+ supply
60
+ ```
61
+
62
+ We can then substitue in values for our quantity variable. We do so in the following cell. Using the method `subs`, we take the equation we already defined, `supply`, and plug in the value 3 in place of `Q`.
63
+
64
+ ```python
65
+ supply.subs(Q, 3)
66
+ ```
67
+
68
+ Next we'll define an inverse-demand equation.
69
+
70
+ ```python
71
+ demand = -4*Q+15
72
+ demand
73
+ ```
74
+
75
+ We are now able to take our supply and demand equations and find where they intersect. When we use the `solve` function, it will tell us the x-value of the point where the two lines intercept. This is the equilibrium quantity, which we will call that value `Q_star`.
76
+
77
+ ```python
78
+ Q_star = solve(demand, supply) # our version of solve is simplified for single solution systems
79
+ Q_star
80
+ ```
81
+
82
+ We can then substitute `Q_star` back into our original inverse-supply and inverse-demand equations to solve for our equilibrium price.
83
+
84
+ ```python
85
+ demand.subs(Q, Q_star)
86
+ ```
87
+
88
+ ```python
89
+ supply.subs(Q, Q_star)
90
+ ```
91
+
92
+ ## Visualizing those supply and demand equations
93
+
94
+ ```python
95
+ def plot_equation(equation, price_start, price_end, label=None):
96
+ plot_prices = [price_start, price_end]
97
+ plot_quantities = [equation.subs(list(equation.free_symbols)[0], c) for c in plot_prices]
98
+ plt.plot(plot_prices, plot_quantities, label=label)
99
+
100
+ def plot_intercept(eq1, eq2):
101
+ ex = sympy.solve(eq1-eq2)[0]
102
+ why = eq1.subs(list(eq1.free_symbols)[0], ex)
103
+ plt.scatter([ex], [why])
104
+ return (ex, why)
105
+
106
+ plot_equation(demand, 0, 5)
107
+ plot_equation(supply, 0, 5)
108
+ plt.ylim(0,20)
109
+ plot_intercept(supply, demand)
110
+ ```
111
+
112
+ ## Modeling a Shift in Demand
113
+ We would like to be able to add in the ability to shift the demand curve, using a slider
114
+
115
+ ```python
116
+
117
+ def shift_demand():
118
+ equation = demand
119
+ def shift_helper(shift):
120
+ plot_equation(equation, -10, 10)
121
+ plot_equation(supply, -10, 10)
122
+ old = plot_intercept(equation, supply)
123
+ print('Original Intercept:', old)
124
+
125
+ if shift != 0:
126
+ plot_equation(equation + shift, -10, 10, 'shifted')
127
+ new = plot_intercept(equation + shift, supply)
128
+ print('New intercept:', new)
129
+ print('Change in Quantity:', round(float(new[0]-old[0]), 2))
130
+ print('Change in Price:', round(float(new[1]-old[1]), 2))
131
+ else:
132
+ print('Nothing shifted yet, use the slider to move the line!')
133
+ plt.xlim(0,8)
134
+ plt.ylim(0,20)
135
+ plt.legend()
136
+ plt.ylabel("Price")
137
+ plt.xlabel("Quantity")
138
+ interact(shift_helper, shift=(-6, 12, 3))
139
+
140
+ shift_demand()
141
+ ```
142
+
143
+ ## Externalities
144
+ Ok lets 'shift' the analysis to
145
+
146
+ **Marginal Private Benefit (MPB)**
147
+ The marginal private benefit (MPB) is the benefit that an individual or firm receives from consuming or producing an additional unit of a good or service. This benefit is internal to the consumer or producer and does not take into account any external costs or benefits that might affect others.
148
+
149
+ In the case of consumption, the marginal private benefit is the value a consumer places on the next unit of a good, which typically decreases as more units are consumed (due to diminishing marginal utility). This is represented by the private demand curve, which shows the relationship between the quantity demanded and the price.
150
+
151
+ For example:
152
+
153
+ If you buy a textbook, the benefit you receive from reading it is the private benefit. You might be willing to pay a certain price for the book based on how much you value the knowledge it provides.
154
+
155
+ **Marginal Social Benefit (MSB)**
156
+ The marginal social benefit (MSB) is the total benefit to society from consuming or producing an additional unit of a good or service. It includes both the marginal private benefit and any external benefits (or subtracts external costs, in the case of negative externalities).
157
+
158
+ When externalities exist, the marginal social benefit differs from the marginal private benefit. In the case of positive externalities, the MSB is greater than the MPB because the good or service provides additional benefits to third parties that are not captured by the individual consumer.
159
+
160
+ For example:
161
+
162
+ Education creates positive externalities. While the student receives private benefits from increased knowledge and skills (MPB), society as a whole also benefits from having a more educated population, leading to increased productivity, lower crime rates, and higher civic engagement. These additional benefits form the social benefit.
163
+ In a competitive market without intervention, only the private benefits are considered, leading to under-consumption of goods with positive externalities. The market does not provide enough of the good relative to the socially optimal level because individuals do not account for the benefits that spill over to others.
164
+
165
+ **Market Outcome vs. Socially Optimal Outcome**
166
+ In the presence of a positive externality:
167
+
168
+ The market outcome is determined by the intersection of the supply curve (marginal cost) and the private demand curve (MPB).
169
+ However, the socially optimal outcome occurs at the intersection of the supply curve and the social demand curve (MSB), which lies above the private demand curve due to the external benefits.
170
+
171
+ Let's do a simpler version where we just solve the following :
172
+ \begin{align*}
173
+ \text{Private Demand (MPB)}: & \quad P = 100 - 0.3Q \\
174
+ \text{Social Demand (MSB)}: & \quad P = (100 + \text{Externality Shift}) - 0.3Q \\
175
+ \text{Supply (MC)}: & \quad P = 10 + 0.2Q\\
176
+ \text {Where}: & \quad \text{Externality Shift} = +10\\
177
+ \end{align*}
178
+
179
+ ```python
180
+ def private_demand(q):
181
+ return 100 - 0.3 * q
182
+
183
+ def social_demand(q):
184
+ return 110 - 0.3 * q
185
+
186
+ def supply(q):
187
+ return 10 + 0.2 * q
188
+
189
+ market_quantity = (100 - 10) / (0.2 + 0.3)
190
+ optimal_quantity = (110 - 10) / (0.2 + 0.3)
191
+ ```
192
+
193
+ ```python
194
+
195
+ quantities = np.linspace(0, 300, 500)
196
+
197
+ #Plotting
198
+ plt.figure(figsize=(6, 6))
199
+ plt.plot(quantities, private_demand(quantities), label='Private Demand (MPB)', color='green')
200
+ plt.plot(quantities, social_demand(quantities), label='Social Demand (MSB)', color='purple', linestyle='--')
201
+ plt.plot(quantities, supply(quantities), label='Supply (MC)', color='blue')
202
+
203
+ plt.axvline(market_quantity, color='green', linestyle='--', label='Market Quantity')
204
+ plt.axvline(optimal_quantity, color='purple', linestyle='--', label='Optimal Quantity')
205
+
206
+ plt.fill_between(quantities, private_demand(quantities), social_demand(quantities), where=(quantities <= optimal_quantity), color='lightblue', alpha=0.3)
207
+
208
+ plt.title('Positive Externality: Demand Curve')
209
+ plt.xlabel('Quantity')
210
+ plt.ylabel('Price')
211
+ plt.legend()
212
+ plt.grid(True)
213
+ plt.show()
214
+ ```
215
+
216
+ Let's do an interactive version where we solve the following with a variable externality :
217
+ \begin{align*}
218
+ \text{Private Demand (MPB)}: & \quad P = 100 - 0.3Q \\
219
+ \text{Social Demand (MSB)}: & \quad P = (100 + \text{Externality Shift}) - 0.3Q \\
220
+ \text{Supply (MC)}: & \quad P = 10 + 0.2Q
221
+ \end{align*}
222
+
223
+ ```python
224
+ #Everything is wrapped in a function that the slider can interact with
225
+
226
+ def plot_externality(externality_shift):
227
+ def social_demand(q):
228
+ return (100 + externality_shift) - 0.3 * q # Marginal Social Benefit (MSB)
229
+
230
+ #Hard coded values for Equilibrium from solving Demand and Supply
231
+ market_quantity = (100 - 10) / (0.2 + 0.3)
232
+ optimal_quantity = ((100 + externality_shift) - 10) / (0.2 + 0.3)
233
+
234
+ market_price = private_demand(market_quantity)
235
+ optimal_price = social_demand(optimal_quantity)
236
+
237
+ #Plotting
238
+ plt.figure(figsize=(8, 6))
239
+ plt.plot(quantities, private_demand(quantities), color='green')
240
+ plt.plot(quantities, social_demand(quantities), color='purple', linestyle='--')
241
+ plt.plot(quantities, supply(quantities), color='blue')
242
+
243
+ plt.axvline(market_quantity, color='green', linestyle='--', label=f'Market Quantity: {market_quantity:.2f}')
244
+ plt.axvline(optimal_quantity, color='purple', linestyle='--', label=f'Social Quantity: {optimal_quantity:.2f}')
245
+
246
+ plt.axhline(market_price, color='green', linestyle='--', label=f'Market Price: {market_price:.2f}')
247
+ plt.axhline(optimal_price, color='purple', linestyle='--', label=f'Social Price: {optimal_price:.2f}')
248
+
249
+
250
+ plt.fill_between(quantities, private_demand(quantities), social_demand(quantities), where=(quantities <= optimal_quantity), color='lightblue', alpha=0.3)
251
+
252
+ #Labels on demand
253
+ plt.text(300, private_demand(300) + 2, 'Marginal Private Benefit (MPB)', color='green', fontsize=12)
254
+ plt.text(300, social_demand(300) + 2, 'Marginal Social Benefit (MSB)', color='purple', fontsize=12)
255
+ #Labels on supply
256
+ plt.text(300, supply(300) + 2, 'Supply ', color='blue', fontsize=12)
257
+
258
+
259
+ plt.title(f' Externality: Externality Shift = {externality_shift}')
260
+ plt.xlabel('Quantity')
261
+ plt.ylabel('Price')
262
+ plt.legend()
263
+ plt.grid(True)
264
+ plt.show()
265
+
266
+ #Slider for externality shift
267
+ interact(plot_externality, externality_shift=widgets.IntSlider(min=-20, max=20, step=1, value=10, description="Externality Shift"));
268
+ ```
269
+
270
+ ## Consumer and Producer Surplus
271
+
272
+ ```python
273
+ import numpy as np
274
+ import matplotlib.pyplot as plt
275
+ import sympy
276
+ from sympy import symbols
277
+ import matplotlib.patches as patches
278
+
279
+ # Define the quantity symbol for sympy
280
+ Q = symbols('Q')
281
+
282
+ # Simplified Equilibrium function with a range of quantities
283
+ def Equilibrium(demandParam, supplyParam):
284
+ # Define demand and supply equations as functions of quantity
285
+ demandEquation = demandParam - Q # P = demandParam - Q
286
+ supplyEquation = (supplyParam / 10) * Q # P = (supplyParam / 10) * Q
287
+
288
+ # Convert the sympy equations to numerical functions using lambdify
289
+ demandFunc = sympy.lambdify(Q, demandEquation, "numpy")
290
+ supplyFunc = sympy.lambdify(Q, supplyEquation, "numpy")
291
+
292
+ # Define a fixed range of quantities (from 0 to 100)
293
+ quantities = np.linspace(0, 50, 50)
294
+
295
+ # Calculate corresponding prices for each quantity for demand and supply
296
+ demandPrices = demandFunc(quantities) # Evaluate demand prices as numerical values
297
+ supplyPrices = supplyFunc(quantities) # Evaluate supply prices as numerical values
298
+
299
+ # Find the equilibrium quantity by solving where demand equals supply
300
+ equilibriumQ = sympy.solve(demandEquation - supplyEquation, Q)[0]
301
+ equilibriumP = demandEquation.subs(Q, equilibriumQ)
302
+
303
+ # Convert equilibrium values to float for plotting
304
+ equilibriumQ = float(equilibriumQ)
305
+ equilibriumP = float(equilibriumP)
306
+
307
+ # Plot demand and supply curves
308
+ plt.plot(quantities, demandPrices, label="Demand (MPB)", color="green")
309
+ plt.plot(quantities, supplyPrices, label="Supply (MC)", color="blue")
310
+
311
+ # Mark equilibrium point
312
+ plt.plot(equilibriumQ, equilibriumP, 'ro', label=f"Equilibrium Q={round(equilibriumQ, 2)}, P={round(equilibriumP, 2)}")
313
+
314
+ # Shade consumer and producer surplus
315
+ triangle1 = patches.Polygon([[0, equilibriumP], [equilibriumQ, equilibriumP], [0, demandFunc(0)]], True, color="green", alpha=0.3)
316
+ triangle2 = patches.Polygon([[0, equilibriumP], [equilibriumQ, equilibriumP], [0, 0]], True, color="red", alpha=0.3)
317
+ currentAxis = plt.gca()
318
+ currentAxis.add_patch(triangle1)
319
+ currentAxis.add_patch(triangle2)
320
+
321
+ # Add labels and legend
322
+ plt.xlabel("Quantity")
323
+ plt.ylabel("Price")
324
+ plt.xlim(0, 50) # Fixed quantity range from 0 to 100
325
+ plt.ylim(0, max(demandPrices)) # Set y-limits based on demand prices
326
+ plt.legend()
327
+ plt.grid(True)
328
+
329
+ # Display plot
330
+ plt.show()
331
+
332
+ # Print equilibrium information
333
+ print(f"The equilibrium price is {round(float(equilibriumP), 2)} and equilibrium quantity is {round(float(equilibriumQ), 2)}.")
334
+ print(f"The consumer surplus at this equilibrium is {(demandFunc(0) - equilibriumP) * equilibriumQ * 0.5}")
335
+ print(f"The producer surplus at this equilibrium is {(equilibriumP * equilibriumQ) * 0.5}")
336
+
337
+ # Example usage
338
+ Equilibrium(demandParam=50, supplyParam=20)
339
+ ```
340
+
341
+ ```python
342
+ import sympy
343
+ import matplotlib.pyplot as plt
344
+ import matplotlib.patches as patches
345
+ p = sympy.Symbol("p")
346
+ def Equilibrium(demandParam, supplyParam, priceStart):
347
+ demandEquation = demandParam - p
348
+ # change the slope
349
+ supplyEquation = p * (supplyParam/10)
350
+ priceEnd = sympy.solve(demandEquation)[0]
351
+ prices = []
352
+ demandQ = []
353
+ supplyQ = []
354
+ for price in range(priceStart,priceEnd+1):
355
+ prices += [price]
356
+ demandQ += [demandEquation.subs(p,price)]
357
+ supplyQ += [supplyEquation.subs(p,price)]
358
+
359
+ equilibriumP = sympy.solve(demandEquation-supplyEquation)[0]
360
+ equilibriumQ = demandEquation.subs(p,equilibriumP)
361
+
362
+
363
+
364
+ triangle1 = patches.Polygon([[equilibriumQ,equilibriumP],[0,equilibriumP],[0,priceEnd]],True,color="green")
365
+ triangle2 = patches.Polygon([[equilibriumQ,equilibriumP],[0,equilibriumP],[0,0]],True,color="red")
366
+ currentAxis = plt.gca()
367
+ currentAxis.add_patch(triangle1)
368
+ currentAxis.add_patch(triangle2)
369
+
370
+ plt.plot(demandQ,prices)
371
+ plt.plot(supplyQ,prices)
372
+ plt.legend(["Demand","Supply"])
373
+ plt.plot(equilibriumQ,equilibriumP, 'ro')
374
+ plt.xlabel("Supply and Demand Quantity")
375
+ plt.ylabel("Price")
376
+ plt.ylim(0, 15)
377
+ plt.xlim(0, 10)
378
+ plt.show()
379
+ print("The equilibrium price is "+str(round(equilibriumP,2))+" and equilibrium quantity is "+str(round(equilibriumQ,2))+".")
380
+ print("The consumer surplus at this equilibrium "+str((priceEnd-equilibriumP)*(equilibriumQ)*.5))
381
+ print("The producer surplus at this equilibrium "+str((equilibriumP)*(equilibriumQ)*.5))
382
+
383
+
384
+ # you can change the range here
385
+ slider1 = widgets.IntSlider(min=5, max=15,step=1,value=10, description="Demand Intercept")
386
+ slider2 = widgets.IntSlider(min=1, max=20,step=1,value=10, description="Supply Slope")
387
+ slider3 = widgets.IntSlider(min=-5, max=5,step=1,value=0)
388
+
389
+ # Add additional text using widgets.Label or widgets.HTML
390
+ text_before = widgets.HTML(
391
+ value="<h3>Equilibrium Simulation</h3><p>This interactive simulation allows you to explore the equilibrium price and quantity based on different demand and supply parameters.</p>"
392
+ )
393
+
394
+ text_after = widgets.HTML(
395
+ value="<p>Adjust the <b>Demand Param</b> and <b>Supply Param</b> sliders to change the shape of the curves, and observe how the equilibrium changes.</p>"
396
+ )
397
+
398
+ # Display all elements together
399
+ ui = widgets.VBox([text_before, slider1, slider2, slider3, text_after])
400
+ out = widgets.interactive_output(Equilibrium, {'demandParam': slider1, 'supplyParam': slider2, 'priceStart': slider3})
401
+
402
+ display(ui, out)
403
+ ```
404
+
405
+ ## Effects of Taxes
406
+
407
+ ```python
408
+ def eqSolve(eq1,eq2,tax):
409
+ demandP = sympy.solve(eq1-q,p)[0]
410
+ supplyP = sympy.solve(eq2-q,p)[0]
411
+ demandP = demandP-cTax
412
+ supplyP = supplyP+pTax
413
+
414
+ demandQ = sympy.solve(demandP-p,q)[0]
415
+ supplyQ = sympy.solve(supplyP-p,q)[0]
416
+
417
+ return sympy.solve((demandP-supplyP, demandQ-supplyQ,tax-cTax-pTax), q,p,cTax,pTax)[q]
418
+ ```
419
+
420
+ ```python
421
+
422
+ p = sympy.Symbol("p")
423
+ q = sympy.Symbol("q")
424
+ cTax = sympy.Symbol("cTax")
425
+ pTax = sympy.Symbol("pTax")
426
+
427
+ def EquilibriumTax(demandParam,supplyParam,priceStart,priceEnd,tax):
428
+ demandEquation = demandParam - p
429
+ supplyEquation = p * (supplyParam/10)
430
+ prices = []
431
+ demand = []
432
+ supply = []
433
+ for price in range(priceStart,priceEnd+1):
434
+ prices += [price]
435
+ demand += [demandEquation.subs(p,price)]
436
+ supply += [supplyEquation.subs(p,price)]
437
+
438
+
439
+
440
+ nonTaxPrice = sympy.solve(demandEquation-supplyEquation)[0]
441
+ nonTaxQ = demandEquation.subs(p,nonTaxPrice)
442
+
443
+
444
+ equilibriumQ = eqSolve(demandEquation,supplyEquation,tax)
445
+ equilibriumP1 = sympy.solve(demandEquation-equilibriumQ)[0]
446
+ equilibriumP2 = sympy.solve(supplyEquation-equilibriumQ)[0]
447
+
448
+ triangle1 = patches.Polygon([[nonTaxQ,nonTaxPrice],[equilibriumQ,nonTaxPrice],[equilibriumQ,equilibriumP1]],True,color="green")
449
+ triangle2 = patches.Polygon([[nonTaxQ,nonTaxPrice],[equilibriumQ,nonTaxPrice],[equilibriumQ,equilibriumP2]],True)
450
+ currentAxis = plt.gca()
451
+ currentAxis.add_patch(triangle1)
452
+ currentAxis.add_patch(triangle2)
453
+
454
+
455
+ rect1 = patches.Rectangle((0,nonTaxPrice),equilibriumQ,equilibriumP1-nonTaxPrice,linewidth=1,facecolor="red")
456
+ rect2 = patches.Rectangle((0,nonTaxPrice),equilibriumQ,equilibriumP2-nonTaxPrice,linewidth=1,facecolor="yellow")
457
+ currentAxis.add_patch(rect1)
458
+ currentAxis.add_patch(rect2)
459
+
460
+ plt.plot(demand,prices)
461
+ plt.plot(supply,prices)
462
+
463
+
464
+ plt.legend([rect1,rect2,triangle1,triangle2], ["Consumer Tax","Producer Tax","Consumer Deadweight Loss","Producer Deadweight Loss"])
465
+ plt.plot(equilibriumQ,equilibriumP1, 'ro')
466
+ plt.plot(equilibriumQ,equilibriumP2, 'ro')
467
+ plt.xlabel("Supply and Demand Quantity")
468
+ plt.ylabel("Price")
469
+ plt.ylim(0, 15)
470
+ plt.xlim(0, 10)
471
+ plt.show()
472
+ print("Without Tax - the equilibrium price is "+str(round(nonTaxPrice,2))+" and equilibrium quantity is "+str(round(nonTaxQ,2)))
473
+ print("With Tax - Price paid by consumers is "+str(equilibriumP1)+" Price received by suppliers is "+str(round(equilibriumP2,2))+" and equilibrium quantity is "+str(equilibriumQ)+".")
474
+ print("Taxes raised from consumers equals "+str(round(equilibriumQ*(equilibriumP1-nonTaxPrice),2)))
475
+ print("Taxes raised from producers equals "+str(round(equilibriumQ*(nonTaxPrice-equilibriumP2),2)))
476
+ print("Total taxes raised equals "+str(equilibriumQ*tax))
477
+
478
+ slider1 = widgets.IntSlider(min=5, max=15,step=1,value=10)
479
+ slider2 = widgets.IntSlider(min=1, max=20,step=1,value=10)
480
+ slider3 = widgets.IntSlider(min=-5, max=5,step=1,value=0)
481
+ slider4 = widgets.IntSlider(min=5, max=20,step=1,value=10)
482
+ slider5 = widgets.IntSlider(min=0, max=8,step=1,value=4)
483
+ display(widgets.interactive(EquilibriumTax, demandParam=slider1, supplyParam=slider2, priceStart=slider3, priceEnd=slider4, tax=slider5))
484
+ ```
485
+
486
+ ## Shifts in Demand and Supply and Incidence of Tax
487
+ In this graph the second line with the suppply plus tax is not graphed but the new equilibrium point is.
488
+
489
+ ## Question 3.1 - Demand Shift - Intercept Slider
490
+ Shift the Demand Parameter - This slider is only shifting the intercept which leads to a parrallel shift in Demand. What happens to the amount of tax paid as demand shifts out. What happens to the ratio of tax paid from Consumer Surplus to Producer Surplus?
491
+
492
+ .... Type your answer in here
493
+
494
+ ## Question 3.2 - Supply Shift - Slope Slider
495
+ Shift the Supply Parameter - This slider is shifting the slope which leads to a change in the steepness of the Supply curve. What happens to the amount of Consumer Surplus as supply becomes steeper? What happens to the tax incidence - the ratio of tax coming from Consumer Surplus vs. Producer Surplus?
496
+
497
+ .... Type your answer in here
498
+
499
+ ## Question 3.3 - Tax Shift -
500
+ Shift the Tax Parameter - This slider is increasing or decreasing the amount of tax.
501
+
502
+ Is it affecting the slope or the intercept?
503
+
504
+ An increase in tax leads to and increase in the price paid by consumers. In this case how much does a given tax lead to an increase in price?
505
+
506
+
507
+ When shifting the tax alone - how does the incidence of tax between producers and consumers change?
508
+
509
+ .... Type your answer in here
510
+
511
+
512
+
513
+
514
+
@@ -0,0 +1,34 @@
1
+ ---
2
+ title: "lec04-four-plot-24"
3
+ type: lecture-notebook
4
+ week: 4
5
+ source_path: "/Users/ericvandusen/Documents/Data88E-ForTraining/F24Lec_NBs/lec04/lec04-four-plot-24.ipynb"
6
+ ---
7
+
8
+ <!--
9
+ https://pressbooks.bccampus.ca/uvicecon103/chapter/4-7-tariffs/
10
+ -->
11
+
12
+ <table style="width: 100%;" id="nb-header">
13
+ <tr style="background-color: transparent;"><td>
14
+ <img src="https://data-88e.github.io/assets/images/blue_text.png" width="250px" style="margin-left: 0;" />
15
+ </td><td>
16
+ <p style="text-align: right; font-size: 10pt;"><strong>Economic Models</strong>, EdX<br>
17
+ Dr. Eric Van Dusen <br>
18
+ Chris Pyles <br>
19
+ </table>
20
+
21
+ # Lecture Notebook 4 - Tariffs: Four Plot
22
+
23
+ Play around with the sliders below to better understand how each of the variables are related!
24
+
25
+ ```python
26
+ from utils24 import *
27
+ ```
28
+
29
+ ```python
30
+ four_plot_widget()
31
+ ```
32
+
33
+
34
+
@@ -0,0 +1,34 @@
1
+ ---
2
+ title: "lec04-four-plot"
3
+ type: lecture-notebook
4
+ week: 4
5
+ source_path: "/Users/ericvandusen/Documents/Data88E-ForTraining/F24Lec_NBs/lec04/lec04-four-plot.ipynb"
6
+ ---
7
+
8
+ <!--
9
+ https://pressbooks.bccampus.ca/uvicecon103/chapter/4-7-tariffs/
10
+ -->
11
+
12
+ <table style="width: 100%;" id="nb-header">
13
+ <tr style="background-color: transparent;"><td>
14
+ <img src="https://data-88e.github.io/assets/images/blue_text.png" width="250px" style="margin-left: 0;" />
15
+ </td><td>
16
+ <p style="text-align: right; font-size: 10pt;"><strong>Economic Models</strong>, EdX<br>
17
+ Dr. Eric Van Dusen <br>
18
+ Chris Pyles <br>
19
+ </table>
20
+
21
+ # Lecture Notebook 4 - Tariffs: Four Plot
22
+
23
+ Play around with the sliders below to better understand how each of the variables are related!
24
+
25
+ ```python
26
+ from utils import *
27
+ ```
28
+
29
+ ```python
30
+ four_plot_widget()
31
+ ```
32
+
33
+
34
+