<jupyter_start><jupyter_text>Hechscher-Ohlin-Samuelson Model of TradeSee the [Edgeworth Box](Edgeworth.ipynb) notebook to understand how the Edgeworth Box diagrams drawn below were constructed to represent this economy.<jupyter_code>from hos import *<jupyter_output><empty_output><jupyter_text>Small Open Economy Consider a small-open economy with two production sectors -- agriculture and manufacturing -- with production in each sector taking place with constant returns to scale production functions.  Producers in the agricultural sector maximize profits$$\max_{K_A,L_A} p_A F(K_A,L_A) - w L_A - r K_A$$Producers in manufacturing maximize$$\max_{K_M,L_M} p_M F(K_M,L_M) - w L_M - r K_M$$In equilibrium total factor demands must equal total supplies:$$K_A + K_M = \bar K$$$$L_A + L_M = \bar L$$  Here is an [Edgeworth Box](Edgeworth.ipynb_ that depicts the situation where $L_A = 50$ units of labor are allocated to the agricultural sector and all other allocations are efficient (along the efficiency locus).<jupyter_code>edgeplot(50)<jupyter_output>(LA,KA)=(50.0, 69.2)  (QA, QM)=(60.8, 41.2)  RTS= 2.1<jupyter_text>If you're reading this using a jupyter server you can interact with the following plot, changing the technology parameters and position of the isoquant. If you are not this may appear blank or static.<jupyter_code>LA = 50
interact(edgeplot, LA=(10, Lbar-10,1), 
         Kbar=fixed(Kbar), Lbar=fixed(Lbar),
         alpha=(0.1,0.9,0.1),beta=(0.1,0.9,0.1));<jupyter_output><empty_output><jupyter_text>Resource Allocation in a small open economy From the first order conditions for profit maximization in each sector we have:$$P_A F_L(K_A,L_A) = w = P_M G_L(K_M,L_M) $$ Note this condition states that competition has driven firms to price at marginal cost in each industry or $P_A = MC_A = w\frac{1}{F_L}$ and $P_M = MC_M = w\frac{1}{G_L}$ which in turn implies that at a market equilibrium optimum $$\frac{P_A}{P_M} = \frac{G_L(K_M,L_M)}{F_L(K_A,L_A)}$$This states that the world price line with slope (negative) $\frac{P_A}{P_M}$ will be tangent to the production possibility frontier which as a slope (negative) $\frac{MC_A}{MC_M}= \frac{P_A}{P_M}$ which can also be written as $\frac{G_L}{F_L}$ or equivalently $\frac{G_K}{F_K}$. The competitive market leads producers to move resources across sectors to maximize the value of GDP at world prices.   The Stolper Samuelson lineWe can derive a relationship between relative product prices (set on the world market) and the equilibrium wage-rental ration $w/r$. With the Cobb Douglas technology we can write:$$F_L = (1-\alpha) \left [ \frac{K_A}{L_A} \right]^\alpha$$$$F_K = \alpha \left [ \frac{L_M}{K_M} \right]^\alpha$$The first order necessary conditions for an interior optimum in each sector lead to an equilibrium where the following condition must hold:$$\frac{F_L(K_A,L_A)}{F_K(K_A,L_A)} = \frac{w}{r}        =\frac{G_L(\bar K-K_A,\bar L- L_A)}{G_K(\bar K-K_A,\bar L- L_A)}$$ Using these expressions and earlier factor demand expressions we can derive: $$\frac{P_A}{P_M} =\frac{1-\alpha}{1-\beta}     \frac{\left [ \frac{ (1-\beta)}{\beta} \frac{w}{r} \right]^\beta}     { \left [ \frac{ (1-\alpha)}{\alpha} \frac{w}{r} \right]^\alpha}$$ or $$\frac{P_A}{P_M} = \Gamma \left [ \frac{w}{r}  \right]^{\beta - \alpha}$$where $$\Gamma =\frac{1-\alpha}{1-\beta} \left ( \frac{\alpha}{1-\alpha} \right )^\alpha \left ( \frac{1-\beta}{\beta} \right )^\beta $$Inverting, we get an expression for the **Stolper Samuelson Line** $$\frac{w}{r} = \frac{1}{\Gamma} \left [  \frac{P_A}{P_M}   \right ]^\frac{1}{\beta-\alpha} $$  The Stolper Samuelson TheoremThe Stolper Samuelson theorem tells us how changes in the world relative price of products translates into changes in the relative price of factors and therefore in the distribution of income in society.The theorem states that an increase in the relative price of a good will lead to an increase in both the relative and the real price of the factor used intensively in the production of that good (and conversely to a decline in both the real and the relative price of the other factor). This relationship can be seen from the formula.  If agriculture were more labor intensive than manufacturing, so $\alpha < \beta$, then an increase in the relative price of agricultural goods creates an incipient excess demand for labor and an excess supply of capital (as firms try to expand production in the now more profitable labor-intensive agricultural sector and cut back production in the now relatively less profitable and capital-intensive manufacturing sector). Equilibrium will only be restored if the equilibrium wage-rental ratio falls which in turn leads firms in both sectors to adopt more capital-intensive techniques.  With more capital per worker in each sector output per worker and hence real wages per worker $\frac{w}{P_a}$ and $\frac{w}{P_m}$ increase.<jupyter_code>ssline(a=0.3, b=0.7)<jupyter_output><empty_output><jupyter_text>Solving for equilibrium allocation as a function of relative price pCode to solve for unique HOS equilibrium as a function of world relative price $\frac{P_A}{P_M}$From Lerner-Edgeworth boxEquilibrium in the capital market:$$K_a + K_m = \bar K$$We can use $K_a= k_a \cdot L_a$ and $K_m = k_m \cdot L_a$ to rewrite this as:$$k_a\cdot L_A + k_m \cdot L_m = \bar K$$Noting that $L_m=\bar L - L_a$ and solving for $L_a$$$k_a\cdot L_A = \bar K - k_m \cdot (\bar L -L_A)$$$$L_A = \frac{\bar K - k_m \cdot \bar L}{k_a-k_m}$$ We now have enough to solve the model.  If the economy is open to trade, it takes factor prices as given. For example if the $P_a \over P_m=1$ then we fan find $w/r$ and from that optimal capital intensities in each industry $k_a$ and $k_m$<jupyter_code>from IPython.display import display, Markdown
p = 1
a = 0.3
b = 0.7
wr = wreq(p, a=a, b=b)
ka = kl(wr,a)
km = kl(wr,b)
LA, KA = hos_eq(p, Kbar=100, Lbar=100)

display(Markdown(rf"""
  When $\frac{{P_a}}{{P_m}}=1, \frac{{w}}{{r}}$ = {wr:0.2f} 
  and $(k_a, k_m)$ = ({ka:0.2f}, {km:0.2f}) 
  """))
HOS(1)
HOS(1.06)
interact(HOS, p=(0.8, 1.1,0.01), 
         Kbar=fixed(Kbar), Lbar=(90, 150,10),
         alpha=(0.1,0.5,0.1), beta=(0.5,0.9,0.1));
klplot(1)
lerner(p=1.2)
interact(lerner, p=(0.7,1.4,0.1));
closed_plot(alpha=0.8, beta=0.2)
interact(closed_plot, alpha=(0.1,0.9,0.1), beta=(0.1,0.9,0.1));<jupyter_output><empty_output><jupyter_text>NOTE: Something is off on this Rybyczynski Edgeworth plot... had been working..<jupyter_code>rybplot(1, Kbar=Kbar, Lbar=Lbar, alpha=0.65, beta=0.35)<jupyter_output><empty_output><jupyter_text>Rbyczynski Theorem.  Adding labor should more than proportionately expand the productinon of the labor-intensive product and reduce the production of the other good.Here Manufacturing is the labor-intensive sector.  We added increase $\bar L$ from 100 to 150 and we see how in the new equilibrium labor in manufacturing goes up from $L_M=65$ to $L_M=135$.  Output of manufacturing increases from 51 to 106 and output of agriculture falls from 51 to 21.<jupyter_code>rybplot(1, Kbar=Kbar, Lbar=Lbar*1.5, alpha=0.65, beta=0.35)
interact(rybplot, p = fixed(1), Lbar =(50,150,10), Kbar =(50,150,10), alpha=fixed(0.65), beta=fixed(0.35));<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12657178388835152, 'fraction_numerical': 0.02556307862373912, 'mean_word_length': 4.837096774193548, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '243288', 'license': 'MIT', 'n_tokens_mistral': 2541, 'n_tokens_neox': 2423, 'n_words': 880, 'path': 'notebooks/trade/HOS.ipynb', 'repo_name': 'jhconning/simpleTeach', 'size': '7237'}