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,203 @@
1
+ ---
2
+ title: 01-supply
3
+ type: textbook
4
+ source_path: content/02-supply/01-supply.ipynb
5
+ chapter: 2
6
+ ---
7
+
8
+ ```python
9
+ from datascience import *
10
+ import matplotlib.pyplot as plt
11
+ %matplotlib inline
12
+ import numpy as np
13
+ import pandas as pd
14
+ from utils import *
15
+ plt.style.use('seaborn-v0_8-muted')
16
+ from matplotlib import patches
17
+ from csaps import csaps
18
+ import warnings
19
+ warnings.filterwarnings("ignore")
20
+ ```
21
+
22
+ # The Supply Curve
23
+
24
+ The supply of a commodity refers to the quantity for which producers or sellers are willing to produce and offer for sale, at a particular price in some given period of time. To answer questions like _"at a given price, what will be the supply of a good in the market?"_, we need to know the market supply curve. A supply curve is simply a curve (or graph) which shows the quantites of a good that can be produced and the prices they will be sold at.
25
+
26
+ It is good to discern between individual and market supply. **Individual supply** refers to the supply offered by a single firm or producer, while **market supply** refers to the supply offered by all the firms or producers in a market. It is the horizontal summation of the individual supply curves in the market.
27
+
28
+ The following table and graph will give an example of a market with two firms: A and B.
29
+
30
+ [Following image is a graph of horizontal supply addition]
31
+
32
+ ```python
33
+ market_supply = Table().with_columns(
34
+ "Price", make_array(2, 3, 4),
35
+ "Quantity supplied by A", make_array(20, 30, 40),
36
+ "Quantity supplied by B", make_array(30, 40, 50),
37
+ "Market Supply", make_array(50, 70, 90)
38
+ )
39
+ market_supply
40
+ ```
41
+
42
+ ```python
43
+ plt.figure(figsize=[7,7])
44
+ plt.plot(market_supply.column(1), market_supply.column(0), marker='o')
45
+ plt.plot(market_supply.column(2), market_supply.column(0), marker='^', color="#049348")
46
+ plt.plot(market_supply.column(3), market_supply.column(0), marker='*', color="red")
47
+ plt.xlabel('Quantity')
48
+ plt.ylabel('Price')
49
+ plt.title('Market Supply')
50
+ plt.legend(make_array("Quantity supplied by A","Quantity supplied by B","Market Supply"), bbox_to_anchor=(1.04,1), loc="center left")
51
+
52
+ plt.show()
53
+ ```
54
+
55
+ Market behavior relating to supply is based on the behavior of the individual firms that comprise it. Now, how does an individual firm make its decision about production? It does so based on the costs associated with production. If the price of a good is enough to recover the costs, the firm produces. Generally, costs increase with the quantity of production. So, to induce producers to increase the quantity supplied, the market prices need to be high enough to compensate for the increased costs.
56
+
57
+ ## Costs
58
+
59
+ We will split costs into two categories: fixed costs and variable costs.
60
+
61
+ ```{admonition} Definition
62
+ **Fixed costs** are costs associated with fixed factors (or inputs) of production. For example, land for a factory, capital equipment like machinery, etc. The quantity of these inputs cannot be changed quickly in the short term. A factory owner cannot purchase land quickly enough to ramp up production in a week. A key point to note is that fixed costs are irrespective of the quantity, i.e., they do not change with the quantity produced.
63
+
64
+ **Variable costs** are costs associated with variable factors (or inputs) of production. For example, labor, raw materials, etc. The quantity of these inputs can be changed quickly in the short term to adjust supply. A factory owner can hire more laborers or purchase more raw material to increase output. Variable costs change as the supply changes.
65
+ ```
66
+
67
+ Another important cost calculation to consider is the marginal cost.
68
+
69
+ ```{admonition} Definition
70
+ The **marginal cost** is the additional cost to produce one more unit of output. It can be calculated as the difference between the total cost and the current level of output and the total cost at the previous level of output.
71
+ ```
72
+
73
+ Below is a table with the following costs incurred by the firm:
74
+
75
+ * **Output:** Units produced and supplied
76
+ * **Total Fixed Cost (TFC):** Cost incurred by firm on usage of all fixed factors.
77
+ * **Total Variable Cost (TVC):** Cost incurred by firm on usage of all variable factors.
78
+ * **Total Cost (TC):** Sum of the total fixed and variable costs.
79
+ * **Marginal Cost (MC)**
80
+ * **Average Fixed Cost (AFC):** Cost per unit of fixed factors. It can be calculated as the Total Fixed Cost divided by the corresponding output level.
81
+ * **Average Variable Cost (AVC):** Cost per unit of variable factors. It can be calculated as the Total Variable Cost divided by the corresponding output level.
82
+ * **Average Total Cost (ATC):** Total cost per unit. This is the sum of the Average Fixed Cost and the Average Variable Cost.
83
+
84
+ ```python
85
+ individual_firm_costs = Table.read_table('supply_textbook.csv')
86
+ individual_firm_costs.show()
87
+ ```
88
+
89
+ Let's create some visualizations to understand the relationships of the different cost curves.
90
+
91
+ [Following image is a graph of Total, Fixed and Variable Costs]
92
+
93
+ ```python
94
+ plt.figure(figsize=[7,7])
95
+ plt.plot(individual_firm_costs.column("Output"), individual_firm_costs.column("Total Fixed Cost"), marker='o')
96
+ plt.plot(individual_firm_costs.column("Output"), individual_firm_costs.column("Total Variable Cost"), marker='^', color="#049348")
97
+ plt.plot(individual_firm_costs.column("Output"), individual_firm_costs.column("Total Cost"), marker='*', color="red")
98
+ plt.xlabel('Quantity')
99
+ plt.ylabel('Cost')
100
+ plt.title('TFC, TVC and TC')
101
+ plt.legend(make_array("Total Fixed Cost","Total Variable Cost","Total Cost"))
102
+
103
+ plt.show()
104
+ ```
105
+
106
+ There are two important things to notice about the graph above. First, the total fixed cost is flat. This is because the fixed cost does not change regardless of quantity produced. Second, the vertical difference between the total variable cost and total cost is the TFC. This is because $\text{TC} = \text{TVC} + \text{TFC}$.
107
+
108
+ [Following image is a graph of Average Total, Fixed, and Variable Costs]
109
+
110
+ ```python
111
+ plt.figure(figsize=[7,7])
112
+ plt.plot(individual_firm_costs.column("Output")[1:], individual_firm_costs.column("Average Fixed Cost")[1:], marker='o')
113
+ plt.plot(individual_firm_costs.column("Output")[1:], individual_firm_costs.column("Average Variable Cost")[1:], marker='^', color="#049348")
114
+ plt.plot(individual_firm_costs.column("Output")[1:], individual_firm_costs.column("Average Total Cost")[1:], marker='*', color="red")
115
+ plt.xlabel('Quantity')
116
+ plt.ylabel('Cost')
117
+ plt.title('AFC, AVC and ATC')
118
+ plt.legend(make_array("Average Fixed Cost","Average Variable Cost","Average Total Cost"))
119
+
120
+ plt.show()
121
+ ```
122
+
123
+ From the graph above, note that:
124
+
125
+ - The average fixed cost is decreasing throughout. This is because at higher levels of production, the fixed cost is divided across more units. This implies that the difference between the ATC and AVC decreases as we increase production, since $\text{ATC} = \text{AVC} + \text{AFC}$.
126
+ - The AVC and ATC slope down initially and then slope up. This represents decreasing and then increasing marginal cost. Marginal cost initially decreases due to efficiencies in producing at scale, but then increases due to the law of variable proportions.
127
+
128
+ Now let's introduce the marginal cost curve:
129
+
130
+ [Following image is a graph of Average Total and Variable Cost and Marginal Cost]
131
+
132
+ ```python
133
+ output = individual_firm_costs.column("Output")[1:]
134
+ mc = individual_firm_costs.column("Marginal Cost")[1:]
135
+ avc = individual_firm_costs.column("Average Variable Cost")[1:]
136
+ atc = individual_firm_costs.column("Average Total Cost")[1:]
137
+
138
+ sp_mc = csaps(output, mc, smooth=0.85) #slightly different command
139
+ sp_avc = csaps(output, avc, smooth=0.85)
140
+ sp_atc = csaps(output, atc, smooth=0.85)
141
+
142
+ output_s = np.linspace(output.min(), output.max(), 150)
143
+ mc_s = sp_mc(output_s)
144
+ avc_s = sp_avc(output_s)
145
+ atc_s = sp_atc(output_s)
146
+
147
+ plt.figure(figsize=[7,7])
148
+ plt.plot(output, mc, marker = 'o', color = 'tab:blue')
149
+ plt.plot(output_s, mc_s, alpha=0.7, lw = 2, label='_nolegend_', color = 'tab:blue')
150
+ plt.plot(output, avc, marker = '^', color = '#2D8A3E')
151
+ plt.plot(output_s, avc_s, alpha=0.7, lw = 2, label='_nolegend_', color = '#2D8A3E')
152
+ plt.plot(output, atc, marker = '*', color = '#CB7432')
153
+ plt.plot(output_s, atc_s, alpha=0.7, lw = 2, label='_nolegend_', color = '#CB7432')
154
+ plt.hlines(y=min(avc), xmin = 6, xmax = 8, lw=3, color='b', zorder = 10)
155
+ plt.hlines(y=min(atc), xmin = 7.5, xmax = 9.5, lw=3, color='b', zorder = 10)
156
+ plt.xlabel('Quantity')
157
+ plt.ylabel('Cost')
158
+ plt.title('MC, AVC and ATC')
159
+ plt.legend(make_array("Marginal Cost","Average Variable Cost","Average Total Cost"))
160
+
161
+ plt.show()
162
+ ```
163
+
164
+ Notice that the MC curve intersects the ATC and AVC curves at their minima. This is because when MC is below the AVC and ATC, it brings down the average since it costs less to produce an additional unit. But as MC begins to increase and surpasses the ATC and AVC cost curves, it will surpass the intersection, and pulls up the AVC and ATC curves. Therefore, it intersects at the minima.
165
+
166
+ ## Production and Firm Behavior
167
+
168
+ A company decides to produce if the price is greater than or equal to its average variable cost. There are 3 different scenarios:
169
+
170
+ - A firm does not produce at all
171
+ - It produces at a loss-minimizing quantity
172
+ - It produces at a profit
173
+
174
+ Profits are calculated as total revenue minus total costs, where total revenue is price times quantity. For any price that is less than AVC, the firm will not produce at all. This is because for any amount of production, they will lose money. In this case, they shut down and the loss is limited to its fixed costs. In this example, we can see this for prices 24 and below.
175
+
176
+ [Following image is a graph of Average Total, Fixed, and Marginal Costs and a price line]
177
+
178
+ ```python
179
+ firm_behaviour(24, individual_firm_costs)
180
+ ```
181
+
182
+ For any price that lies above the AVC curve but below the ATC curve, the firm will produce at a loss-minimising quantity. This is because for some levels of production, they will make revenue that is more than the total variable cost of production but is still less than the total cost, which includes the fixed cost. While they still lose money, they have offset some of the losses they would have incurred from the fixed cost. In our example, we see this for prices between 25 and 31. The red patch in the plot shows the loss.
183
+
184
+ [Following image is a graph of Average Total, Fixed, and Variable Costs with a loss]
185
+
186
+ ```python
187
+ firm_behaviour(28, individual_firm_costs)
188
+ ```
189
+
190
+ If the price is above the ATC curve, the firm produces at a profit. In this example, it is at prices 32 and above. The green patch shows the profit.
191
+
192
+ [Following image is a graph of Average Total, Fixed, and Variable Costs with a profit]
193
+
194
+ ```python
195
+ firm_behaviour(36, individual_firm_costs)
196
+ ```
197
+
198
+ So, we have seen that a firm produces if the price is above the AVC. The question now is: what is the level of production?
199
+
200
+ A profit-maximising firm will produce until price is less than or equal to marginal cost. In the above example, the firm produces 8 units. At the 8th unit, the marginal cost to produce that unit is 28, which is less than the price of 36. Thus the firm gets more revenue for the 8th unit than the cost to produce that unit. But the 9th unit costs an additional 38 to produce. The price of 36 is not enough to cover it. Thus it does not produce the 9th unit.
201
+
202
+ Therefore, based on the price, each firm looks at its costs and makes a decision to produce. At low prices, only the firms with the lowest production costs produce. As the price increases, firms with higher production costs find it feasible to produce and begin to supply. Thus, the market supply rises with higher prices. Firms with lower costs make extra profits.
203
+
@@ -0,0 +1,86 @@
1
+ ---
2
+ title: 02-eep147-example
3
+ type: textbook
4
+ source_path: content/02-supply/02-eep147-example.ipynb
5
+ chapter: 2
6
+ ---
7
+
8
+ ```python
9
+ from datascience import *
10
+ import matplotlib.pyplot as plt
11
+ %matplotlib inline
12
+ import numpy as np
13
+ import pandas as pd
14
+ from utils import *
15
+ plt.style.use('seaborn-muted')
16
+ from matplotlib import patches
17
+ import csaps
18
+ import warnings
19
+ warnings.filterwarnings("ignore")
20
+ ```
21
+
22
+ # An Empirical Example from EEP 147
23
+
24
+ Let's take a look at an empirical example of production. The dataset for this section comes from EEP 147: Regulation of Energy and the Environment.
25
+
26
+ ```python
27
+ ESG_table = Table.read_table('ESGPorfolios_forcsv.csv').select(
28
+ "Group", "Group_num", "UNIT NAME", "Capacity_MW", "Total_Var_Cost_USDperMWH"
29
+ ).sort("Total_Var_Cost_USDperMWH", descending = False).relabel(4, "Average Variable Cost")
30
+ ESG_table
31
+ ```
32
+
33
+ This table shows some electricity generation plants in California and their costs. The `Capacity` is the output the firm is capable of producing. The `Average Variable Cost` shows the minimum variable cost per megawatt (MW) produced. At a price below AVC, the firm supplies nothing. At a price above the AVC, the firm can supply up to its capacity. Being a profit-maximising firm, it will try to supply its full capacity.
34
+
35
+ First, lets look at just the Big Coal producers and understand this firm's particular behavior.
36
+
37
+ [Following image is a bar graph of 6 power plants ]
38
+
39
+ ```python
40
+ selection = 'Big Coal'
41
+ Group = ESG_table.where("Group", are.equal_to(selection))
42
+ Group
43
+ ```
44
+
45
+ ```python
46
+ # Make the plot
47
+ plt.figure(figsize=(9,6))
48
+ plt.bar(new_x_group, height_group, width=width_group, edgecolor = "black")
49
+ # Add title and axis names
50
+ plt.title(selection)
51
+ plt.xlabel('Capacity_MW')
52
+ plt.ylabel('Variable Cost/Price')
53
+
54
+ plt.show()
55
+ ```
56
+
57
+ We have created the Big Coal supply curve. It shows the price of electricity, and the quantity supplied at those prices, which depends on variable cost. For example, at any variable cost equal to or above 36.5, the producer `FOUR CORNERS` (the one with the lowest production costs) will supply, and so on. Notably, we observe that the supply curve is also upward sloping since we need higher prices to entice producers with higher variasble costs to produce.
58
+
59
+ [Following image is a bar graph of 6 power plants with a price line]
60
+
61
+ ```python
62
+ group_plot(30)
63
+ ```
64
+
65
+ ```python
66
+ group_plot(37)
67
+ ```
68
+
69
+ ```python
70
+ group_plot(50)
71
+ ```
72
+
73
+ Now we will look at all the energy sources. They have been colored according to source for reference.
74
+
75
+ [Following image is a bar graph of all power plants in all portfilios ]
76
+
77
+ ```python
78
+ ESG_plot(30)
79
+ ```
80
+
81
+ ```python
82
+ ESG_plot(50)
83
+ ```
84
+
85
+ Look at the thin bars concentrated on the right end of the plot. These are plants with small capacities and high variable costs. Conversely, plants with larger capacities tend to have lower variable costs. Why might this be the case? Electricity production typically benefits from economies of scale: it is cheaper per unit when producing more units. Perhaps the high fixed cost required for electricity production, such as for equipment and land, is the reason behind this phenomenon.
86
+
@@ -0,0 +1,138 @@
1
+ ---
2
+ title: 03-sympy
3
+ type: textbook
4
+ source_path: content/02-supply/03-sympy.ipynb
5
+ chapter: 2
6
+ ---
7
+
8
+ # SymPy
9
+
10
+ ```python
11
+ from datascience import *
12
+ import numpy as np
13
+ from sympy import *
14
+ import sympy
15
+ init_printing()
16
+ import matplotlib.pyplot as plt
17
+ %matplotlib inline
18
+ solve = lambda x,y: sympy.solve(x-y)[0] if len(sympy.solve(x-y))==1 else "Not Single Solution"
19
+ ```
20
+
21
+ Python has many tools, such as the [SymPy library](https://docs.sympy.org/latest/tutorial/index.html) that we can use for expressing and evaluating formulas and functions in economics.
22
+
23
+ Since SymPy helps with symbolic math, we start out by create a symbol using `Symbol`, which we assign to a variable name. Then, we can use the symbols to construct symbolic expressions.
24
+
25
+ ```python
26
+ x = Symbol('x')
27
+ x
28
+ ```
29
+
30
+ Now let's try using SymPy to create a symbolic expression for some hypothetical supply and demand curves.
31
+
32
+ To define an upward sloping supply curve with price expressed as a function of quantity, we start off defining the symbol $Q$, which represents quantity. Then, we set up a negative relationship expressing $P_S$, which denotes the price of the supplied good (how much the producer earns), in terms of $Q$.
33
+
34
+ ```python
35
+ Q = Symbol('Q')
36
+ P_S = 2 * Q - 3
37
+ P_S
38
+ ```
39
+
40
+ Similarly, we will also use $Q$ to express a relationship with $P_D$, the price of the good purchased (how much the consumer pays), creating a downward sloping demand curve.
41
+
42
+ Note that both functions are of the variable $Q$; this will be important in allowing us to solve for the equilibrium.
43
+
44
+ ```python
45
+ P_D = 2 - Q
46
+ P_D
47
+ ```
48
+
49
+ To solve for the equilibrium given the supply and demand curve, we know that the price paid by consumers must equal to the price earned by suppliers. Thus, $P_D = P_S$, allowing us to set the two equations equal to each other and solve for the equilibrium quantity and thus equilibrium price. To solve this by hand, we would set up the following equation to solve for $Q$:
50
+
51
+ $$
52
+ P_D = P_S\\
53
+ 2-Q = 2Q-3
54
+ $$
55
+
56
+ Using SymPy, we call `solve`, which takes in 2 arguments that represent the 2 sides of an equation and solves for the underlying variable such that the equation holds. Here, we pass in $P_D$ and $P_S$, both represented in terms of $Q$, to solve for the value of $Q$ such that $P_D=P_S$. It's good to know that `solve` is a custom function built for this class, and will be provided in the notebooks for you.
57
+
58
+ ```python
59
+ Q_star = solve(P_D, P_S)
60
+ Q_star
61
+ ```
62
+
63
+ The value of $Q$ that equates $P_D$ and $P_S$ is known as the market equilibrium quantity, and we denote it as $Q^*$. Here, $Q^* = \frac{5}{3}$.
64
+
65
+ With $Q^*$ determined, we can substitute this value as $Q$ to thus calculate $P_D$ or $P_S$. We substitute values using the `subs` function, which follows the syntax `expression.subs(symbol_we_want_to_substitute, value_to_substitute_with)`.
66
+
67
+ ```python
68
+ P_D.subs(Q, Q_star)
69
+ ```
70
+
71
+ We can also substitute $Q^*$ into $P_S$, and should get the same results.
72
+
73
+ ```python
74
+ P_S.subs(Q, Q_star)
75
+ ```
76
+
77
+ Thus, the equilibrium price and quantity are \$0.33 and $\frac{5}{3}$, respectively.
78
+
79
+ Let's try another example. Suppose our demand function is $\text{Price}_{D}=-2 \cdot \text{Quantity} + 10$. Using SymPy, this would be
80
+
81
+ ```python
82
+ demand = -2 * Q + 10
83
+ demand
84
+ ```
85
+
86
+ In addition, let the supply function be $\text{Price}_{S}=3 \cdot \text{Quantity} + 1$. Using SymPy, this would be
87
+
88
+ ```python
89
+ supply = 3 * Q + 1
90
+ supply
91
+ ```
92
+
93
+ We will now try to find the market equilibrium. The market price equilibrium $P^*$ is the price at which the quantity supplied and quantity demanded of a good or service are equal to each other. Similarly, the market quantity equilibrium $Q^*$ is the quantity at which the price paid by consumers is equal to the price received by producers.
94
+
95
+ Combined, the price equilibrium and quantity equilibrium form a point on the graph with quantity and price as its axes, called the equilibrium point. This point is the point at which the demand and supply curves intersect.
96
+
97
+ First, we solve for the quantity equilibrium.
98
+
99
+ ```python
100
+ Q_star = solve(demand, supply)
101
+ Q_star
102
+ ```
103
+
104
+ Next, we plug the quantity equilibrium into our demand or supply expression to get the price equilibrium:
105
+
106
+ ```python
107
+ demand.subs(Q, 9/5)
108
+ ```
109
+
110
+ Graphically, we can plot the supply and demand curves with quantity on the $x$ axis and price on the $y$ axis. The point at which they intersect is the equilibrium point.
111
+
112
+ [Following image is a graph with lines for supply and demand intersecting ]
113
+
114
+ ```python
115
+ def plot_equation(equation, price_start, price_end, label=None, color=None, linestyle=None):
116
+ plot_prices = [price_start, price_end]
117
+ plot_quantities = [equation.subs(list(equation.free_symbols)[0], c) for c in plot_prices]
118
+ plt.plot(plot_prices, plot_quantities, label=label, color=color, linestyle=linestyle)
119
+
120
+ def plot_intercept(eq1, eq2):
121
+ ex = sympy.solve(eq1-eq2)[0]
122
+ why = eq1.subs(list(eq1.free_symbols)[0], ex)
123
+ plt.scatter([ex], [why], color='black', label="Equilibrium")
124
+ return (ex, why)
125
+
126
+ plot_equation(demand, 0, 5, label="Demand")
127
+ plot_equation(supply, 0, 5, label="Supply", color="#CB7432", linestyle="dashed")
128
+ equilibrium = plot_intercept(supply, demand)
129
+ plt.legend()
130
+ plt.ylim(0,20)
131
+ plt.xlabel("Quantity")
132
+ plt.ylabel("Price")
133
+ plot_intercept(supply, demand);
134
+ ```
135
+
136
+ ```python
137
+
138
+ ```
@@ -0,0 +1,204 @@
1
+ ---
2
+ title: 04-market-equilibria
3
+ type: textbook
4
+ source_path: content/02-supply/04-market-equilibria.ipynb
5
+ chapter: 2
6
+ ---
7
+
8
+ ```python
9
+ from datascience import *
10
+
11
+ import sympy
12
+ import matplotlib.pyplot as plt
13
+ import matplotlib as mpl
14
+ import matplotlib.patches as patches
15
+ # plt.style.use('seaborn-muted')
16
+ mpl.rcParams['figure.dpi'] = 200
17
+ %matplotlib inline
18
+
19
+ from IPython.display import display
20
+ import numpy as np
21
+ import pandas as pd
22
+ solve = lambda x,y: sympy.solve(x-y)[0] if len(sympy.solve(x-y))==1 else "Not Single Solution"
23
+
24
+ import warnings
25
+ warnings.filterwarnings('ignore')
26
+ ```
27
+
28
+ # Market Equilibria
29
+
30
+ We will now explore the relationship between price and quantity of oranges produced between 1924 and 1938. Since the data {cite}`01demand-fruits` is from the 1920s and 1930s, it is important to remember that the prices are much lower than what they would be today because of inflation, competition, innovations, and other factors. For example, in 1924, a ton of oranges would have costed \$6.63; that same amount in 2019 is \$100.78.
31
+
32
+ ```python
33
+ fruitprice = Table.read_table('fruitprice.csv')
34
+ fruitprice
35
+ ```
36
+
37
+ ## Finding the Equilibrium
38
+
39
+ An important concept in econmics is the market equilibrium. This is the point at which the demand and supply curves meet and represents the "optimal" level of production and price in that market.
40
+
41
+ ```{admonition} Definition
42
+ The **market equilibrium** is the price and quantity at which the demand and supply curves intersect. The price and resulting transaction quantity at the equilibrium is what we would predict to observe in the market.
43
+ ```
44
+
45
+ Let's walk through how to the market equilibrium using the market for oranges as an example.
46
+
47
+ ### Data Preprocessing
48
+
49
+ Because we are only examining the relationship between prices and quantity for oranges, we can create a new table with the relevant columns: `Year`, `Orange Price`, and `Orange Unloads`. Here, `Orange Price` is measured in dollars, while `Orange Unloads` is measured in tons.
50
+
51
+ ```python
52
+ oranges_raw = fruitprice.select("Year", "Orange Price", "Orange Unloads")
53
+ oranges_raw
54
+ ```
55
+
56
+ Next, we will rename our columns. In this case, let's rename `Orange Unloads` to `Quantity` and `Orange Price` to `Price` for brevity and understandability.
57
+
58
+ ```python
59
+ oranges = oranges_raw.relabel("Orange Unloads", "Quantity").relabel("Orange Price", "Price")
60
+ oranges
61
+ ```
62
+
63
+ ### Visualize the Relationship
64
+
65
+ Let's first take a look to see what the relationship between price and quantity is. We would expect to see a downward-sloping relationship between price and quantity; if a product's price increases, consumers will purchase less, and if a product's price decreases, then consumers will purchase more.
66
+
67
+ We will create a scatterplot between the points.
68
+
69
+ [Following image is a scatter plot for demand for oranges]
70
+
71
+ ```python
72
+ oranges.scatter("Quantity", "Price", width=5, height=5)
73
+ plt.title("Demand Curve for Oranges", fontsize = 16);
74
+ ```
75
+
76
+ The visualization shows a negative relationship between quantity and price, which is in line with our expectations: as the price increases, fewer consumers will purchase oranges, so the quantity demanded will decrease. This corresponds to a leftward movement along the demand curve. Alternatively, as the price decreases, the quantity sold will increase because consumers want to maximize their purchasing power and buy more oranges; this is shown by a rightward movement along the curve.
77
+
78
+ ### Fit a Polynomial
79
+
80
+ We will now quantify our demand curve using NumPy's [`np.polyfit` function](https://numpy.org/doc/stable/reference/generated/numpy.polyfit.html). Recall that `np.polyfit` returns an array of size 2, where the first element is the slope and the second is the $y$-intercept.
81
+
82
+ For this exercise, we will be expressing demand and supply as quantities in terms of price.
83
+
84
+ ```python
85
+ np.polyfit(oranges.column("Price"), oranges.column("Quantity"), 1)
86
+ ```
87
+
88
+ This shows that the demand curve is $D(P) = -3433 P+ 53626$. The slope is -3433 and $y$-intercept is 53626. That means that as price increases by 1 unit (in this case, \$1), quantity decreases by 3433 units (in this case, 3433 tons).
89
+
90
+ ### Create the Demand Curve
91
+
92
+ We will now use SymPy to write out this demand curve. To do so, we start by creating a symbol `P` that we can use to create the equation.
93
+
94
+ ```python
95
+ P = sympy.Symbol("P")
96
+ demand = -3432.846 * P + 53625.87
97
+ demand
98
+ ```
99
+
100
+ ### Create the Supply Curve
101
+
102
+ As you've learned, the supply curve is the relationship between the price of a good or service and the quantity of that good or service that the seller is willing to supply. It shows how much of a good suppliers are willing and able to supply at different prices. In this case, as the price of the oranges increases, the quantity of oranges that orange manufacturers are willing to supply increases. They capture the producer's side of market decisions and are upward-sloping.
103
+
104
+ Let's now assume that the supply curve is given by $S(P) = 4348P$. (Note that this supply curve is not based on data.)
105
+
106
+ ```python
107
+ supply = 4348 * P
108
+ supply
109
+ ```
110
+
111
+ This means that as the price of oranges increases by 1, the quantity supplied increases by 4348. At a price of 0, no oranges are supplied.
112
+
113
+ ### Find the Price Equilibrium
114
+
115
+ With the supply and demand curves known, we can solve the for equilibrium.
116
+ The equilibrium is the point where the supply curve and demand curve intersect, and denotes the price and quantity of the good transacted in the market.
117
+
118
+ The equilbrium consists of 2 components: the quantity equilbrium and price equilbrium.
119
+ The price equilibrium is the price at which the supply curve and demand curve intersect: the price of the good that consumers desire to purchase at is equivalent to the price of the good that producers want to sell at. There is no shortage of surplus of the product at this price.
120
+
121
+
122
+ Let's find the price equilibrium. To do this, we will use the provided `solve` function. This is a custom function that leverages some SymPy magic and will be provided to you in assignments.
123
+
124
+ ```python
125
+ P_star = solve(demand, supply)
126
+ P_star
127
+ ```
128
+
129
+ This means that the price of oranges that consumers want to purchase at and producers want to provide is about \$6.89.
130
+
131
+ ### Find the Quantity Equilibrium
132
+
133
+ Similarly, the quantity equilibrium is the quantity of the good that consumers desire to purchase is equivalent to the quantity of the good that producers supply; there is no shortage or surplus of the good at this quantity.
134
+
135
+ ```python
136
+ demand.subs(P, P_star)
137
+ supply.subs(P, P_star)
138
+ ```
139
+
140
+ This means that the number of tons of oranges that consumers want to purchase and producers want to provide in this market is about 29,967 tons of oranges.
141
+
142
+ ### Visualize the Market Equilibrium
143
+
144
+ Now that we have our demand and supply curves and price and quantity equilibria, we can visualize them on a graph to see what they look like.
145
+
146
+ There are 2 pre-made functions we will use: `plot_equation` and `plot_intercept`.
147
+ - `plot_equation`: It takes in the equation we made previously (either demand or supply) and visualizes the equations between the different prices we give it
148
+ - `plot_intercept`: It takes in two different equations (demand and supply), finds the point at which the two intersect, and creates a scatter plot of the result
149
+
150
+ ```python
151
+ def plot_equation(equation, price_start, price_end, label=None, color=None, linestyle=None):
152
+ plot_prices = [price_start, price_end]
153
+ plot_quantities = [equation.subs(list(equation.free_symbols)[0], c) for c in plot_prices]
154
+ plt.plot(plot_quantities, plot_prices, label=label, color=color, linestyle=linestyle)
155
+
156
+ def plot_intercept(eq1, eq2):
157
+ ex = sympy.solve(eq1-eq2)[0]
158
+ why = eq1.subs(list(eq1.free_symbols)[0], ex)
159
+ plt.scatter([why], [ex], zorder=10, color="black")
160
+ return (ex, why)
161
+ ```
162
+
163
+ We can leverage these functions and the equations we made earlier to create a graph that shows the market equilibrium.
164
+
165
+ [Following image is a scatter plot for supply and demand for oranges]
166
+
167
+ ```python
168
+ mpl.rcParams['figure.dpi'] = 150
169
+ plot_equation(demand, 2, 10, label = "Demand")
170
+ plot_equation(supply, 2, 10, label = "Supply", color="#CB7432", linestyle="dashed")
171
+ plt.ylim(0,13)
172
+ plt.title("Orange Supply and Demand in 1920's and 1930's", fontsize = 15)
173
+ plt.xlabel("Quantity (Tons)", fontsize = 14)
174
+ plt.ylabel("Price ($)", fontsize = 14)
175
+ plot_intercept(supply, demand)
176
+ plt.legend(loc = "upper right", fontsize = 12)
177
+ plt.legend()
178
+ plt.show()
179
+ ```
180
+
181
+ You can also practice on your own and download additional data sets [here](http://users.stat.ufl.edu/~winner/datasets.html), courtesy of the University of Flordia's Statistics Department.
182
+
183
+ ## Movements Away from Equilibrium
184
+
185
+ What happens to market equilibrium when either supply or demand shifts due to an exogenous shock?
186
+
187
+ Let's assume that consumers now prefer Green Tea as their hot beverage of choice moreso than before. We have an outward shift of the demand curve - quantity demanded is greater at every price. The market is no longer in equilibrium.
188
+
189
+ [Following image is a hand drawn diagram of a shift in demand]
190
+
191
+ ```{figure} fig1-demand.png
192
+ ---
193
+ width: 500px
194
+ name: demand-shift
195
+ ---
196
+ A shift in the demand curve
197
+ ```
198
+
199
+ ![title](fig1-demand.png)
200
+
201
+ At the same price level (the former equilibrium price), there is a shortage of Green Tea. The amount demanded by consumers exceeds that supplied by producers: $Q_D > Q_S$. This is a seller's market, as the excess quantity demanded gives producers leverage (or market power) over consumers. They are able to increase the price of Green Tea to clear the shortage. As prices increase, consumers who were willing and able to purchase tea at the previous equilibrium price would leave the market, reducing quantity demanded. $Q_S$ and $Q_D$ move up along their respective curves until the new equilibrium is achieved where $Q_S = Q_D$.
202
+
203
+ This dual effect of increasing $Q_S$ and $Q_D$ is sometimes referred to as the "invisible hand". Sans government intervention, it clears out the shortage or surplus in the market, resulting in the eventual convergence to a new equilibrium level of quantity $Q^*$ and price $P^*$.
204
+
@@ -0,0 +1,16 @@
1
+ ---
2
+ title: index
3
+ type: textbook
4
+ source_path: content/02-supply/index.md
5
+ chapter: 2
6
+ ---
7
+
8
+ # Supply and Market Equilibrium
9
+
10
+ **Student Learning Outcomes:**
11
+ * Know how a supply curve is formed
12
+ * Understand when and how much a firm decided to produce
13
+ * Understand demand and price elasticities of goods
14
+ * Use SymPy to solve systems of supply and demand equations
15
+ * Calculate the price equilibrium
16
+