Exemplo n.º 1
0
parameters['N'] = 50 #number of consumers

#creating a dictionary that contains the parameters of the bernoulli distribution that models the endowment process
e_dist = {}
e_dist['lo'] = 0.5 #lower value in endowment distribution
e_dist['hi'] = 1 #higher value in endowment distribution
e_dist['lo_prob'] = 0.5 #prob lower earning state in endowment bernoulli distribution

#initialize interest rate variable
rate = .05

#create and initialize a list of N consumers, each with a distinct, randomly chosen beta. Beta is drawn from an uniform distribution between .9 and 1.
population = [agents.consumer(random.uniform(parameters['beta_lo'], parameters['beta_hi'])) for i in range(parameters['N'])]

#construct and initialize a single bank to represent the financial system in this economy.
bank = agents.bank(rate)

#main loop. each iteration is one time period. How long is a 'period' in this model?
bond_limit = []
borrow_matrix = np.empty((parameters['N'], parameters['T']))
borrow_adj_matrix = np.empty((parameters['N'], parameters['T']))
consump_matrix = np.empty((parameters['N'], parameters['T']))
utility_matrix = np.empty((parameters['N'], parameters['T']))

for period in range(parameters['T']):
	print(period)

	for person in population:
		idx = population.index(person)
		person.borrowing(parameters, e_dist, period, bank.rate) 
Exemplo n.º 2
0
def sen_analysis(parameters):


	# This is the main program that should be executed to run the agent-based model.
	import matplotlib.pyplot as plt
	import numpy as np
	import random
	import agents

	#breaking apart parameters
	e_dist = {}
	e_dist['lo'] = parameters['e_lo']
	e_dist['hi'] = parameters['e_hi']
	e_dist['lo_prob'] = parameters['e_lo_prob']

	rate = parameters['rate']

	#setting a seed for random number generator
	random.seed(1)

	#create and initialize a list of N consumers, each with a distinct, randomly chosen beta. Beta is drawn from an uniform distribution between .9 and 1.
	population = [agents.consumer(random.uniform(parameters['beta_lo'], parameters['beta_hi'])) for i in np.arange(parameters['N'])]

	#construct and initialize a single bank to represent the financial system in this economy.
	bank = agents.bank(rate)

	#main loop. each iteration is one time period. How long is a 'period' in this model?
	bond_limit = []
	borrow_matrix = np.empty((parameters['N'], parameters['T']))
	borrow_adj_matrix = np.empty((parameters['N'], parameters['T']))
	consump_matrix = np.empty((parameters['N'], parameters['T']))
	utility_matrix = np.empty((parameters['N'], parameters['T']))

	for period in np.arange(parameters['T']):
		if (period % 100) == 0:
			print(period)

		for person in population:
			idx = population.index(person)
			person.borrowing(parameters, e_dist, period, bank.rate) 

			#collecting borrowing/saving decision of each consumer in each period BEFORE adjusted by the bank.
			borrow_matrix[idx, period] = person.bond #collecting borrowing constrained by borrowing limit. does borrowing limit actually bind? mostly no.

		#a list collecting the borrowing limits across time. this list is graphed below.	
		bond_limit.append(person.bond_limit)

		#bank then adjusts borrowing/saving amounts so that market clears, 
		bank.clearing_market(population)

		#need to calculate consumption and utility BEFORE adjusting price since TODAY's interest rate factors into both calculations, but AFTER bank adjusts borrowing. 
		for person in population:
			idx = population.index(person)
			person.calculating_utility(parameters, bank.rate)

			consump_matrix[idx, period] = person.consumption
			utility_matrix[idx, period] = person.utility
			borrow_adj_matrix[idx, period] = person.bond #borrowing adjusted to equate supply and demand

		#bank then adjusts the interest rate based upon balance of supply and bank. This adjusted interest rate will be used next period by consumers to make borrowing/saving decision.
		bank.adjusting_price()


	return bank.supply_rec, bank.demand_rec, bank.market_balance_rec, bank.rate_rec, np.sum(consump_matrix, axis = 0), np.sum(utility_matrix, axis = 0)