Esempio n. 1
0
def main(parameters):
    simulation = Simulation(rounds=parameters['rounds'], processes=1)
    simulation.declare_round_endowment(resource='adult', units=1, product='labor')
    simulation.declare_perishable(good='labor')

    simulation.aggregate('household', possessions=['money', 'GOOD'],
                         variables=['current_utiliy'])
    simulation.panel('firm', possessions=['money', 'GOOD'],
                    variables=['price', 'inventory'])

    firms = simulation.build_agents(Firm, 'firm', number=parameters['num_firms'])
    households = simulation.build_agents(Household, 'household', number=1, parameters=parameters)

    for r in simulation.next_round():
        households.do('sell_labor')
        firms.do('buy_labor')
        firms.do('production')
        firms.do('panel')
        firms.do('quotes')
        households.do('buy_goods')
        firms.do('sell_goods')
        households.do('aggregate')
        households.do('consumption')
        firms.do('adjust_price')

    simulation.graphs()
Esempio n. 2
0
def main(simulation_parameters):
        simulation = Simulation(rounds=simulation_parameters['rounds'])

        simulation.declare_round_endowment(resource={'labor_endowment': 1},
                                           product='labor')

        simulation.declare_perishable(good='labor')

        simulation.aggregate('household', possessions=[],  # put a list of household possessions to track here
                                      variables=['count']) # put a list of household possessions to track here

        simulation.aggregate('firm', possessions=[],  # put a list of household possessions to track here
                                      variables=['count']) # put a list of household possessions to track here

        firms = simulation.build_agents(Firm, 'firm',
                       number=simulation_parameters['firms'],
                       parameters=simulation_parameters)

        households = simulation.build_agents(Household, 'household',
                       number=simulation_parameters['households'],
                       parameters=simulation_parameters)

        messengers = simulation.build_agents(Messenger, 'messenger', 1)

        for r in simulation.next_round():
            messengers.do('messaging')
            (firms+households).do('receive_message')
            firms.do('add_household')
            firms.do('add_firm')
            firms.do('print_id')
            households.do('print_id')
            # this instructs ABCE to save panel data as declared below
            (firms+households).do('aggregate')
        simulation.graphs()
Esempio n. 3
0
def main(simulation_parameters):
        simulation = Simulation(rounds=simulation_parameters['rounds'])
        simulation.declare_calendar(2000, 1, 1)
        simulation.panel('agent', possessions=['money'])
        simulation.aggregate('agent', possessions=['labor'])
        agents = simulation.build_agents(Agent, 'agent', number=1)

        for r in simulation.next_round():
            date = simulation._round
            if date.weekday() == 2:
                agents.do('wednessday')
            if date.day == 1:
                agents.do('first')
            if date.month == 12 and date.day == 31:
                agents.do('newyearseve')
            if date.day <= 7 and date.weekday() == 4:
                agents.do('firstfriday')
            if date.month == 15:
                agents.do('fiveteens')
            if date.toordinal() % 3 == 0:
                agents.do('everythreedays')
            agents.do('panel')
            agents.do('aggregate')

        simulation.graphs()
Esempio n. 4
0
def main(simulation_parameters):
        simulation = Simulation(rounds=simulation_parameters['rounds'])
        action_list = [('firm', 'one'),
                       ('household', 'two'),
                       ('all', 'three')
                       ('household', 'panel')]  # this instructs ABCE to save panel data as declared below
        simulation.add_action_list(action_list)

        simulation.declare_round_endowment(resource='labor_endowment',
                                           units=1,
                                           product='labor'
        )
        simulation.declare_perishable(good='labor')

        simulation.panel('household', possessions=['good1', 'good2'],  # put a list of household possessions to track here
                                      variables=['utility']) # put a list of household possessions to track here

        simulation.build_agents(Firm, 'firm',
                       number=simulation_parameters['firms'],
                       parameters=simulation_parameters)
        simulation.build_agents(Household, 'household',
                       number=simulation_parameters['households'],
                       parameters=simulation_parameters)


        simulation.run()
        simulation.graphs()
Esempio n. 5
0
def main(simulation_parameters):
    simulation = Simulation(rounds=simulation_parameters['rounds'])
    action_list = [
        ('firm', 'one'), ('household', 'two'), ('all', 'three')('household',
                                                                'panel')
    ]  # this instructs ABCE to save panel data as declared below
    simulation.add_action_list(action_list)

    simulation.declare_round_endowment(resource='labor_endowment',
                                       units=1,
                                       product='labor')
    simulation.declare_perishable(good='labor')

    simulation.panel(
        'household',
        possessions=['good1', 'good2'
                     ],  # put a list of household possessions to track here
        variables=['utility'
                   ])  # put a list of household possessions to track here

    simulation.build_agents(Firm,
                            'firm',
                            number=simulation_parameters['firms'],
                            parameters=simulation_parameters)
    simulation.build_agents(Household,
                            'household',
                            number=simulation_parameters['households'],
                            parameters=simulation_parameters)

    simulation.run()
    simulation.graphs()
Esempio n. 6
0
def main(parameters):
    simulation = Simulation(rounds=parameters['rounds'], cores=1)
    action_list = [
        ('household', 'sell_labor'),
        ('firm', 'buy_labor'),
        ('firm', 'production'),
        ('firm', 'panel'),
        ('firm', 'quotes'),
        ('household', 'buy_goods'),
        ('firm', 'sell_goods'),
        ('household', 'aggregate'),
        ('household', 'consumption'),
        ('firm', 'adjust_price')]
    simulation.add_action_list(action_list)

    simulation.declare_round_endowment(resource='adult', units=1, product='labor')
    simulation.declare_perishable(good='labor')

    simulation.aggregate('household', possessions=['money', 'GOOD'],
                         variables=['current_utiliy'])
    simulation.panel('firm', possessions=['money', 'GOOD'],
                    variables=['price', 'inventory'])

    simulation.build_agents(Firm, 'firm', number=parameters['num_firms'])
    simulation.build_agents(Household, 'household', number=1, parameters=parameters)

    simulation.run()
    simulation.graphs()
Esempio n. 7
0
def main(simulation_parameters):
        simulation = Simulation(rounds=simulation_parameters['rounds'])
        action_list = [('killer', 'kill'),
                       ('agent', 'am_I_dead'),
                       ('killer', 'send_message'),
                       ('agent', 'aggregate'),
                       ('agent', 'panel')]  # this instructs ABCE to save panel data as declared below
        simulation.add_action_list(action_list)

        simulation.declare_round_endowment(resource='labor_endowment',
                                           units=1,
                                           product='labor'
        )
        simulation.declare_perishable(good='labor')

        simulation.aggregate('agent', possessions=[], variables=['count'])
        simulation.panel('agent', possessions=[], variables=['idn'])

        simulation.build_agents(Agent, 'agent',
                       number=simulation_parameters['agents'],
                       parameters=simulation_parameters)
        simulation.build_agents(Killer, 'killer',
                       number=1,
                       parameters=simulation_parameters)


        simulation.run()
        simulation.graphs()
Esempio n. 8
0
def main(parameters):
    simulation = Simulation(rounds=parameters['rounds'], processes=1)
    simulation.declare_round_endowment(resource='adult',
                                       units=1,
                                       product='labor')
    simulation.declare_perishable(good='labor')

    simulation.aggregate('household',
                         possessions=['money', 'GOOD'],
                         variables=['current_utiliy'])
    simulation.panel('firm',
                     possessions=['money', 'GOOD'],
                     variables=['price', 'inventory'])

    firms = simulation.build_agents(Firm,
                                    'firm',
                                    number=parameters['num_firms'])
    households = simulation.build_agents(Household,
                                         'household',
                                         number=1,
                                         parameters=parameters)

    for r in simulation.next_round():
        households.do('sell_labor')
        firms.do('buy_labor')
        firms.do('production')
        firms.do('panel')
        firms.do('quotes')
        households.do('buy_goods')
        firms.do('sell_goods')
        households.do('aggregate')
        households.do('consumption')
        firms.do('adjust_price')

    simulation.graphs()
Esempio n. 9
0
def main(simulation_parameters):
        simulation = Simulation(rounds=simulation_parameters['rounds'])
        simulation.declare_round_endowment(resource='labor_endowment',
                                           units=1,
                                           product='labor')
        simulation.declare_perishable(good='labor')

        simulation.aggregate('agent', possessions=[], variables=['count'])
        simulation.panel('agent', possessions=[], variables=['idn'])

        agents = simulation.build_agents(Agent, 'agent',
                       number=simulation_parameters['agents'],
                       parameters=simulation_parameters)
        killers = simulation.build_agents(Killer, 'killer',
                       number=1,
                       parameters=simulation_parameters)
        for r in simulation.next_round():
            killers.do('kill')
            agents.do('am_I_dead')
            killers.do('send_message')
            agents.do('aggregate')
            agents.do('panel')


        simulation.graphs()
Esempio n. 10
0
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()
Esempio n. 11
0
def main(simulation_parameters):
    simulation = Simulation(rounds=simulation_parameters['rounds'])

    simulation.declare_round_endowment(resource='labor_endowment',
                                       units=1,
                                       product='labor')

    simulation.declare_perishable(good='labor')

    simulation.aggregate(
        'household',
        possessions=[],  # put a list of household possessions to track here
        variables=['count'
                   ])  # put a list of household possessions to track here

    simulation.aggregate(
        'firm',
        possessions=[],  # put a list of household possessions to track here
        variables=['count'
                   ])  # put a list of household possessions to track here

    firms = simulation.build_agents(Firm,
                                    'firm',
                                    number=simulation_parameters['firms'],
                                    parameters=simulation_parameters)

    households = simulation.build_agents(
        Household,
        'household',
        number=simulation_parameters['households'],
        parameters=simulation_parameters)

    messengers = simulation.build_agents(Messenger, 'messenger', 1)

    for r in simulation.next_round():
        messengers.do('messaging')
        (firms + households).do('receive_message')
        firms.do('add_household')
        firms.do('add_firm')
        firms.do('print_id')
        households.do('print_id')
        # this instructs ABCE to save panel data as declared below
        (firms + households).do('aggregate')
    simulation.graphs()
Esempio n. 12
0
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()
Esempio n. 13
0
def main(simulation_parameters):
    simulation = Simulation(rounds=simulation_parameters['scheduledEndTime'],
                            processes=1)

    insurancefirms = simulation.build_agents(
        InsuranceFirm,
        'insurancefirm',
        number=simulation_parameters['numberOfInsurers'],
        parameters=simulation_parameters)
    insurancecustomers = simulation.build_agents(
        InsuranceCustomer,
        'insurancecustomer',
        number=simulation_parameters['numberOfRiskholders'],
        parameters=simulation_parameters)

    allagents = insurancefirms + insurancecustomers
    #pdb.set_trace()

    events = defaultdict(list)

    for round in simulation.next_round():
        new_events = insurancecustomers.do('randomAddRisk')
        for risk in events[round]:
            new_events += [risk.explode(round)]
        for event_time, risk in new_events:
            if event_time is not None:
                event_time = math.ceil(event_time)
                events[event_time].append(risk)
                assert isinstance(event_time, int)
                assert risk is not None
                assert event_time >= round
        (insurancefirms + insurancecustomers).do('mature_contracts')
        insurancefirms.do('quote')
        insurancecustomers.do('subscribe_coverage')
        insurancefirms.do('add_contract')
        allagents.do('filobl')
        insurancecustomers.do('check_risk')

    simulation.graphs()
Esempio n. 14
0
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()
Esempio n. 15
0
def main(simulation_parameters):
    simulation = Simulation(rounds=simulation_parameters['rounds'],
                            name='ABCEsimulation_name')

    simulation.declare_round_endowment(resource='labor_endowment',
                                       units=1,
                                       product='labor')
    simulation.declare_perishable(good='labor')

    simulation.panel(
        'household',
        possessions=['good1', 'good2'
                     ],  # put a list of household possessions to track here
        variables=['utility'
                   ])  # put a list of household possessions to track here

    firms = simulation.build_agents(Firm,
                                    'firm',
                                    number=simulation_parameters['firms'],
                                    parameters=simulation_parameters)
    households = simulation.build_agents(
        Household,
        'household',
        number=simulation_parameters['households'],
        parameters=simulation_parameters)

    allagents = firms + households
    try:  # makes sure that graphs are displayed even when the simulation fails
        for round_number in simulation.next_round():
            firms.do('one')
            households.do('two')
            allagents.do('three')
            households.do('panel')
    except Exception as e:
        print(e)
    finally:
        simulation.graphs()
Esempio n. 16
0
def main(simulation_parameters):
        simulation = Simulation(rounds=simulation_parameters['rounds'])
        action_list = [('messenger', 'messaging'),
                       (('firm', 'household'), 'receive_message'),
                       ('firm', 'add_household'),
                       ('firm', 'add_firm'),
                       ('firm', 'print_id'),
                       ('household', 'print_id'),
                       (('firm', 'household'), 'aggregate')]  # this instructs ABCE to save panel data as declared below
        simulation.add_action_list(action_list)

        simulation.declare_round_endowment(resource='labor_endowment',
                                           units=1,
                                           product='labor')

        simulation.declare_perishable(good='labor')

        simulation.aggregate('household', possessions=[],  # put a list of household possessions to track here
                                      variables=['count']) # put a list of household possessions to track here

        simulation.aggregate('firm', possessions=[],  # put a list of household possessions to track here
                                      variables=['count']) # put a list of household possessions to track here

        simulation.build_agents(Firm, 'firm',
                       number=simulation_parameters['firms'],
                       parameters=simulation_parameters, expandable=True)

        simulation.build_agents(Household, 'household',
                       number=simulation_parameters['households'],
                       parameters=simulation_parameters, expandable=True)

        simulation.build_agents(Messenger, 'messenger', 1)


        simulation.run()
        simulation.graphs()