```python
import sympy
import matplotlib.pyplot as plt
p = sympy.Symbol("p")
class supplyDemand:
    def __init__(self,demandEquation,supplyEquation):
        self.demandEquation = demandEquation
        self.supplyEquation = supplyEquation
        self.priceEnd = sympy.solve(demandEquation)[0]
        self.prices = []
        self.demandQ = []
        self.supplyQ = []
        for price in range(0,self.priceEnd+1):
            self.prices += [price]
            self.demandQ += [demandEquation.subs(p,price)]
            self.supplyQ += [supplyEquation.subs(p,price)]
        self.startingQ = sympy.solve(demandEquation-supplyEquation)[0]
        self.startingP = demandEquation.subs(p,self.startingQ)
        self.mode = "Normal"
    
    def plot(self):
        plt.plot(self.demandQ,self.prices,'k')
        plt.plot(self.supplyQ,self.prices,'k')
        plt.plot(self.startingQ,self.startingP, 'bo')
        plt.xlabel("Supply and Demand Quantity")
        plt.ylabel("Price")
        plt.show()
```


```python
import sympy
import matplotlib.pyplot as plt
p = sympy.Symbol("p")
class supplyDemand:
    def __init__(self,demandEquation,supplyEquation):
        self.demandEquation = demandEquation
        self.supplyEquation = supplyEquation
        self.priceEnd = sympy.solve(demandEquation)[0]
        self.prices = []
        self.demandQ = []
        self.supplyQ = []
        for price in range(0,self.priceEnd+1):
            self.prices += [price]
            self.demandQ += [demandEquation.subs(p,price)]
            self.supplyQ += [supplyEquation.subs(p,price)]
        self.startingQ = sympy.solve(demandEquation-supplyEquation)[0]
        self.startingP = demandEquation.subs(p,self.startingQ)
        self.mode = "Normal"
    
    def plot(self):
        plt.plot(self.demandQ,self.prices,'k')
        plt.plot(self.supplyQ,self.prices,'k')
        plt.plot(self.startingQ,self.startingP, 'bo')
        plt.xlabel("Supply and Demand Quantity")
        plt.ylabel("Price")
        plt.show()
    def internationalTrade(self,worldPrice):
        self.mode = "International"
        self.worldPrice = worldPrice
        if worldPrice>self.startingP:
            self.export = True
            self.domesticQ = self.demandEquation.subs(p,worldPrice)
            self.internationalQ = self.supplyEquation.subs(p,worldPrice)-self.demandEquation.subs(p,worldPrice)
            self.totalQ = self.domesticQ+self.internationalQ
        else:
            self.export = False
            self.domesticQ = self.supplyEquation.subs(p,worldPrice)
            self.internationalQ = self.demandEquation.subs(p,worldPrice)-self.domesticQ
            self.totalQ = self.domesticQ+self.internationalQ
```


```python
economy1 = supplyDemand(10-p,p)
economy1.plot()
economy1.internationalTrade(6)
print(economy1.startingQ)
print(economy1.export)
print(economy1.domesticQ)
print(economy1.totalQ)
```


```python
import sympy
import matplotlib.pyplot as plt
p = sympy.Symbol("p")
class supplyDemand:
    def __init__(self,demandEquation,supplyEquation):
        self.demandEquation = demandEquation
        self.supplyEquation = supplyEquation
        self.priceEnd = sympy.solve(demandEquation)[0]
        self.prices = []
        self.demandQ = []
        self.supplyQ = []
        for price in range(0,self.priceEnd+1):
            self.prices += [price]
            self.demandQ += [demandEquation.subs(p,price)]
            self.supplyQ += [supplyEquation.subs(p,price)]
        self.startingQ = sympy.solve(demandEquation-supplyEquation)[0]
        self.startingP = demandEquation.subs(p,self.startingQ)
        self.mode = "Normal"
    def internationalTrade(self,worldPrice):
        self.mode = "International"
        self.worldPrice = worldPrice
        if worldPrice>self.startingP:
            self.export = True
            self.domesticQ = self.demandEquation.subs(p,worldPrice)
            self.internationalQ = self.supplyEquation.subs(p,worldPrice)-self.demandEquation.subs(p,worldPrice)
            self.totalQ = self.domesticQ+self.internationalQ
        else:
            self.export = False
            self.domesticQ = self.supplyEquation.subs(p,worldPrice)
            self.internationalQ = self.demandEquation.subs(p,worldPrice)-self.domesticQ
            self.totalQ = self.domesticQ+self.internationalQ
    
    def plot(self):
        plt.plot(self.demandQ,self.prices,'k')
        plt.plot(self.supplyQ,self.prices,'k')
        plt.plot(self.startingQ,self.startingP, 'bo')
        plt.xlabel("Supply and Demand Quantity")
        plt.ylabel("Price")
        if self.mode=="International":
            plt.plot([self.totalQ,self.priceEnd],[self.worldPrice,self.worldPrice],'k')
            if self.startingP!=self.worldPrice:
                plt.plot(self.totalQ,self.worldPrice, 'bo')
                plt.plot(self.domesticQ,self.worldPrice,'bo')
                plt.plot([0,self.domesticQ],[self.worldPrice,self.worldPrice],label='Domestic Quantity')
                plt.plot([self.domesticQ,self.totalQ],[self.worldPrice,self.worldPrice], label='International Quantity')
                plt.legend()
        plt.show()
economy1 = supplyDemand(10-p,p)
economy1.internationalTrade(6)
economy1.plot()
```


```python
import sympy
import matplotlib.pyplot as plt
p = sympy.Symbol("p")
class supplyDemand:
    def __init__(self,demandEquation,supplyEquation):
        self.demandEquation = demandEquation
        self.supplyEquation = supplyEquation
        self.priceEnd = sympy.solve(demandEquation)[0]
        self.prices = []
        self.demandQ = []
        self.supplyQ = []
        for price in range(0,self.priceEnd+1):
            self.prices += [price]
            self.demandQ += [demandEquation.subs(p,price)]
            self.supplyQ += [supplyEquation.subs(p,price)]
        self.startingQ = sympy.solve(demandEquation-supplyEquation)[0]
        self.startingP = demandEquation.subs(p,self.startingQ)
        self.mode = "Normal"
    def internationalTrade(self,worldPrice):
        self.mode = "International"
        self.worldPrice = worldPrice
        if worldPrice>self.startingP:
            self.export = True
            self.domesticQ = self.demandEquation.subs(p,worldPrice)
            self.internationalQ = self.supplyEquation.subs(p,worldPrice)-self.demandEquation.subs(p,worldPrice)
            self.totalQ = self.domesticQ+self.internationalQ
        else:
            self.export = False
            self.domesticQ = self.supplyEquation.subs(p,worldPrice)
            self.internationalQ = self.demandEquation.subs(p,worldPrice)-self.domesticQ
            self.totalQ = self.domesticQ+self.internationalQ
    
    def plot(self):
        plt.plot(self.demandQ,self.prices,'k')
        plt.plot(self.supplyQ,self.prices,'k')
        plt.plot(self.startingQ,self.startingP, 'bo')
        plt.xlabel("Supply and Demand Quantity")
        plt.ylabel("Price")
        if self.mode=="International":
            plt.plot([self.totalQ,self.priceEnd],[self.worldPrice,self.worldPrice],'k')
            if self.startingP!=self.worldPrice:
                plt.plot(self.totalQ,self.worldPrice, 'bo')
                plt.plot(self.domesticQ,self.worldPrice,'bo')
                plt.plot([0,self.domesticQ],[self.worldPrice,self.worldPrice],label='Domestic Quantity')
                plt.plot([self.domesticQ,self.totalQ],[self.worldPrice,self.worldPrice], label='International Quantity')
                plt.legend()
                if self.export:
                    print("The country exports during international trade, and the price moves from "+str(self.startingP)+" to "+str(self.worldPrice)+".")
                    print("The domestic producers go from producing "+str(self.startingQ)+" units to "+str(self.totalQ)+" units.")
                    print("The domestic consumers go from consuming "+str(self.startingQ)+" units to "+str(self.domesticQ)+" units.")
                    print("Total domestic producer revenue is "+str(self.totalQ*self.worldPrice))
                else:
                    print("The country imports during international trade, and the price moves from "+str(self.startingP)+" to "+str(self.worldPrice)+".")
                    print("The domestic producers go from producing "+str(self.startingQ)+" units to "+str(self.domesticQ)+" units.")
                    print("The domestic consumers go from consuming "+str(self.startingQ)+" units to "+str(self.totalQ)+" units.")
                    print("Total domestic producer revenue is "+str(self.domesticQ*self.worldPrice))
        plt.show()
economy1 = supplyDemand(10-p,p)
economy1.internationalTrade(6)
economy1.plot()
```


```python
import sympy
import matplotlib.pyplot as plt
import matplotlib.patches as patches
p = sympy.Symbol("p")
class supplyDemand:
    def __init__(self,demandEquation,supplyEquation):
        self.demandEquation = demandEquation
        self.supplyEquation = supplyEquation
        self.priceEnd = sympy.solve(demandEquation)[0]
        self.prices = []
        self.demandQ = []
        self.supplyQ = []
        for price in range(0,self.priceEnd+1):
            self.prices += [price]
            self.demandQ += [demandEquation.subs(p,price)]
            self.supplyQ += [supplyEquation.subs(p,price)]
        self.startingQ = sympy.solve(demandEquation-supplyEquation)[0]
        self.startingP = demandEquation.subs(p,self.startingQ)
        self.mode = "Normal"
    def internationalTrade(self,worldPrice):
        self.mode = "International"
        self.worldPrice = worldPrice
        if worldPrice>self.startingP:
            self.export = True
            self.domesticQ = self.demandEquation.subs(p,worldPrice)
            self.internationalQ = self.supplyEquation.subs(p,worldPrice)-self.demandEquation.subs(p,worldPrice)
            self.totalQ = self.domesticQ+self.internationalQ
        else:
            self.export = False
            self.domesticQ = self.supplyEquation.subs(p,worldPrice)
            self.internationalQ = self.demandEquation.subs(p,worldPrice)-self.domesticQ
            self.totalQ = self.domesticQ+self.internationalQ
        self.domesticQ
    def drawSurplus1(self):
        if self.export:
            triangle1 = patches.Polygon([[self.domesticQ,self.worldPrice],[0,self.worldPrice],[0,self.priceEnd]],True,label="Consumer Surplus")
            triangle2 = patches.Polygon([[0,0],[0,self.startingP],[self.startingQ,self.startingP]],True,label="Original Producer Surplus",color="red")
            rect1 = patches.Polygon([[0,self.startingP],[0,self.worldPrice],[self.domesticQ,self.worldPrice],[self.startingQ,self.startingP]],True,label="Transferred Surplus",color="orange")
            triangle3 = patches.Polygon([[self.domesticQ,self.worldPrice],[self.totalQ,self.worldPrice],[self.startingQ,self.startingP]],True,label="Surplus from International",color="yellow")
            currentAxis = plt.gca()
            currentAxis.add_patch(triangle1)
            currentAxis.add_patch(triangle2)
            currentAxis.add_patch(rect1)
            currentAxis.add_patch(triangle3)
        else:
            triangle1 = patches.Polygon([[self.startingQ,self.startingP],[0,self.startingP],[0,self.priceEnd]],True,label="Original Consumer Surplus", color="red")
            triangle2 = patches.Polygon([[0,0],[0,self.worldPrice],[self.domesticQ,self.worldPrice]],True,label="Producer Surplus")
            rect1 = patches.Polygon([[0,self.startingP],[0,self.worldPrice],[self.domesticQ,self.worldPrice],[self.startingQ,self.startingP]],True,label="Transferred Surplus",color="orange")
            triangle3 = patches.Polygon([[self.domesticQ,self.worldPrice],[self.totalQ,self.worldPrice],[self.startingQ,self.startingP]],True,label="Surplus from International",color="yellow")
            currentAxis = plt.gca()
            currentAxis.add_patch(triangle1)
            currentAxis.add_patch(triangle2)
            currentAxis.add_patch(rect1)
            currentAxis.add_patch(triangle3)
            
    
    def plot(self):
        plt.plot(self.demandQ,self.prices,'k')
        plt.plot(self.supplyQ,self.prices,'k')
        plt.plot(self.startingQ,self.startingP, 'bo')
        plt.xlabel("Supply and Demand Quantity")
        plt.ylabel("Price")
        if self.mode=="International":
            plt.plot([0,self.priceEnd],[self.worldPrice,self.worldPrice],"k")
            if self.startingP!=self.worldPrice:
                plt.plot(self.totalQ,self.worldPrice, 'bo')
                plt.plot(self.domesticQ,self.worldPrice,'bo')
                plt.plot([0,self.domesticQ],[self.worldPrice,self.worldPrice],"m",label='Domestic Quantity')
                plt.plot([self.domesticQ,self.totalQ],[self.worldPrice,self.worldPrice],"g", label='International Quantity')
                
                if self.export:
                    print("The country exports during international trade, and the price moves from "+str(self.startingP)+" to "+str(self.worldPrice)+".")
                    print("The domestic producers go from producing "+str(self.startingQ)+" units to "+str(self.totalQ)+" units.")
                    print("The domestic consumers go from consuming "+str(self.startingQ)+" units to "+str(self.domesticQ)+" units.")
                    print("Total domestic producer revenue is "+str(self.totalQ*self.worldPrice))
                else:
                    print("The country imports during international trade, and the price moves from "+str(self.startingP)+" to "+str(self.worldPrice)+".")
                    print("The domestic producers go from producing "+str(self.startingQ)+" units to "+str(self.domesticQ)+" units.")
                    print("The domestic consumers go from consuming "+str(self.startingQ)+" units to "+str(self.totalQ)+" units.")
                    print("Total domestic producer revenue is "+str(self.domesticQ*self.worldPrice))
                plt.legend()
        plt.show()
```


```python
economy1 = supplyDemand(10-p,p)
economy1.internationalTrade(4)
economy1.drawSurplus1()
economy1.plot()
```


```python
import sympy
import matplotlib.pyplot as plt
import matplotlib.patches as patches
p = sympy.Symbol("p")
class supplyDemand:
    def __init__(self,demandEquation,supplyEquation):
        self.demandEquation = demandEquation
        self.supplyEquation = supplyEquation
        self.priceEnd = sympy.solve(demandEquation)[0]
        self.prices = []
        self.demandQ = []
        self.supplyQ = []
        for price in range(0,self.priceEnd+1):
            self.prices += [price]
            self.demandQ += [demandEquation.subs(p,price)]
            self.supplyQ += [supplyEquation.subs(p,price)]
        self.startingQ = sympy.solve(demandEquation-supplyEquation)[0]
        self.startingP = demandEquation.subs(p,self.startingQ)
        self.mode = "Normal"
    def internationalTrade(self,worldPrice):
        self.mode = "International"
        self.worldPrice = worldPrice
        if worldPrice>self.startingP:
            self.export = True
            self.domesticQ = self.demandEquation.subs(p,worldPrice)
            self.internationalQ = self.supplyEquation.subs(p,worldPrice)-self.demandEquation.subs(p,worldPrice)
            self.totalQ = self.domesticQ+self.internationalQ
        else:
            self.export = False
            self.domesticQ = self.supplyEquation.subs(p,worldPrice)
            self.internationalQ = self.demandEquation.subs(p,worldPrice)-self.domesticQ
            self.totalQ = self.domesticQ+self.internationalQ
        self.domesticQ
    def drawSurplus1(self):
        if self.export:
            triangle1 = patches.Polygon([[self.domesticQ,self.worldPrice],[0,self.worldPrice],[0,self.priceEnd]],True,label="Consumer Surplus")
            triangle2 = patches.Polygon([[0,0],[0,self.startingP],[self.startingQ,self.startingP]],True,label="Original Producer Surplus",color="red")
            rect1 = patches.Polygon([[0,self.startingP],[0,self.worldPrice],[self.domesticQ,self.worldPrice],[self.startingQ,self.startingP]],True,label="Transferred Surplus",color="orange")
            triangle3 = patches.Polygon([[self.domesticQ,self.worldPrice],[self.totalQ,self.worldPrice],[self.startingQ,self.startingP]],True,label="Surplus from International",color="yellow")
            currentAxis = plt.gca()
            currentAxis.add_patch(triangle1)
            currentAxis.add_patch(triangle2)
            currentAxis.add_patch(rect1)
            currentAxis.add_patch(triangle3)
            print("The consumer surplus goes from "+str((self.priceEnd-self.startingP)*self.startingQ*.5)+" to "+str((self.priceEnd-self.worldPrice)*self.domesticQ*.5))
            print("The producer surplus goes from "+str(self.startingP*self.startingQ*.5)+" to "+str(self.worldPrice*self.totalQ*.5))
        else:
            triangle1 = patches.Polygon([[self.startingQ,self.startingP],[0,self.startingP],[0,self.priceEnd]],True,label="Original Consumer Surplus", color="red")
            triangle2 = patches.Polygon([[0,0],[0,self.worldPrice],[self.domesticQ,self.worldPrice]],True,label="Producer Surplus")
            rect1 = patches.Polygon([[0,self.startingP],[0,self.worldPrice],[self.domesticQ,self.worldPrice],[self.startingQ,self.startingP]],True,label="Transferred Surplus",color="orange")
            triangle3 = patches.Polygon([[self.domesticQ,self.worldPrice],[self.totalQ,self.worldPrice],[self.startingQ,self.startingP]],True,label="Surplus from International",color="yellow")
            currentAxis = plt.gca()
            currentAxis.add_patch(triangle1)
            currentAxis.add_patch(triangle2)
            currentAxis.add_patch(rect1)
            currentAxis.add_patch(triangle3)
            print("The producer surplus goes from "+str(self.startingP*self.startingQ*.5)+" to "+str(self.worldPrice*self.domesticQ*.5))
            print("The consumer surplus goes from "+str((self.priceEnd-self.startingP)*self.startingQ*.5)+" to "+str((self.priceEnd-self.worldPrice)*self.domesticQ*.5))
    
    def plot(self):
        plt.plot(self.demandQ,self.prices,'k')
        plt.plot(self.supplyQ,self.prices,'k')
        plt.plot(self.startingQ,self.startingP, 'bo')
        plt.xlabel("Supply and Demand Quantity")
        plt.ylabel("Price")
        if self.mode=="International":
            plt.plot([0,self.priceEnd],[self.worldPrice,self.worldPrice],"k")
            if self.startingP!=self.worldPrice:
                plt.plot(self.totalQ,self.worldPrice, 'bo')
                plt.plot(self.domesticQ,self.worldPrice,'bo')
                plt.plot([0,self.domesticQ],[self.worldPrice,self.worldPrice],"m",label='Domestic Quantity')
                plt.plot([self.domesticQ,self.totalQ],[self.worldPrice,self.worldPrice],"g", label='International Quantity')
                
                if self.export:
                    print("The country exports during international trade, and the price moves from "+str(self.startingP)+" to "+str(self.worldPrice)+".")
                    print("The domestic producers go from producing "+str(self.startingQ)+" units to "+str(self.totalQ)+" units.")
                    print("The domestic consumers go from consuming "+str(self.startingQ)+" units to "+str(self.domesticQ)+" units.")
                    print("Total domestic producer revenue is "+str(self.totalQ*self.worldPrice))
                else:
                    print("The country imports during international trade, and the price moves from "+str(self.startingP)+" to "+str(self.worldPrice)+".")
                    print("The domestic producers go from producing "+str(self.startingQ)+" units to "+str(self.domesticQ)+" units.")
                    print("The domestic consumers go from consuming "+str(self.startingQ)+" units to "+str(self.totalQ)+" units.")
                    print("Total domestic producer revenue is "+str(self.domesticQ*self.worldPrice))
                plt.legend()
        plt.show()
```


```python
economy1 = supplyDemand(10-p,p)
economy1.internationalTrade(6)
economy1.drawSurplus1()
economy1.plot()
```

6d4e49ed6bfb1a268e6a0d287c7e0dcfaba1cb6d
ipynb
Jupyter Notebook
FinanceAndPython.com-EconomicFoundations-master/11 Imports and Exports.ipynb
ds-modules/IAS-106
8fb0344c9dd112e79c535d86f12c1b0000be5041
MIT
FinanceAndPython.com-EconomicFoundations-master/11 Imports and Exports.ipynb
ds-modules/IAS-106
8fb0344c9dd112e79c535d86f12c1b0000be5041
MIT
FinanceAndPython.com-EconomicFoundations-master/11 Imports and Exports.ipynb
ds-modules/IAS-106
8fb0344c9dd112e79c535d86f12c1b0000be5041
MIT
2019-12-07T07:01:18.000Z
2022-02-05T01:46:45.000Z
Qwen/Qwen-72B
1. YES
2. YES