示例#1
0
    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)
示例#2
0
    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)
示例#3
0
    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, "labour", "start")
        print("Current labour")
        print(household.labour)
        print("Running do_shock with parameter end")
        shock.do_shock(environment, 46, "labour", "end")
        print("Current labour")
        print(household.labour)
示例#4
0
class Runner(object):
    #	from environment import Environment

    #
    # VARIABLES
    #

    #
    # METHODS
    #
    #-------------------------------------------------------------------------
    # __init__
    #-------------------------------------------------------------------------
    def __init__(self):
        pass

    #-------------------------------------------------------------------------

    #-------------------------------------------------------------------------
    # initialize()
    #-------------------------------------------------------------------------
    def initialize(self, environment):
        self.environment = environment
        self.updater = Updater(self.environment)
        self.shocker = Shock()

    #-------------------------------------------------------------------------

    #-------------------------------------------------------------------------
    # do_run
    #-------------------------------------------------------------------------
    def do_run(self, measurement, debug):
        # loop over all time steps and do the updating
        for i in range(self.environment.parameters.numSweeps):
            # the update step
            self.updater.do_update(self.environment, i, debug)

            # check if there is a shock at the current time step
            if (int(self.environment.get_state(i).shockType) != 0):
                self.shocker.do_shock(self.environment, int(i))
                self.environment.get_state(i).shockType = 0

            # do the measurement
            measurement.do_measurement(self.environment.banks)
示例#5
0
    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)
示例#6
0
    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
示例#7
0
文件: runner.py 项目: fhk/black_rhino
 def initialize(self,  environment):
     self.identifier = environment.identifier
     self.num_simulations = environment.static_parameters["numSweeps"]
     self.environment = environment
     self.updater = Updater(self.environment)
     self.shocker = Shock()
示例#8
0
文件: runner.py 项目: fhk/black_rhino
class Runner(BaseRunner):
    # from environment import Environment

    #
    # VARIABLES
    #

    identifier = ""
    num_simulations = 0

    #
    # METHODS
    #
    # -------------------------------------------------------------------------
    # __init__
    # -------------------------------------------------------------------------
    def __init__(self):
        pass
    # -------------------------------------------------------------------------

    def get_identifier(self):
        return self.identifier
    def set_identifier(self, _value):
        """
        Class variables: identifier
        Local variables: _identifier
        """
        super(Runner, self).set_identifier(_value)

    def get_num_simulations(self):
        return self.num_simulations
    def set_num_simulations(self, _value):
        """
        Class variables: num_simulations
        Local variables: _num_simulations
        """
        super(Runner, self).set_num_simulaitons(_value)

    # -------------------------------------------------------------------------
    # initialize()
    # -------------------------------------------------------------------------
    def initialize(self,  environment):
        self.identifier = environment.identifier
        self.num_simulations = environment.static_parameters["numSweeps"]
        self.environment = environment
        self.updater = Updater(self.environment)
        self.shocker = Shock()
    # -------------------------------------------------------------------------

    # -------------------------------------------------------------------------
    # do_run
    # -------------------------------------------------------------------------
    def do_run(self, measurement,  debug):
        # loop over all time steps and do the updating
        for i in range(self.num_simulations):
            # the update step
            self.updater.do_update(self.environment, i, debug)

            # check if there is a shock at the current time step
            if (int(self.environment.get_state(i).static_parameters["shockType"]) != 0):
                self.shocker.do_shock(self.environment, int(i))
                self.environment.get_state(i).static_parameters["shockType"] = 0

            # do the measurement
            measurement.do_measurement(self.environment.banks)
示例#9
0
 def initialize(self, environment):
     self.environment = environment
     self.updater = Updater(self.environment)
     self.shocker = Shock()
示例#10
0
 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()