Tuesday, January 17, 2023

Python Experiment: Macroeconomic Theory: Income Price Inflation Control Simulator in the ADAS model


 I have created a macroeconomic policy simulator with Python programming. 

This refers to the aggregate demand and supply interaction based on the simplified IS-LM interaction influencing the aggregate demand (AD) and the labour market and the capital cost influencing the short-run aggregate supply (AS). These curves are composed of the two main parameters, the aggregate income level and the price level, as well as the money supply (MS) basing the IS-LM, and the wage index (W) basing the labour market. 

My Python codes are as follows: 

# Default Parameters
import random
Y=[20,30]  # The aggregate income level: Change here to see each effect
P=[100,102] # The price level: Change here to see each effect
W=[10]
WB=0.2
MS=[100]
rHD=10 
CapCost=[10]

# Function representing the price inflation
def PrInf():
    return ((P[-1]-P[-2])/P[-2])

PrInf()

# Higher function
# The aggregate demand influence
def Y_Inv(MSlmis,Ylmis,dp):
    r_MS=pow(MSlmis/10,-1.05)+rHD*(PrInf()) #LM side
    return pow(Ylmis,-1*(r_MS-PrInf())) #IS-side

Y_Inv(MS[-1],Y[-1],PrInf())

# A part of the short-run aggregate supply influence (The Labour Market).
def Y_Lab(Wlab,Plab):
    return (50-(50/(Wlab/Plab)))/100

Y_Lab(W[-1],1+PrInf()+0.000001)


def AggregateDemandCurve(Ydd):
    Pd=Y_Inv(MS,Ydd)/Ydd
    return Pd

def AggregateSupplyCurve(Wlab,Plab,Css):
    Ps=Css+Y_Lab(Wlab,Plab)
    return Ps
    

def AggregateSupplyCurveShift(Y1,Y2,Pinv):
    dp=(Y_Inv(MS[-1],Y1,Pinv))-(Y_Inv(MS[-1],Y2,Pinv)) #AggregateDemandCurve(Yd1)-AggregateDemandCurve(Yd2)
    return dp

print(Y_Inv(MS[-1],Y[-1],PrInf()),Y[-1],PrInf())
print(Y_Inv(MS[-1],Y[-2],PrInf()),Y[-2],PrInf())
AggregateSupplyCurveShift(Y[-1],Y[-2],PrInf())


def AggregateDemandCurveShift(Y1,Y2,Wlab,Plab,Csd):
    dp = (Csd+(Y_Lab(Wlab,Plab)*(1+WB*(Y1-Y2)/Y2)))-(Csd+Y_Lab(Wlab,Plab)) #AggregateSupplyCurve(Yd1)-AggregateSupplyCurve(Yd2)
    return dp

print(CapCost[-1]+(Y_Lab(W[-1],PrInf())*(1+WB*(Y[-1]-Y[-2])/Y[-2])))
print(CapCost[-1]+Y_Lab(W[-1],PrInf()))
           
AggregateDemandCurveShift(Y[-1],Y[-2],W[-1],PrInf(),CapCost[-1])

# Calculating the average aggregate income level across all over the time period to generate the long-run aggregate supply interaction
def Ymean():
    Ysum=0
    for i in range(len(Y)):
        Ysum=Ysum+Y[i]
    return Ysum/len(Y)
Ymean()

# Main function: The interaction of the aggregate demand and the short-run aggregate supply
def Shift1(MSlmis=MS,Y1=Y[-1],Y2=Y[-2],Wlab=W,Plab=PrInf(),Csd=CapCost[-1],Pinv=PrInf()):
    OutputGap=Y[-1]-Ymean()
    PriceInflation=((P[-1]-P[-2])/P[-2])
    if (OutputGap>0.05) & (PriceInflation>0.0001): # Positive Inflation
        dP=AggregateDemandCurveShift(Y1,Y2,Wlab,Plab,Csd)
        P.append(P[-1]*(1+dP))
        print(dP)
        MS.append(MS[-1]*(1+OutputGap/Ymean()))
        print(MS[-1])
        Y.append(Y[-1]*(1+(Y_Inv(MS[-1],Y[-1],dP)-Y_Inv(MS[-2],Y[-1],PriceInflation))))
        W.append(W[-1])
        CapCost.append(CapCost[-1])
    elif (OutputGap<-0.05) & (PriceInflation>0.0001): # Negative Inflation
        dP=AggregateSupplyCurveShift(Y1,Y2,Pinv)
        P.append(P[-1]*(1+dP))
        print(dP)
        W.append(W[-1]*(1+Ymean()/OutputGap))
        CapCost.append((1+dP)*CapCost[-1])
        print(W[-1])
        Y.append(Y[-1]*(CapCost[-1]/CapCost[-2]+(Y_Lab(W[-1],dP)-Y_Lab(W[-2],PriceInflation))))
        MS.append(MS[-1])
    elif (OutputGap<-0.05) & (PriceInflation<-0.0001): # Deflation
        dP=AggregateDemandCurveShift(Y1,Y2,Wlab,Plab,Csd)
        P.append(P[-1]*(1+dP))
        print(dP)
        MS.append(MS[-1]*(1+OutputGap/Ymean()))
        print(MS[-1])
        Y.append(Y[-1]*(1+(Y_Inv(MS[-1],Y[-1],dP)-Y_Inv(MS[-2],Y[-1],PriceInflation))))
        W.append(W[-1])
        CapCost.append(CapCost[-1])
    elif (OutputGap<-0.05) & (PriceInflation<-0.0001): # Dereguation
        dP=AggregateSupplyCurveShift(Y1,Y2,Pinv)
        P.append(P[-1]*(1+dP))
        print(dP)
        W.append(W[-1]*(1+Ymean()/OutputGap))
        CapCost.append((1+dP)*CapCost[-1])
        print(W[-1])
        Y.append(Y[-1]*(CapCost[-1]/CapCost[-2]+(Y_Lab(W[-1],dP)-Y_Lab(W[-2],PriceInflation))))
        MS.append(MS[-1])
    else: 
        print("Nothing")
    
    print(OutputGap,P,Y)

  # See the result
Shift1(MS[-1],Y[-1],Y[-2],W[-1],PrInf(),CapCost[-1])

print(Y)
print(P)
print(MS)
print(W)
print(CapCost)

 

 

 

No comments: