def build_model(self): country = self.Country gov = ConsolidatedGovernment(country, 'GOV', 'Government') hh = Household(country, 'HH', 'Household', alpha_income=.6, alpha_fin=.4) # A literally non-profit business sector bus = FixedMarginBusiness(country, 'BUS', 'Business Sector') # Create the linkages between sectors - tax flow, markets - labour ('LAB'), goods ('GOOD') tax = TaxFlow(country, 'TF', 'TaxFlow', taxrate=.2) labour = Market(country, 'LAB', 'Labour market') goods = Market(country, 'GOOD', 'Goods market') if self.UseBookExogenous: # Need to set the exogenous variable - Government demand for Goods ("G" in economist symbology) gov.SetExogenous('DEM_GOOD', '[0.,] + [20.,] * 105') return self.Model
def build_model(self): country = self.Country gov = ConsolidatedGovernment(country, 'GOV', 'Government') hh = HouseholdWithExpectations(country, 'HH', 'Household', alpha_income=.6, alpha_fin=.4) # A literally non-profit business sector bus = FixedMarginBusiness(country, 'BUS', 'Business Sector') # Create the linkages between sectors - tax flow, markets - labour ('LAB'), goods ('GOOD') tax = TaxFlow(country, 'TF', 'TaxFlow', .2) labour = Market(country, 'LAB', 'Labour market') goods = Market(country, 'GOOD', 'Goods market') if self.UseBookExogenous: # Need to set the exogenous variable - Government demand for Goods ("G" in economist symbology) gov.SetExogenous('DEM_GOOD', '[0.,] + [20.,] * 105') # In order to replicate the book results, we need to patch in this initial condition so that the # expected income in period 1 is 16. self.Model.AddInitialCondition('HH', 'AfterTax', 16.) return self.Model
def test_LookupSector(self): mod = Model() can = Country(mod, 'Eh', 'Canada') gov = ConsolidatedGovernment(can, 'GOV', 'Government') hh = Household(can, 'HH', 'Household', .9) self.assertEqual(can.LookupSector('HH').ID, hh.ID) self.assertEqual(can.LookupSector('GOV').ID, gov.ID) with self.assertRaises(KeyError): can.LookupSector('Smurf')
def test_getitem(self): # Hits both Model and Country GetItem mod = Model() can = Country(mod, 'CA', 'Can') gov = ConsolidatedGovernment(can, 'GOV', 'Gov') us = Country(mod, 'US', 'US') with self.assertRaises(KeyError): mod['x'] with self.assertRaises(KeyError): can['x'] self.assertEqual(gov, mod['CA']['GOV'])
def CreateCountry(mod, name, code): # Create the country. cntry = Country(mod, code, name) # Create sectors ConsolidatedGovernment(cntry, 'GOV', 'Government') hou = Household(cntry, 'HH', 'Household') hou.AddVariable('TaxRate', 'Tax rate for workers', '.2') cap = Capitalists(cntry, 'CAP', 'Capitalists') cap.AddVariable('TaxRate', 'Tax rate for capitalists', '0.3') FixedMarginBusiness(cntry, 'BUS', 'Business Sector') # Create the linkages between sectors - tax flow, markets - labour ('LAB'), goods ('GOOD') TaxFlow(cntry, 'TF', 'TaxFlow', .2) Market(cntry, 'LAB', 'Labour market') Market(cntry, 'GOOD', 'Goods market') return cntry
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 test_contains(self): mod = Model() can = Country(mod, 'CA', 'Can') gov = ConsolidatedGovernment(can, 'GOV', 'Gov') self.assertIn(gov, can)
def test_AddSector(self): mod = Model() can = Country(mod, 'Eh', 'Canada') gov = ConsolidatedGovernment(can, 'GOV', 'Government') self.assertEqual(can.SectorList[0].ID, gov.ID)
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()