예제 #1
0
def main():
    register_standard_logs('output', __file__)
    mod = build_model()
    mod.main()
    k = mod.GetTimeSeries('k')
    gc = mod.GetTimeSeries('S_GOV__GOLDCOVER')
    g = mod.GetTimeSeries('S_GOV__DEM_GOOD')
    Yd = mod.GetTimeSeries('S_HH__AfterTax')
    N_Yd = mod.GetTimeSeries('N_HH__AfterTax')
    Quick2DPlot(k,gc,'Southern Government Gold Cover', filename='intro_gold_cover.png')
    Quick2DPlot(k, g, 'Southern Government Consumption (G)', filename='intro_gold_gov_spend.png')
    Quick2DPlot(k, Yd, 'Southern Household Disposable Income', filename='intro_gold_Yd.png')
    Quick2DPlot(k, N_Yd, 'Northern Household Disposable Income', filename='intro_gold_N_Yd.png')
def main():
    # Create model, which holds all entities
    mod = Model()
    # Create first country - Canada. (This model only has one country.)
    can = Country(mod, 'CA', 'Canada')
    # Create sectors
    tre = Treasury(can, 'TRE', 'Treasury')
    cb = CentralBank(can, 'CB', 'Central Bank')
    hh = Household(can, 'HH', 'Household')
    # A literally non-profit business sector
    bus = FixedMarginBusiness(can, 'BUS', 'Business Sector')
    # Create the linkages between sectors - tax flow, markets - labour ('LAB'), goods ('GOOD')
    tax = TaxFlow(can, 'TF', 'TaxFlow', .2)
    labour = Market(can, 'LAB', 'Labour market')
    goods = Market(can, 'GOOD', 'Goods market')
    # Add the financial markets
    # GOV -> issuing sector
    mm = MoneyMarket(can)
    dep = DepositMarket(can)
    # --------------------------------------------
    # Financial asset demand equations
    # Need to call this before we set the demand functions for
    mod._GenerateFullSectorCodes()
    # Need the full variable name for 'F' in household
    hh_F = hh.GetVariableName('F')
    hh.AddVariable('DEM_MON', 'Demand for Money', '0.5 * ' + hh_F)
    hh.AddVariable('DEM_DEP', 'Demand for deposits', '0.5 * ' + hh_F)
    # -----------------------------------------------------------------
    # Need to set the exogenous variables
    # Government demand for Goods ("G" in economist symbology)
    mod.AddExogenous('TRE', 'DEM_GOOD', '[20.,] * 105')
    mod.AddExogenous('DEP', 'r', '[0.0,] * 5 + [0.04]*100')
    mod.AddInitialCondition('HH', 'F', 80.)
    # Build the model
    # Output is put into two files, based on the file name passed into main() ['out_SIM_Machine_Model']
    # (1) [out_YYY]_log.txt:  Log file
    # (2) [out_YYY].py:  File that solves the system of equations
    mod.MaxTime = 100
    eqns = mod._main_deprecated('out_ex20170108_model_PC')

    # Only import after the file is created (which is unusual).
    import out_ex20170108_model_PC as SFCmod
    obj = SFCmod.SFCModel()
    obj.main()
    obj.WriteCSV('out_ex20170103_model_PC.csv')
    Quick2DPlot(obj.t[1:], obj.GOOD_SUP_GOOD[1:],
                'Goods supplied (national production Y)')
    Quick2DPlot(obj.t[1:], obj.HH_F[1:], 'Household Financial Assets (F)')
예제 #3
0
def main():
    # The next line of code sets the name of the output files based on the code file's name.
    # This means that if you paste this code into a new file, get a new log name.
    register_standard_logs('output', __file__)
    # Create model, which holds all entities
    mod = Model()
    mod.EquationSolver.TraceStep = 10
    # Create first country - Canada. (This model only has one country.)
    can = Country(mod, 'CA', 'Canada')
    # Create sectors
    gov = ConsolidatedGovernment(can, 'GOV', 'Government')
    hh = Household(can, 'HH', 'Household')
    # A literally non-profit business sector
    bus = FixedMarginBusiness(can, 'BUS', 'Business Sector')
    # Create the linkages between sectors - tax flow, markets - labour ('LAB'), goods ('GOOD')
    tax = TaxFlow(can, 'TF', 'TaxFlow', .2)
    labour = Market(can, 'LAB', 'Labour market')
    goods = Market(can, 'GOOD', 'Goods market')
    # Need to set the exogenous variable - Government demand for Goods ("G" in economist symbology)
    mod.AddExogenous('GOV', 'DEM_GOOD', '[20.,] * 105')
    mod.AddExogenous('TF', 'TaxRate',
                     '[.15, .4, .05, .1, .02, .08, .4, .1, .02] + [.2]*100')
    mod.EquationSolver.ParameterSolveInitialSteadyState = True
    # Build the model
    mod.main()
    CUT = 10
    k = mod.GetTimeSeries('k', cutoff=CUT)
    goods_produced = mod.GetTimeSeries('BUS__SUP_GOOD', cutoff=CUT)
    Quick2DPlot(k,
                goods_produced,
                'National Output With Erratic Taxes',
                filename='oscillate_wildly.png')
def main():
    register_standard_logs('output', __file__)
    # Create model, which holds all entities
    mod = Model()
    can = CreateCountry(mod, 'Scenario 1', 'SCEN1')
    us = CreateCountry(mod, 'Scenario 2', 'SCEN2')
    # Need to set the exogenous variable - Government demand for Goods ("G" in economist symbology)
    mod.AddExogenous('SCEN1_GOV', 'DEM_GOOD', '[20.,] * 105')
    mod.AddExogenous('SCEN2_GOV', 'DEM_GOOD', '[20.,] * 105')
    sfc_models.Parameters.SolveInitialEquilibrium = True
    # Generate a $1 tax cut based on steady state values.
    # Scenario #1: Tax cut for workers at t=5
    # Initial tax rate is 20%, and pays $14.545 in tax, so cut tax rate to 18.6%.
    # (tax rate = [.2, .2, .2, .2, .2, .186 ,186 ...]
    mod.AddExogenous('SCEN1_HH', 'TaxRate', '[0.2,]*5 + [0.186,]*100')
    # Scenario #2: Tax cut for capitalists at t=5
    # Initial tax rate is 30%, and pays $5.455 in tax, so cut tax rate to 24.5%.
    # (tax rate = [.3, .3, .3, .3, .3, .245 , ,245 ...]
    mod.AddExogenous('SCEN2_CAP', 'TaxRate', '[0.3,]*5 + [0.245,]*100')

    mod.main()
    t = mod.GetTimeSeries('t', cutoff=30)
    scen1 = mod.GetTimeSeries('SCEN1_GOOD__SUP_GOOD', cutoff=30)
    scen2 = mod.GetTimeSeries('SCEN2_GOOD__SUP_GOOD', cutoff=30)
    p = Quick2DPlot([t, t], [scen1, scen2], 'Output - Y', run_now=False)
    p.Legend = [
        'Scenario #1 - Worker Tax Cut', 'Scenario #2 - Capitalist Tax Cut'
    ]
    p.LegendPos = 'center right'
    p.DoPlot()
예제 #5
0
def main():
    # The next line of code sets the name of the output files based on the code file's name.
    # This means that if you paste this code into a new file, get a new log name.
    sfc_models.register_standard_logs('output', __file__)
    # Create model, which holds all entities
    mod = Model()
    # Create first country - Canada. (This model only has one country.)
    can = Country(mod, 'CA', 'Canada')
    # Create sectors
    gov = ConsolidatedGovernment(can, 'GOV', 'Government')
    hh = Household(can, 'HH', 'Household')
    # A literally non-profit business sector
    bus = FixedMarginBusiness(can, 'BUS', 'Business Sector')
    # Create the linkages between sectors - tax flow, markets - labour ('LAB'), goods ('GOOD')
    tax = TaxFlow(can, 'TF', 'TaxFlow', .2)
    labour = Market(can, 'LAB', 'Labour market')
    goods = Market(can, 'GOOD', 'Goods market')
    # Add the financial markets
    # GOV -> issuing sector
    mm = MoneyMarket(can, issuer_short_code='GOV')
    dep = DepositMarket(can, issuer_short_code='GOV')
    # --------------------------------------------
    # Financial asset demand equations
    # Need the full variable name for 'F' in household
    hh_F = hh.GetVariableName('F')
    hh.AddVariable('DEM_MON', 'Demand for Money', '0.5 * ' + hh_F)
    hh.AddVariable('DEM_DEP', 'Demand for deposits', '0.5 * ' + hh_F)
    # -----------------------------------------------------------------
    # Need to set the exogenous variables
    # Government demand for Goods ("G" in economist symbology)
    mod.AddExogenous('GOV', 'DEM_GOOD', '[20.,] * 105')
    mod.AddExogenous('DEP', 'r', '[0.0,] * 5 + [0.04]*100')
    mod.AddInitialCondition('HH', 'F', 80.)
    mod.main()

    mod.TimeSeriesSupressTimeZero = True
    mod.TimeSeriesCutoff = 20
    Quick2DPlot(mod.GetTimeSeries('t'), mod.GetTimeSeries('GOOD__SUP_GOOD'),
                'Goods supplied (national production Y)')
    Quick2DPlot(mod.GetTimeSeries('t'), mod.GetTimeSeries('HH__F'),
                'Household Financial Assets (F)')
def main():
    # The next line of code sets the name of the output files based on the code file's name.
    # This means that if you paste this code into a new file, get a new log name.
    register_standard_logs('output', __file__)
    # Create model, which holds all entities
    big_mod = build_model(small_gov=False)
    small_mod = build_model(small_gov=True)
    # First set of charts: short-term effects
    CUT = 100
    k = small_mod.GetTimeSeries('k', cutoff=CUT)
    goods_small = small_mod.GetTimeSeries('BUS__PROD', cutoff=CUT)
    goods_big = big_mod.GetTimeSeries('BUS__PROD', cutoff=CUT)
    # fisc_bal =  mod.GetTimeSeries('GOV__FISC_BAL', cutoff=CUT)
    # profit = mod.GetTimeSeries('BUS__PROFORMA', cutoff=CUT)
    # Fix initial conditions
    # profit[0] = 14.
    p = Quick2DPlot([k, k], [goods_small, goods_big],
                    'National Output',
                    filename='accelerator_gummint.png',
                    run_now=False)
    p.Legend = ('Small Government', 'Big Government')
    p.DoPlot()
예제 #7
0
model_SIM = builder_SIM.build_model()
model_SIM.main()

model.TimeSeriesCutoff = 20
model_SIM.TimeSeriesCutoff = 20
time = model.GetTimeSeries('k')
Y_SIMEX = model.GetTimeSeries('GOOD__SUP_GOOD')
Y_SIM = model_SIM.GetTimeSeries('GOOD__SUP_GOOD')
income = model.GetTimeSeries('HH__AfterTax')
expected_income = model.GetTimeSeries('HH__EXP_AfterTax')
F_SIMEX = model.GetTimeSeries('HH__F')
F_SIM = model_SIM.GetTimeSeries('HH__F')

Quick2DPlot(time,
            Y_SIMEX,
            'Output (Y) - Model SIMEX',
            filename='intro_5_4_1.png')

q = Quick2DPlot([time, time], [expected_income, income],
                'Household Income in Model SIMEX',
                run_now=False,
                filename='intro_5_4_2.png')
q.Legend = ['Expected', 'Realised']
q.DoPlot()

q = Quick2DPlot([time, time], [Y_SIMEX, Y_SIM],
                'Output (Y)',
                run_now=False,
                filename='intro_5_4_3.png')
q.Legend = ['Model SIMEX', 'Model SIM']
q.DoPlot()
model = builder_PC.build_model()
Parameters.SolveInitialEquilibrium = True
# Generate the file name using an operating system independent tool - os.path.join
model.main()


model.TimeSeriesCutoff = 40

time = model.GetTimeSeries('t')
k = model.GetTimeSeries('k')
Y_PC = model.GetTimeSeries('GOOD__SUP_GOOD')
r = model.GetTimeSeries('DEP__r')
Y_d = model.GetTimeSeries('HH__AfterTax')
FB = model.GetTimeSeries('TRE__FISCBAL')
PB = model.GetTimeSeries('TRE__PRIM_BAL')
w_dep = model.GetTimeSeries('HH__WGT_DEP')
w_mon = model.GetTimeSeries('HH__WGT_MON')

# Quick2DPlot(time, r, 'Interest Rate - Model PC')
# Quick2DPlot(time, Y_PC, 'Output (Y) - Model PC')
# Quick2DPlot(time, Y_d, 'Household Disposable Income - Model PC')
# Quick2DPlot(time, FB, 'Fiscal Balance - Model PC')
# Quick2DPlot(time, PB, 'Primary Fiscal Balance')

Quick2DPlot(k[5:15], w_mon[5:15], 'Money (Currency) Weighting')
Quick2DPlot(k[5:15], r[5:15], 'Interest Rate')
Quick2DPlot(k[5:15], w_dep[5:15], 'Deposit (Treasury Bill) Weighting')
Quick2DPlot(k[5:15], Y_PC[5:15], 'Output')


def main():
    # The next line of code sets the name of the output files based on the code file's name.
    # This means that if you paste this code into a new file, get a new log name.
    register_standard_logs('output', __file__)
    # Create model, which holds all entities
    mod = Model()
    mod.EquationSolver.TraceStep = 10
    mod.EquationSolver.MaxTime = 100
    # Create first country - Canada. (This model only has one country.)
    can = Country(mod, 'CA', 'Canada')
    # Create sectors
    gov = ConsolidatedGovernment(can, 'GOV', 'Government')
    hh = Household(can, 'HH', 'Household')
    # A literally non-profit business sector
    bus = BusinessWithInvestment(can, 'BUS', 'Business Sector')
    # Create the linkages between sectors - tax flow, markets - labour ('LAB'), goods ('GOOD')
    tax = TaxFlow(can, 'TF', 'TaxFlow', .2)
    labour = Market(can, 'LAB', 'Labour market')
    goods = Market(can, 'GOOD', 'Goods market')
    # Initial conditions
    bus.AddInitialCondition('CAPITAL', 100.)
    bus.AddInitialCondition('PROD', 100.)
    bus.AddInitialCondition('INV', 95.)
    # bus.AddInitialCondition('LAG_INV', 100.)

    # bus.AddInitialCondition('LAG_SUP_GOOD', 95.)
    bus.AddInitialCondition('SUP_GOOD', 95.)
    bus.AddInitialCondition('NUMHOURS', 100.)
    # Initialise money holdings
    bizcash = 69
    hhcash = 76.
    gov.AddInitialCondition('F', -(bizcash + hhcash))
    hh.AddInitialCondition('F', hhcash)
    bus.AddInitialCondition('F', bizcash)
    # Need to set the exogenous variable - Government demand for Goods ("G" in economist symbology)
    #mod.AddExogenous('GOV', 'DEM_GOOD', '[19.,] * 20 + [25.]*100')
    mod.AddExogenous('GOV', 'DEM_GOOD', '[19.,] * 105')
    mod.AddExogenous('BUS', 'ALPHA_CAPITAL', '[1.,] * 105')
    mod.AddExogenous('HH', 'AlphaIncome', [
        .6,
    ] * 5 + [.55] * 100)

    # Build the model
    mod.main()

    # First set of charts: short-term effects
    CUT = 9
    k = mod.GetTimeSeries('k', cutoff=CUT)
    goods_produced = mod.GetTimeSeries('BUS__PROD', cutoff=CUT)
    capital_ratio = mod.GetTimeSeries('BUS__CAPITAL_RATIO', cutoff=CUT)
    investment = mod.GetTimeSeries('BUS__INVEST', cutoff=CUT)
    dem_labour = mod.GetTimeSeries('BUS__DEM_LAB', cutoff=CUT)
    inventory = mod.GetTimeSeries('BUS__INV', cutoff=CUT)
    inventory_sales = mod.GetTimeSeries('BUS__INVSALES', cutoff=CUT)
    profit = mod.GetTimeSeries('BUS__PROFORMA', cutoff=CUT)
    consumption = mod.GetTimeSeries('HH__DEM_GOOD', cutoff=CUT)
    # Fix initial condition
    investment[0] = 5.
    capital_ratio[0] = 1.
    inventory_sales[0] = 1.
    profit[0] = 14.
    consumption[0] = 76.
    print(profit)
    if True:
        p = Quick2DPlot([k, k], [goods_produced, consumption],
                        title='Effect Of Shock',
                        filename='consumption_propensity_01.png',
                        run_now=False)
        p.Legend = ['Production', 'Household Consumption']
        p.DoPlot()
        Quick2DPlot(k,
                    inventory,
                    'Inventory',
                    filename='consumption_propensity_02.png')
        Quick2DPlot(k,
                    investment,
                    'Gross Investment',
                    filename='consumption_propensity_03.png')
        # Quick2DPlot(k, inventory, 'Inventory', filename='consumption_propensity_02.png')
        return
        Quick2DPlot(k,
                    capital_ratio,
                    'Ratio of Capital to Target',
                    filename='consumption_02.png')
        Quick2DPlot(k,
                    dem_labour,
                    'Wage Income',
                    filename='consumption_03.png')

        Quick2DPlot(k,
                    inventory_sales,
                    'Inventory/Sales Ratio',
                    filename='consumption_05.png')
        Quick2DPlot(k,
                    goods_produced,
                    'Goods Produced (National Output)',
                    filename='consumption_propensity_06.png')
    # Quick2DPlot(k, profit, 'Business Sector (Pro-Forma) Profit', filename='recession_investment_07.png')
    CUT = 100
    k = mod.GetTimeSeries('k', cutoff=CUT)
    goods_produced = mod.GetTimeSeries('BUS__PROD', cutoff=CUT)
    fisc_bal = mod.GetTimeSeries('GOV__FISC_BAL', cutoff=CUT)
    profit = mod.GetTimeSeries('BUS__PROFORMA', cutoff=CUT)
    consumption = mod.GetTimeSeries('HH__DEM_GOOD', cutoff=CUT)

    # Fix initial conditions
    profit[0] = 14.

    Quick2DPlot(k,
                goods_produced,
                'Goods Produced (National Output) - Long Run',
                filename='recession_investment_07.png')
    Quick2DPlot(k,
                fisc_bal,
                'Government Fiscal Balance - Long Run',
                filename='recession_investment_08.png')
    Quick2DPlot(k,
                profit,
                'Business Sector (Pro-Forma) Profits',
                filename='recession_investment_09.png')
from sfc_models.examples.Quick2DPlot import Quick2DPlot


register_standard_logs('output', __file__)
mod = Model()
country = Country(mod, 'CO')
Household(country, 'HH')
ConsolidatedGovernment(country, 'GOV')
FixedMarginBusiness(country, 'BUS', profit_margin=.025)
Market(country, 'GOOD')
Market(country, 'LAB')
TaxFlow(country, 'TAX', taxrate=.2)
# At time period 25, cut spending to 17 (from 20)
mod.AddExogenous('GOV', 'DEM_GOOD', [20.,]* 25 + [17.,]*20)
mod.AddGlobalEquation('DEBT_GDP', 'DEBT-TO-GDP RATIO', '-100.*GOV__F/BUS__SUP_GOOD')
mod.AddGlobalEquation('DEFICIT', 'DEFICIT', '-1.*GOV__INC')
mod.EquationSolver.MaxTime = 40
mod.main()
k = mod.GetTimeSeries('k')

Rat = mod.GetTimeSeries('DEBT_GDP')
Def = mod.GetTimeSeries('GOV__INC')
spend = mod.GetTimeSeries('GOV__DEM_GOOD')

p = Quick2DPlot([k, k], [spend, Def], title='Spending and Deficit', filename='intro_X_XX_multiplier_deficit.png',
                run_now=False)
p.Legend = ['G', 'Deficit']
p.LegendPos = 'center left'
p.DoPlot()
Quick2DPlot(k, Rat, title='Debt-to-GDP Ratio', filename='intro_X_XX_multiplier_debt_gdp.png')
hh_ca = Sector(ca, 'HH', has_F=True)
hh_ca.AddVariable('GIFT', 'Sending money..', '5.')
hh_us = Sector(us, 'HH', has_F=True)
mod.RegisterCashFlow(hh_ca, hh_us, 'GIFT')
mod.EquationSolver.TraceStep = 1
mod.main()
mod.TimeSeriesCutoff = 1
series_list = ('CA_HH__F', 'US_HH__F', 'EXT_FX__NET_CAD', 'EXT_FX__NET_USD')
print('Net balance fixed')
for s in series_list:
    print(s, mod.GetTimeSeries(s)[1])

series_list = (
    'CA_GOV__GOLDPURCHASES',
    'US_GOV__GOLDPURCHASES',
)
print('Net balance fixed')
for s in series_list:
    print(s, mod.GetTimeSeries(s)[1])

# Get the data...
source = mod.EquationSolver.TimeSeriesStepTrace
x = source['iteration']
y = source['CA_GOV__GOLDPURCHASES']
stop = 50
Quick2DPlot(x[0:stop],
            y[0:stop],
            'Solution evolution for gold purchases',
            filename='intro_goldstandard_iteration.png')
예제 #12
0
def main():
    # The next line of code sets the name of the output files based on the code file's name.
    # This means that if you paste this code into a new file, get a new log name.
    sfc_models.register_standard_logs('output', __file__)
    # Create model, which holds all entities
    mod = Model()
    # Create first country - Canada.
    can = Country(mod, 'CA', 'Canada')
    # Create sectors
    gov = ConsolidatedGovernment(can, 'GOV', 'Government')
    hh = Household(can, 'HH', 'Household')
    # A literally non-profit business sector
    bus = FixedMarginBusiness(can, 'BUS', 'Business Sector')
    # Create the linkages between sectors - tax flow, markets - labour ('LAB'), goods ('GOOD')
    tax = TaxFlow(can, 'TF', 'TaxFlow', .2)
    labour = Market(can, 'LAB', 'Labour market')
    goods = Market(can, 'GOOD', 'Goods market')

    # Create a second country, with non-zero profits
    # This is a very error-prone way of building the model; if we repeat code blocks, they should be in
    # a function.
    # Create United States - Almost identical to Canada.
    us = Country(mod, 'US', 'United States')
    # Create sectors
    gov2 = ConsolidatedGovernment(us, 'GOV', 'Government')
    hh2 = Household(us, 'HH', 'Household')
    # ********** Profit margin of 10% *****************
    bus2 = FixedMarginBusiness(us, 'BUS', 'Business Sector', profit_margin=.1)
    # Create the linkages between sectors - tax flow, markets - labour ('LAB'), goods ('GOOD')
    tax2 = TaxFlow(us, 'TF', 'TaxFlow', .2)
    labor2 = Market(us, 'LAB', 'Labor market')
    goods2 = Market(us, 'GOOD', 'Goods market')
    # *****************************************************************
    # Need to set the exogenous variable - Government demand for Goods ("G" in economist symbology)
    # Since we have a two country model, we need to specify the full sector code, which includes the country code.
    mod.AddExogenous('CA_GOV', 'DEM_GOOD', '[20.,] * 105')
    mod.AddExogenous('US_GOV', 'DEM_GOOD', '[20.,] * 105')

    # Do the main work of building and solving the model
    mod.main()
    CUT = 25
    t = mod.GetTimeSeries('t', cutoff=CUT)
    Y_CA = mod.GetTimeSeries('CA_GOOD__SUP_GOOD', cutoff=CUT)
    Y_US = mod.GetTimeSeries('US_GOOD__SUP_GOOD', cutoff=CUT)
    p = Quick2DPlot([t, t], [Y_CA, Y_US], 'Output - Y', run_now=False)
    p.Legend = ['Canada (0% profit)', 'U.S. (10% Profit)']
    p.DoPlot()
    F_CA = mod.GetTimeSeries('CA_BUS__F', cutoff=CUT)
    F_US = mod.GetTimeSeries('US_BUS__F', cutoff=CUT)
    p = Quick2DPlot([t, t], [F_CA, F_US],
                    'Business Sector Financial Assets (F)',
                    run_now=False)
    p.Legend = ['Canada (0% profit)', 'U.S. (10% Profit)']
    p.DoPlot()
    BAL_CA = mod.GetTimeSeries('CA_GOV__FISC_BAL', cutoff=CUT)
    BAL_US = mod.GetTimeSeries('US_GOV__FISC_BAL', cutoff=CUT)
    p = Quick2DPlot([t, t], [BAL_CA, BAL_US],
                    'Government Financial Balance',
                    run_now=False)
    p.Legend = ['Canada (0% profit)', 'U.S. (10% Profit)']
    p.DoPlot()
# This next line imports all of the objects used.
# The syntax "from <module> import *" is frowned upon, but I want to reduce the number of lines of
# code in these simpler examples.
from sfc_models.objects import *
from sfc_models.examples.Quick2DPlot import Quick2DPlot

# The next line of code sets the name of the output files based on the code file's name.
# This means that if you paste this code into a new file, get a new log name.
register_standard_logs('output', __file__)
# Create model, which holds all entities
mod = Model()
# Create first country - Canada. (This model only has one country.)
can = Country(mod, 'CA', 'Canada')
# Create sectors
gov = ConsolidatedGovernment(can, 'GOV', 'Government')
hh = Household(can, 'HH', 'Household')
# A literally non-profit business sector
bus = FixedMarginBusiness(can, 'BUS', 'Business Sector')
labour = Market(can, 'LAB', 'Labour market')
goods = Market(can, 'GOOD', 'Goods market')
# Need to set the exogenous variable - Government demand for Goods ("G" in economist symbology)
mod.AddExogenous('GOV', 'DEM_GOOD', '[20.,] * 105')
# Build the model
mod.main()
CUT = 10
k = mod.GetTimeSeries('k', cutoff=CUT)
goods_produced = mod.GetTimeSeries('BUS__SUP_GOOD', cutoff=CUT)
print("Goods Production at time 1 = {0}".format(goods_produced[1]))
Quick2DPlot(k, goods_produced, 'Goods Produced (National Output)')

mod20 = build_model(government_consumption=20.0)
mod20.main()
mod25 = build_model(government_consumption=25.0)
mod25.main()
k = mod20.GetTimeSeries('k')
Y20 = mod20.GetTimeSeries('BUS__SUP_GOOD')
Rat20 = mod20.GetTimeSeries('DEBT_GDP')
Def20 = mod20.GetTimeSeries('GOV__INC')
Y30 = mod25.GetTimeSeries('BUS__SUP_GOOD')
Rat30 = mod25.GetTimeSeries('DEBT_GDP')
Def30 = mod25.GetTimeSeries('GOV__INC')

p = Quick2DPlot([k, k], [Y20, Y30],
                title='Output in Simulations',
                filename='intro_X_XX_sim_fiscal.png',
                run_now=False)
p.Legend = ['Scenario #1', 'Scenario #2']
p.DoPlot()
p = Quick2DPlot([k, k], [Def20, Def30],
                title='Fiscal Balance',
                filename='intro_X_XX_sim_deficit.png',
                run_now=False)
p.Legend = ['Scenario #1', 'Scenario #2']
p.DoPlot()
p = Quick2DPlot([k, k], [Rat20, Rat30],
                title='Debt-to-GDP Ratio',
                filename='intro_X_XX_sim_debt_gdp.png',
                run_now=False)
p.Legend = ['Scenario #1', 'Scenario #2']
p.DoPlot()
예제 #15
0
# Step 1.5: set up logging
# The next line of code sets the name of the output files based on the code file's name.
# This means that if you paste this code into a new file, get a new log name.
register_standard_logs('output', __file__)

# Step 2: build the model objects
# Create model, which holds all entities
mod = Model()
# Create first country - Canada. (This model only has one country.)
can = Country(mod, 'CA', 'Canada')
# Create sectors
gov = ConsolidatedGovernment(can, 'GOV', 'Government')
hh = Household(can, 'HH', 'Household')
# A literally non-profit business sector
bus = FixedMarginBusiness(can, 'BUS', 'Business Sector', profit_margin=0.0)
# Create the linkages between sectors - tax flow, markets - labour ('LAB'), goods ('GOOD')
tax = TaxFlow(can, 'TF', 'TaxFlow', .2)
labour = Market(can, 'LAB', 'Labour market')
goods = Market(can, 'GOOD', 'Goods market')
# Need to set the exogenous variable - Government demand for Goods ("G" in economist symbology)
mod.AddExogenous('GOV', 'DEM_GOOD', '[20.,] * 105')
# Step 3: Invoke the method ("main") that builds the model.
mod.main()

# Once the framework has built and solved the model equations, we can either work with the output files,
# or within Python. Here, we do a plot with Quick2DPlot.
mod.TimeSeriesCutoff = 20
time = mod.GetTimeSeries('k')
Y_SIM = mod.GetTimeSeries('GOOD__SUP_GOOD')
Quick2DPlot(time, Y_SIM, 'Output (Y) - Model SIM', filename='intro_3_02_Y.png')
예제 #16
0
country = Country(mod, 'CO')
Household(country, 'HH')
gov = ConsolidatedGovernment(country, 'GOV')
FixedMarginBusiness(country, 'BUS')
Market(country, 'GOOD')
Market(country, 'LAB')
TaxFlow(country, 'TAX', taxrate=.2)
# Set the demand for goods to be (1.02)^k
gov.SetEquationRightHandSide('DEM_GOOD', 'pow(1.02, k)')

mod.AddGlobalEquation('DEBT_GDP', 'DEBT-TO-GDP RATIO',
                      '-100.*GOV__F/BUS__SUP_GOOD')
mod.AddGlobalEquation('DEFICIT', 'DEFICIT', '-100.*GOV__INC/BUS__SUP_GOOD')
mod.EquationSolver.MaxTime = 40
mod.EquationSolver.ParameterSolveInitialSteadyState = False
mod.main()
k = mod.GetTimeSeries('k')

Rat = mod.GetTimeSeries('DEBT_GDP')
Def = mod.GetTimeSeries('DEFICIT')
spend = mod.GetTimeSeries('GOV__DEM_GOOD')

Quick2DPlot(k,
            Def,
            'Deficit Ratio (2% growth/year)',
            filename='intro_X_XX_sim_growing_deficit.png')
Quick2DPlot(k,
            Rat,
            title='Debt-to-GDP Ratio, (2% growth/year)',
            filename='intro_X_XX_sim_growing_fiscal.png')
Nd = Y/W                             # (3.11)
# Params
alpha1 = 0.6
alpha2 = 0.4
theta = 0.2
W = 1.0
# Initial conditions
Hh(0) = 80.0
Hs(0) = 80.0
# Exogenous variable
Gd = [20., ] * 35 + [25., ] * 66
# Length of simulation
MaxTime = 100
"""

obj = generator.IterativeMachineGenerator(eqn)
obj.main(filename)

# Can only import now...
import SIM_model

obj = SIM_model.SFCModel()
obj._main_deprecated()

# Lop off t = 0 because it represents hard-coded initial conditions
Quick2DPlot(obj.t[1:], obj.Y[1:], 'Y - National Production')
Quick2DPlot(obj.t[1:], obj.Y[1:], 'G - Government Consumption')
print("Validate that Hh = Hs")
Quick2DPlot(obj.t[1:], obj.Hh[1:], 'Hh - Household Money Holdings')
Quick2DPlot(obj.t[1:], obj.Hs[1:], 'Hs - Money Supplied by the Gummint')