def main(): """ Demonstration of the simulation.advance_round function, which can take arbitrary values """ simulation = Simulation() agents = simulation.build_agents(Agent, 'agent', number=1) weekday = 0 for year in range(2000, 2010): for month in range(12): for day in range(30): simulation.advance_round((year, month, day)) weekday = (weekday + 1) % 7 print(weekday) if weekday == 3: agents.wednessday() if day == 1: agents.first() if month == 12 and day == 31: agents.newyearseve() if day <= 7 and weekday == 5: agents.firstfriday() if day == 15: agents.fiveteens() agents.panel_log(possessions=['money']) agents.agg_log(possessions=['labor']) simulation.finalize()
def main(parameters): simulation = Simulation(processes=1) simulation.declare_round_endowment(resource='adult', units=1, product='labor') simulation.declare_perishable(good='labor') firms = simulation.build_agents(Firm, 'firm', number=parameters['num_firms']) households = simulation.build_agents(Household, 'household', number=1, parameters=parameters) try: for rnd in range(parameters['rounds']): simulation.advance_round(rnd) households.sell_labor() firms.buy_labor() firms.production() firms.panel_log(possessions=['money', 'GOOD'], variables=['price', 'inventory']) firms.quotes() households.buy_goods() firms.sell_goods() households.agg_log(possessions=['money', 'GOOD'], variables=['current_utiliy']) households.consumption() firms.adjust_price() except Exception as e: print(e)
def main(): s = Simulation() a = s.build_agents(MyAgent, 'myagent', 10000) for r in range(50): s.advance_round(r) a.do("compute") s.finalize()
def main(): simulation_parameters = { 'name': 'direct_optimization', 'random_seed': None, 'rounds': 500, 'trade_logging': 'off', 'num_firms': 250, 'alpha': 0.3, 'gamma': 0.8, 'price_stickiness': 0.0, 'network_weight_stickiness': 0.0, 'wage_stickiness': 0.0, 'dividends_percent': 0.0, 'percentage_beneficiaries': 0.25, 'percentage_injection': 0.25, 'time_of_intervention': 250 } s = Simulation(name=simulation_parameters['name']) s.declare_service('labor_endowment', 1, 'labor') network = create_network(simulation_parameters['num_firms']) network = [ network.neighbors(neighbor) for neighbor in range(simulation_parameters['num_firms']) ] firms = s.build_agents(Firm, 'firm', parameters=simulation_parameters, agent_parameters=network) household = s.build_agents(Household, 'household', 1, parameters=simulation_parameters) centralbank = s.build_agents(CentralBank, 'centralbank', 1, parameters=simulation_parameters) for rnd in range(simulation_parameters['rounds']): s.advance_round(rnd) (firms + household).send_demand() (firms + household).selling() (firms + household).buying() firms.production() firms.dividends() household.consuming() firms.change_weights() firms.stats() centralbank.intervention() household.agg_log(possessions=['money'], variables=['utility', 'rationing']) firms.agg_log(possessions=['money'], variables=[ 'produced', 'profit', 'price', 'dead', 'inventory', 'rationing' ]) s.graphs()
def main(): s = Simulation(processes=8) myagents = s.build_agents(MyAgent, 'myagent', 50000) youragents = s.build_agents(YourAgent, 'youragent', 50000) for r in range(100): s.advance_round(r) # (myagents+youragents).do('compute') youragents.s() myagents.g() s.finalize()
def main(simulation_parameters): s = Simulation() firms = s.build_agents(Firm, 'firm', 10) households = s.build_agents(Household, 'household', 10) for r in range(int(simulation_parameters['rounds'])): s.advance_round(r) firms.panel_log(possessions=['cookies']) firms.quote() households.buying() firms.selling() households.panel_log(possessions=['cookies']) households.consumption() s.finalize()
def main(simulation_parameters): s = Simulation() firms = s.build_agents( Firm, 'firm', parameters=simulation_parameters, number=1) market = s.build_agents( Market, 'market', parameters=simulation_parameters, number=1) for r in range(simulation_parameters['rounds']): s.advance_round(r) firms.my_production() firms.selling() market.buying() firms.adjust_price() firms.adjust_quantity() market.consumption() s.finalize()
def main(): s = Simulation() buy = s.build_agents(Buy, group_name='buy', number=2, parameters=simulation_parameters) sell = s.build_agents(Sell, group_name='sell', number=2, parameters=simulation_parameters) all = buy + sell for r in range(simulation_parameters['num_rounds']): s.advance_round(r) for r in range(20000): all.one() all.two() all.three() all.clean_up() all.all_tests_completed()
def main(): s = Simulation(name='Sticky Prices Microfoundations') s.declare_perishable('labor') firms = s.build_agents(Firm, 'firm', 1) market = s.build_agents(Market, 'market', 1) labormarket = s.build_agents(LaborMarket, 'labormarket', 1) for r in range(20): s.advance_round(r) firms.do('quote_hire') labormarket.do('accepting') firms.do('hire') firms.do('my_production') firms.do('selling') market.do('buying') firms.do('adjust_price') firms.do('adjust_quantity') market.do('consumption')
def main(): simulation = Simulation(name="NORI Token Market Simulation v0.1") print(simulation) # simulation.declare_round_endowment() IS THIS NECESSARY? suppliers = simulation.build_agents( Supplier, 'supplier', 100) # Put these in parameters.csv and use .build_agents_from_file simulation.build_agents(Spotbuyer, 'spotbuyer', 100) simulation.build_agents(Speculator, 'speculator', 1000) simulation.build_agents(Coinex, 'coinex', 1) # Create supplier_queue from 'crc_supply_sample.csv' in order returned from the code in lines 70-75, above # Each supplier has an associated marginal_cost and marginal_qty # For supplier i, if expected_price >= reserve_price, # list_crc and remove from queue # else evaluate the next element in list # LIKE THIS? # Make 100 suppliers #for supplier_number in range(100): # new_supplier = {'marginal_cost': X, 'marginal_qty': Y, 'expected_price': Z} # supplier_queue.append(new_supplier) for round in range(360): # Assume 360 trading days per year simulation.advance_round(round) Supplier().self.list_crc( ) # IS THIS THE RIGHT WAY TO DO THIS? Supplier lists CRC if expected_price > marginal_cost spotbuyer.buy_nori() # Spot Buyer buys NORI from Coinex coinex.exch_sell_nori() # Coinex sells NORI to Spot Buyer spotbuyer.buy_crc() # Spot Buyer purchases CRC spotbuyer.retire_crc() # Spot Buyer (smart contract) retires CRC (supplier + spotbuyer()).panel_log(...) # Log CRC trades speculator.trade_nori() # Speculators trade supplier.sell_nori() # Supplier sells NORI to Coinex speculator.sell_nori() # Speculator sells NORI to Coinex coinex.exch_buy_nori() # Coinex buys coinex.panel_log(...) # Log NORI trades # Do we need to clear trades? If so, how? simulation.graphs() simulation.finalize()
def main(simulation_parameters): s = Simulation(name=simulation_parameters['name']) s.declare_service('labor_endowment', 1, 'labor') network = create_network(simulation_parameters['num_firms']) network = [ network.neighbors(neighbor) for neighbor in range(simulation_parameters['num_firms']) ] firms = s.build_agents(Firm, 'firm', parameters=simulation_parameters, agent_parameters=network) household = s.build_agents(Household, 'household', 1, parameters=simulation_parameters) centralbank = s.build_agents(CentralBank, 'centralbank', 1, parameters=simulation_parameters) for rnd in range(simulation_parameters['rounds']): s.advance_round(rnd) (firms + household).send_demand() (firms + household).selling() (firms + household).buying() firms.production() firms.dividends() household.consuming() firms.change_weights() firms.stats() centralbank.intervention() household.agg_log(possessions=['money'], variables=['utility', 'rationing']) firms.agg_log(possessions=['money'], variables=[ 'produced', 'profit', 'price', 'dead', 'inventory', 'rationing' ]) s.finalize()
def main(processes, rounds): s = Simulation(processes=processes, name='unittest') print('build Buy') buy = s.build_agents(Buy, 'buy', 1000, rounds=rounds) print('build Sell') sell = s.build_agents(Sell, 'sell', 1000, rounds=rounds) print('build Give') give = s.build_agents(Give, 'give', 2, rounds=rounds) print('build LoggerTest') loggertest = s.build_agents(LoggerTest, 'loggertest', 1, rounds=rounds) all = buy + sell + give + loggertest for r in range(rounds): s.advance_round(r) for _ in range(5): buy.one() buy.two() buy.three() buy.clean_up() buy.panel_log(variables=['price']) for _ in range(5): sell.one() sell.two() sell.three() sell.clean_up() for _ in range(5): give.one() give.two() give.three() give.clean_up() for _ in range(5): loggertest.one() loggertest.two() loggertest.three() loggertest.clean_up() all.all_tests_completed() s.finalize()
def main(simulation_parameters): w = Simulation() w.declare_round_endowment(resource='labor_endowment', units=5, product='labor') w.declare_perishable(good='labor') firms = w.build_agents(Firm, 'firm', 2) households = w.build_agents(Household, 'household', 2) for r in range(simulation_parameters['rounds']): w.advance_round(r) # to access round, just get the value of w.round # to access its datetime version, use w._round # todo, better naming households.sell_labor() firms.buy_inputs() firms.production() firms.panel_log(possessions=['consumption_good', 'intermediate_good']) firms.sell_intermediary_goods() households.buy_intermediary_goods() households.panel_log(possessions=['consumption_good']) households.consumption() w.finalize()
def main(): s = Simulation(processes=1) grid = MultiGrid(50, 50, True) # build sugar and spice sugar_distribution = pylab.genfromtxt("sugar-map.txt") spice_distribution = sugar_distribution.T sugars = [] spices = [] for _, x, y in grid.coord_iter(): max_sugar = sugar_distribution[x, y] max_spice = spice_distribution[x, y] sugar = SugarPatch((x, y), max_sugar) spice = SpicePatch((x, y), max_spice) sugars.append(sugar) spices.append(spice) grid.place_agent(sugar, (x, y)) grid.place_agent(spice, (x, y)) # build agents agents = s.build_agents(SsAgent, 'SsAgent', 100, parameters={'grid': grid}) # prices = [] for r in range(100): s.advance_round(r) for sugar in sugars: sugar.step() for spice in spices: spice.step() agents.move() agents.eat() print(',', len(agents.trade_with_neighbors())) agents.trade() agents.agg_log(possessions=['sugar', 'spice']) s.graphs()
def main(simulation_parameters): sam = Sam( 'climate_square.sam.csv', inputs=[ 'col', 'ele', 'gas', 'o_g', 'oil', 'eis', 'trn', 'roe', 'lab', 'cap' ], outputs=['col', 'ele', 'gas', 'o_g', 'oil', 'eis', 'trn', 'roe'], output_tax='tax', consumption=['col', 'ele', 'gas', 'o_g', 'oil', 'eis', 'trn', 'roe'], consumers=['hoh']) """ reads the social accounting matrix and returns coefficients of a cobb-douglas model """ carbon_prod = defaultdict(float) carbon_prod.update({ 'col': 2112 * 1e-4, 'oil': 2439.4 * 1e-4, 'gas': 1244.3 * 1e-4 }) """ this is the co2 output per sector at the base year """ print(sam.output_tax_shares()) simulation_parameters.update({ 'name': 'cce', 'random_seed': None, 'num_household': 1, 'num_firms': 1, 'endowment_FFcap': sam.endowment('cap'), 'endowment_FFlab': sam.endowment('lab'), 'final_goods': sam.consumption, 'capital_types': ['cap', 'lab'], 'dividends_percent': 0.0, 'production_functions': sam.production_functions(), 'consumption_functions': sam.utility_function(), 'output_tax_shares': sam.output_tax_shares(), 'money': 2691.2641884030372, 'inputs': sam.inputs, 'outputs': sam.outputs, 'balance_of_payment': sam.balance_of_payment('nx', 'inv'), 'sam': sam, 'carbon_prod': carbon_prod, 'wage_stickiness': 0.5, 'price_stickiness': 0.5, 'network_weight_stickiness': 0.5 }) simulation = Simulation(trade_logging='group', processes=1) simulation.declare_service('endowment_FFcap', 1, 'cap') simulation.declare_service('endowment_FFlab', 1, 'lab') """ every round for every endowment_FFcap the owner gets one good of lab similar for cap""" firms = { good: simulation.build_agents(Firm, number=simulation_parameters['num_firms'], group_name=good, parameters=simulation_parameters) for good in sam.outputs } household = simulation.build_agents(Household, 'household', simulation_parameters['num_household'], parameters=simulation_parameters) netexport = simulation.build_agents(NetExport, 'netexport', 1, parameters=simulation_parameters) government = simulation.build_agents(Government, 'government', 1, parameters=simulation_parameters) firms_and_household = sum(firms.values()) + household all_firms = sum(firms.values()) try: for r in range(simulation_parameters['rounds']): simulation.advance_round(r) all_firms.taxes_intervention() firms_and_household.send_demand() firms_and_household.selling() firms_and_household.buying() household.money_to_nx() all_firms.production() all_firms.carbon_taxes() all_firms.sales_tax() government.taxes_to_household() all_firms.international_trade() all_firms.invest() netexport.invest() household.sales_accounting() all_firms.dividends() all_firms.change_weights() all_firms.stats() household.agg_log(variables=['welfare']) (firms['col'] + firms['gas'] + firms['oil']).agg_log(variables=['price', 'produced', 'co2']) (firms['ele'] + firms['o_g'] + firms['eis'] + firms['trn'] + firms['roe']).agg_log(variables=['price', 'produced']) household.consuming() except Exception as e: print(e) simulation.finalize() # raise # put raise for full traceback but no graphs in case of error iotable.to_iotable(simulation.path, [99, simulation_parameters['rounds'] - 1]) mean_price = iotable.average_price(simulation.path, 99) print('mean price', mean_price) # simulation.graphs() return mean_price
def main(processes, rounds): s = Simulation(processes=processes, name='unittest') s.declare_round_endowment(resource='labor_endowment', units=5, product='labor', groups=['all']) s.declare_round_endowment(resource='cow', units=10, product='milk', groups=['all']) s.declare_perishable(good='labor') s.panel('buy', variables=['price']) # s.declare_expiring('xcapital', 5) print('build Buy') buy = s.build_agents(Buy, 'buy', 1000, parameters={'rounds': rounds}) print('build Sell') # s.build_agents(QuoteBuy, 2) sell = s.build_agents(Sell, 'sell', 1000, parameters={'rounds': rounds}) print('build Give') give = s.build_agents(Give, 'give', 2, parameters={'rounds': rounds}) # tests give and messaging print('build Endowment') endowment = s.build_agents(Endowment, 'endowment', 2, parameters={ 'rounds': rounds, 'creation': 0 }) # tests declare_round_endowment and declare_perishable print('build LoggerTest') loggertest = s.build_agents(LoggerTest, 'loggertest', 1, parameters={'rounds': rounds}) print('build ProductionMultifirm') productionmultifirm = s.build_agents(ProductionMultifirm, 'productionmultifirm', 1, parameters={'rounds': rounds}) print('build ProductionFirm') productionfirm = s.build_agents(ProductionFirm, 'productionfirm', 7, parameters={'rounds': rounds}) print('build UtilityHousehold') utilityhousehold = s.build_agents(UtilityHousehold, 'utilityhousehold', 5, parameters={'rounds': rounds}) # print('build ContractSeller') # contractseller = s.build_agents(ContractSeller, 'contractseller', 2, # parameters={'rounds': rounds}) # print('build ContractBuyer') # contractbuyer = s.build_agents(ContractBuyer, 'contractbuyer', 2, # parameters={'rounds': rounds}) # print('build ContractSellerStop') # contractsellerstop = s.build_agents(ContractSellerStop, # 'contractsellerstop', 2, parameters={'rounds': rounds}) # print('build ContractBuyerStop') # contractbuyerstop = s.build_agents(ContractBuyerStop, # 'contractbuyerstop', 2, parameters={'rounds': rounds}) # s.build_agents(ExpiringCapital, 1) # s.build_agents(GiveExpiringCapital, 2) print('build BuyExpiringCapital') _ = s.build_agents(BuyExpiringCapital, 'buyexpiringcapital', 2, parameters={'rounds': rounds}) print('build MessageA') messagea = s.build_agents(MessageA, 'messagea', 20, parameters={'rounds': rounds}) print('build MessageB') messageb = s.build_agents(MessageB, 'messageb', 20, parameters={'rounds': rounds}) print('build Killer') killer = s.build_agents(Killer, 'killer', 1, parameters={'rounds': rounds}) print('build Victim') victim = s.build_agents(Victim, 'victim', rounds, parameters={'rounds': rounds}) print('build Victim loudvictim') _ = s.build_agents(Victim, 'loudvictim', rounds, parameters={'rounds': rounds}) some = buy + sell + give + loggertest + utilityhousehold # contractagents = (contractbuyer + contractseller # + contractbuyerstop + contractsellerstop) print('build AddAgent') addagent = s.build_agents(AddAgent, 'addagent', 0) for r in range(rounds): s.advance_round(r) for _ in range(5): buy.do('one') buy.do('two') buy.do('three') buy.do('clean_up') buy.do('panel') for _ in range(5): sell.do('one') sell.do('two') sell.do('three') sell.do('clean_up') for _ in range(5): give.do('one') give.do('two') give.do('three') give.do('clean_up') for _ in range(5): loggertest.do('one') loggertest.do('two') loggertest.do('three') loggertest.do('clean_up') for _ in range(5): utilityhousehold.do('one') utilityhousehold.do('two') utilityhousehold.do('three') utilityhousehold.do('clean_up') endowment.do('Iconsume') productionmultifirm.do('production') productionfirm.do('production') utilityhousehold.do('consumption') (messagea + messageb).do('sendmsg') (messageb + messagea).do('recvmsg') # (contractbuyer + contractbuyerstop).do('request_offer') # (contractseller + contractsellerstop).do('make_offer') # contractagents.do('accept_offer') # contractagents.do('deliver') # contractagents.do('pay') # contractagents.do('control') killer.do('kill') killer.do('send_message') victim.do('am_I_dead') some.do('all_tests_completed') addagent.do('add_agent') s.finalize()
def main(processes, rounds): s = Simulation(processes=processes, name='unittest') s.declare_round_endowment(resource='labor_endowment', units=5, product='labor') s.declare_round_endowment(resource='cow', units=10, product='milk') s.declare_perishable(good='labor') # s.declare_expiring('xcapital', 5) print('build Buy') buy = s.build_agents(Buy, 'buy', 1000, parameters={'rounds': rounds}) print('build Sell') # s.build_agents(QuoteBuy, 2) sell = s.build_agents(Sell, 'sell', 1000, parameters={'rounds': rounds}) print('build Give') give = s.build_agents(Give, 'give', 2, parameters={'rounds': rounds}) # tests give and messaging print('build Endowment') endowment = s.build_agents(Endowment, 'endowment', 2, parameters={ 'rounds': rounds, 'creation': 0 }) # tests declare_round_endowment and declare_perishable print('build LoggerTest') loggertest = s.build_agents(LoggerTest, 'loggertest', 1, parameters={'rounds': rounds}) print('build ProductionMultifirm') productionmultifirm = s.build_agents(ProductionMultifirm, 'productionmultifirm', 1, parameters={'rounds': rounds}) print('build ProductionFirm') productionfirm = s.build_agents(ProductionFirm, 'productionfirm', 7, parameters={'rounds': rounds}) print('build UtilityHousehold') utilityhousehold = s.build_agents(UtilityHousehold, 'utilityhousehold', 5, parameters={'rounds': rounds}) # print('build ContractSeller') # contractseller = s.build_agents(ContractSeller, 'contractseller', 2, # parameters={'rounds': rounds}) # print('build ContractBuyer') # contractbuyer = s.build_agents(ContractBuyer, 'contractbuyer', 2, # parameters={'rounds': rounds}) # print('build ContractSellerStop') # contractsellerstop = s.build_agents(ContractSellerStop, # 'contractsellerstop', 2, parameters={'rounds': rounds}) # print('build ContractBuyerStop') # contractbuyerstop = s.build_agents(ContractBuyerStop, # 'contractbuyerstop', 2, parameters={'rounds': rounds}) # s.build_agents(ExpiringCapital, 1) # s.build_agents(GiveExpiringCapital, 2) print('build BuyExpiringCapital') _ = s.build_agents(BuyExpiringCapital, 'buyexpiringcapital', 2, parameters={'rounds': rounds}) print('build MessageA') messagea = s.build_agents(MessageA, 'messagea', 20, parameters={'rounds': rounds}) print('build MessageB') messageb = s.build_agents(MessageB, 'messageb', 20, parameters={'rounds': rounds}) some = buy + sell + give + loggertest + utilityhousehold # contractagents = (contractbuyer + contractseller # + contractbuyerstop + contractsellerstop) for r in range(rounds): s.advance_round(r) for _ in range(5): buy.one() buy.two() buy.three() buy.clean_up() buy.panel_log(variables=['price']) for _ in range(5): sell.one() sell.two() sell.three() sell.clean_up() for _ in range(5): give.one() give.two() give.three() give.clean_up() for _ in range(5): loggertest.one() loggertest.two() loggertest.three() loggertest.clean_up() for _ in range(5): utilityhousehold.one() utilityhousehold.two() utilityhousehold.three() utilityhousehold.clean_up() endowment.Iconsume() productionmultifirm.production() productionfirm.production() utilityhousehold.consumption() (messagea + messageb).sendmsg() (messageb + messagea).recvmsg() # (contractbuyer + contractbuyerstop).request_offer() # (contractseller + contractsellerstop).make_offer() # contractagents.accept_offer() # contractagents.deliver() # contractagents.pay() # contractagents.control() some.all_tests_completed() s.finalize()