abcEconomics.agents package

Submodules

abcEconomics.agents.deadagent module

abcEconomics.agents.firm module

The Firm class allows you to set up firm agents with complex or several production functions. While the simple Firm automatically handles one technology, Firm allows you to manage several technologies manually.

The create_* functions allow you to create a technology and assign it to a variable. abcEconomics.Firm.produce() and similar methods use this variable to produce with the according technology.

class abcEconomics.agents.firm.Firm[source]

Bases: object

With self.produce a firm produces a good using production functions. For example the following farm has a cobb-douglas production function:

class Farm(abcEconomics.Agent, abcEconomics.Firm):
def init(self):
self.production_function = create_cobb_douglas({‘land’: 0.7,
‘capital’: 0.1, ‘labor’: 0.2})
def firming(self):
self.produce(self.production_function, {{‘land’: self[‘land’],
‘capital’: self[‘capital’], ‘labor’: 2}})
Production functions can be auto generated with:
  • py:meth:~abcEconomics.Firm.create_cobb_douglas or
  • py:meth:~abcEconomics.Firm.create_ces or
  • py:meth:~abcEconomics.Firm.create_leontief

or specified by hand:

A production function looks like this:

def production_function(wheels, steel, stearing_wheels, machines):
    result = {'car': min(wheels / 4, steel / 10, stearing_wheels),
              'wheels': 0,
              'steel': 0,
              'steering_wheels': 0,
              'machine': machine * 0.9}
    return result

Or more readably like this:

def production_function(wheels, steel, stearing_wheels, machines):
car = min(wheels / 4, steel / 10, stearing_wheels) wheels = 0 steel = 0 stearing_wheels = 0 machine = machine * 0.9 return locals()

This production function, produces one car for every four wheels, 10 tonnes of steel and one stearing_wheel, it also requires one machine. Wheels, steel and stearing_wheels are completely used. The plant is not used and the machine depreciates by 10%.production.

A production function can also produce multiple goods. The last line return locals(), can not be omitted. It returns all variables you define in this function as a dictionary.

create_ces(output, gamma, multiplier=1, shares=None)[source]

creates a CES production function

A production function is a production process that produces the given input goods according to the CES formula to the output good:

\(Q = F \cdot \left[\sum_{i=1}^n a_{i}X_{i}^{\gamma}\ \right]^{\frac{1}{\gamma}}\)

Production_functions are than used as an argument in produce, predict_vector_produce and predict_output_produce.

Args:

‘output’:
Name of the output good
gamma:
elasticity of substitution \(= s =\frac{1}{1-\gamma}\)
multiplier:
CES multiplier \(F\)
shares:
\(a_{i}\) = Share parameter of input i, \(\sum_{i=1}^n a_{i} = 1\) when share_parameters is not specified all inputs are weighted equally and the number of inputs is flexible.

Returns:

A production_function that can be used in produce etc.

Example:

self.stuff_production_function = create_ces('stuff', gamma=0.5, multiplier=1,
                                            shares={'labor': 0.25, 'stone':0.25, 'wood':0.5})
self.produce(self.stuff_production_function, {'stone' : 20, 'labor' : 1, 'wood': 12})
create_cobb_douglas(output, multiplier, exponents)[source]

creates a Cobb-Douglas production function

A production function is a production process that produces the given input goods according to the Cobb-Douglas formula to the output good. Production_functions are than used as an argument in produce, predict_vector_produce and predict_output_produce.

Args:

‘output’:
Name of the output good
multiplier:
Cobb-Douglas multiplier
{‘input1’: exponent1, ‘input2’: exponent2 …}:
dictionary containing good names ‘input’ and corresponding exponents

Returns:

A production_function that can be used in produce etc.

Example:

def init(self):
self.plastic_production_function = create_cobb_douglas(‘plastic’, {‘oil’ : 10, ‘labor’ : 1}, 0.000001)

def producing(self):
self.produce(self.plastic_production_function, {‘oil’ : 20, ‘labor’ : 1})
create_leontief(output, utilization_quantities)[source]

creates a Leontief production function

A production function is a production process that produces the given input goods according to the Leontief formula to the output good. Production_functions are than used as an argument in produce, predict_vector_produce and predict_output_produce.

Args:

‘output’:
Name of the output good
multiplier:
dictionary of multipliers it min(good1 * a, good2 * b, good3 * c…)
{‘input1’: exponent1, ‘input2’: exponent2 …}:
dictionary containing good names ‘input’ and corresponding exponents

Returns:

A production_function that can be used in produce etc.

Example: self.car_production_function = create_leontief(‘car’, {‘wheel’ : 4, ‘chassi’ : 1}) self.produce(self.car_production_function, {‘wheel’ : 20, ‘chassi’ : 5})

produce(production_function, input_goods, results=False)[source]

Produces output goods given the specified amount of inputs.

Transforms the Agent’s goods specified in input goods according to a given production_function to output goods. Automatically changes the agent’s belonging. Raises an exception, when the agent does not have sufficient resources.

Args:
production_function:
A production_function produced with py:meth:~abcEconomics.Firm.create_production_function, py:meth:~abcEconomics.Firm.create_cobb_douglas or py:meth:~abcEconomics.Firm.create_leontief
input goods dictionary or list:
dictionary containing the amount of input good used for the production or a list of all goods that get completely used.
results:
If True returns a dictionary with the used and produced goods.
Raises:
NotEnoughGoods:
This is raised when the goods are insufficient.

Example:

car = {'tire': 4, 'metal': 2000, 'plastic':  40}
bike = {'tire': 2, 'metal': 400, 'plastic':  20}
try:
    self.produce(car_production_function, car)
except NotEnoughGoods:
    A.produce(bike_production_function, bike)

self.produce(car_production_function, ['tire', 'metal', 'plastic'])  # produces using all goods

abcEconomics.agents.firmmultitechnologies module

abcEconomics.agents.household module

The Household class extends the agent by giving him utility functions and the ability to consume goods.

class abcEconomics.agents.household.Household[source]

Bases: object

consume(utility_function, input_goods)[source]

consumes input_goods returns utility according to the agent’s utility function.

A utility_function, has to be set before see py:meth:~abcEconomics.Household.create_cobb_douglas_utility_function or manually; see example.

Args:

utility_function:
A function that takes goods as parameters and returns a utility or returns (utility, left_over_dict). Where left_over_dict is a dictionary of all goods that are not completely consumed
input goods dictionary or list:
dictionary containing the amount of input good used consumed or a list of all goods that get completely consumed.
Raises:
NotEnoughGoods: This is raised when the goods are insufficient.
Returns:
The utility as a number. To log it see example.

Example:

def utility_function(car, cookies, bike):
    utility = car ** 0.5 * cookies ** 0.2 * bike ** 0.3
    cookies = 0  # cookies are consumed, while the other goods are not consumed
    return utility, locals()


def utility_function(cake, cookies, bonbons):  # all goods get completely consumed
    utility = cake ** 0.5 * cookies ** 0.2 * bonbons ** 0.3
    return utility

self.consumption_set = {'car': 1, 'cookies': 2000, 'bike':  2}
self.consume_everything = ['car', 'cookies', 'bike']
try:
    utility = self.consume(utility_function, self.consumption_set)
except NotEnoughGoods:
    utility = self.consume(utility_function, self.consume_everything)
self.log('utility': {'u': utility})
create_cobb_douglas_utility_function(exponents)[source]

creates a Cobb-Douglas utility function

Utility_functions are than used as an argument in consume_with_utility, predict_utility and predict_utility_and_consumption.

Args:
{‘input1’: exponent1, ‘input2’: exponent2 …}: dictionary containing good names ‘input’ and correstponding exponents
Returns:
A utility_function that can be used in consume_with_utility etc.

Example: self._utility_function = self.create_cobb_douglas({‘bread’ : 10, ‘milk’ : 1}) self.produce(self.plastic_utility_function, {‘bread’ : 20, ‘milk’ : 1})

Module contents