def market__rationing(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 text = "This test checks market.rationing \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 market__rationing in run: %s', environment_directory + identifier + ".xml") # Construct household filename environment = Environment(environment_directory, identifier) # generate a bank bank = Bank() bank.identifier = "test_bank" environment.banks.append(bank) # generate a firm firm = Firm() firm.identifier = "test_firm" environment.firms.append(firm) # generate a household household = Household() household.identifier = "test_household" environment.households.append(household) # # TESTING # market = Market("market") rationed = market.rationing([["agent1", 5], ["agent2", 7], ["agent3", -3], ["agent4", -4]]) print("Pairs found through rationing:") print(rationed)
def sell_labour(self, environment, time): # First we find the market equilibrium price # Important to note that this currently does # not depend on the wealth of the buyers # That is their demand may be higher than # what they can actually buy, which may be ok # We set the values necessary for tatonnement # The list of sellers and their supply functions sellers = [] for agent in environment.households: sellers.append([agent, agent.supply_of_labour_solow]) # And the list of buyers and their demand functions buyers = [] for agent in environment.firms: buyers.append([agent, agent.demand_for_labour_solow]) # We may start the search for price at some specific point # Here we pass 0, which means it'll start looking at a # random point between 0 and 10 starting_price = 0.0 # We initialize the price price = 0.0 # Put the appropriate settings, i.e. desired identifier market = Market("market") # And we find the market price of labour # given supply and demand of the agents # and tolerance of error, resolution of search # and amplification factor for exponential search price = market.tatonnement(sellers, buyers, starting_price, 0.00000000001, 0.01, 1.1) environment.variable_parameters["price_of_labour"] = price # now we use rationing to find the actual transactions between agents for_rationing = [] for household in environment.households: for_rationing.append( [household, household.supply_of_labour_solow(price)]) for firm in environment.firms: for_rationing.append([firm, -firm.demand_for_labour_solow(price)]) # And we find the rationing, ie the amounts # of goods sold between pairs of agents rationed = market.rationing(for_rationing) # # A (from) L (to) # bank loan deposit # household deposit labour # firm labour loan # for ration in rationed: # The labour is an asset (production factor) for the firm # and a liability (promise to work) for the household environment.new_transaction("labour", "", ration[1].identifier, ration[0].identifier, ration[2], 0, 0, -1) random_bank = random.choice(environment.banks) # Deposit is a liability of the bank # and an asset of the household environment.new_transaction("deposits", "", ration[0].identifier, random_bank.identifier, ration[2] * price, random_bank.interest_rate_deposits, 0, -1) # Loan is an asset of the bank # and a liability of the firm environment.new_transaction("loans", "", random_bank.identifier, ration[1].identifier, ration[2] * price, random_bank.interest_rate_loans, 0, -1) # We print the action of selling to the screen print( "{}s sold {}d units of labour at a price {}f to {}s at time {}d." .format(ration[0].identifier, ration[2], price, ration[1].identifier, time)) logging.info(" labour sold to firms on step: %s", time)