def initialize_shock(self, shock_config): from src.runner import Runner runner = Runner(self) from src.shock import Shock shock = Shock(self, runner) shock.read_xml_config_file(shock_config) self.shocks.append(shock)
def shock__do_shock(self, args): import os from src.bank import Bank from src.household import Household from src.firm import Firm from src.environment import Environment from src.transaction import Transaction from src.market import Market from src.updater import Updater from src.shock import Shock text = "This test checks shock.do_shock \n" self.print_info(text) # # INITIALIZATION # environment_directory = str(args[0]) identifier = str(args[1]) log_directory = str(args[2]) # Configure logging parameters so we get output while the program runs logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S', filename=log_directory + identifier + ".log", level=logging.INFO) logging.info('START logging for test shock__do_shock in run: %s', environment_directory + identifier + ".xml") # Construct household filename environment = Environment(environment_directory, identifier) # generate a household household = Household() household.identifier = "test_household" environment.households.append(household) # # TESTING # shock = Shock() print("Starting labour") print(household.labour) print("Running do_shock with parameter start") shock.do_shock(environment, 46, "start") print("Current labour") print(household.labour) print("Running do_shock with parameter end") shock.do_shock(environment, 46, "end") print("Current labour") print(household.labour)
def initialize_shock(self, shock_config): from src.runner import Runner runner = Runner(self) from src.shock import Shock shock = Shock(self, runner) shock.read_xml_config_file(shock_config) self.shocks.append(shock) shock.measure_intitial_shock(self) for k, v in shock.legend.iteritems(): if shock.legend[k] != 0: self.shock_measure = (k, v) # df_shock = pd.DataFrame[] # you can use this code below to see if the function of reading the shock worked for key in shock.asset_returns: if shock.asset_returns[key] != 0.0: # print "0. ***ENV.PY*** When shock is initialised: The asset class", key, "is shocked by", shock.asset_returns[key] * 100, "%" pass
def initialize(self, environment): self.environment = environment self.updater = Updater(self.environment) self.shocker = Shock()
def do_run(self, environment): # loop over all time steps and do the updating # We initialise the measurement class for writing outputs to csv # measurement = Measurement("Measurement", environment, self, {1: ["Step", "static", "self.runner.current_step"], # 2: ["Deposits", "dynamic", "self.environment.households[0].get_account", ["deposits"]]}, "TestMeasurement.csv") measurement = Measurement(environment, self) # And open the output file measurement.open_file() # We start the shock class as well shock_class = Shock() # For each update step for i in range(self.num_sweeps): # Do the shock: # First we check if the shock occurs at the current sweep # Then we run the shock procedure at the start of the update for shock in environment.shocks: if int(shock[0]) <= i+1 and int(shock[1]) >= i+1: shock_class.do_shock(environment, i, shock[2], "start") # the update step # append current step, this is mostly for measurements self.current_step = i # do the actual update self.updater.do_update(environment, i) # write the state of the system measurement.write_to_file() # Do the shock (revert the shock if necessary): # First we check if the shock occurs at the current sweep # Then we run the shock procedure at the end of the update for shock in environment.shocks: if int(shock[0]) <= i+1 and int(shock[1]) >= i+1: shock_class.do_shock(environment, i, shock[2], "end") # HELPER, to be removed in production # for firm in environment.households: # print(firm) # print(environment.households[0]) # print(environment.firms[0]) # capital = 0.0 # for tranx in environment.firms[0].accounts: # if tranx.type_ == "capital" and tranx.from_ == environment.firms[0]: # capital = capital + tranx.amount # if tranx.type_ == "capital" and tranx.to == environment.firms[0]: # capital = capital - tranx.amount # print(environment.firms[0].get_account("deposits")+capital-environment.firms[0].get_account("loans")) # capital = 0.0 # for tranx in environment.firms[1].accounts: # if tranx.type_ == "capital" and tranx.from_ == environment.firms[1]: # capital = capital + tranx.amount # if tranx.type_ == "capital" and tranx.to == environment.firms[1]: # capital = capital - tranx.amount # print(environment.firms[1].get_account("deposits")+capital-environment.firms[1].get_account("loans")) # capital = 0.0 # for tranx in environment.firms[2].accounts: # if tranx.type_ == "capital" and tranx.from_ == environment.firms[2]: # capital = capital + tranx.amount # if tranx.type_ == "capital" and tranx.to == environment.firms[2]: # capital = capital - tranx.amount # print(environment.firms[2].get_account("deposits")+capital-environment.firms[2].get_account("loans")) print(environment.banks[0]) # print(environment.firms[0]) # Close the output file at the end of the simulation measurement.close_file()