abce.contracts package

Submodules

abce.contracts.contracting module

class abce.contracts.contracting.Contract(sender_group, sender_id, deliver_good_group, deliver_good_id, pay_group, pay_id, good, quantity, price, end_date, id, round)[source]

Bases: object

deliver_good_group
deliver_good_id
delivered
end_date
good
id
paid
pay_group
pay_id
price
quantity
round
sender_group
sender_id
class abce.contracts.contracting.Contracting[source]

Bases: object

This is a class, that allows you to create contracts. For example a work contract. One agent commits to deliver a good or service for a set amount of time.

For example you have a firm and a worker class. ‘Labor’ is set as a service meaning that it lasts not longer than one round and the worker how has an adult gets one unit of labor every round see: abce.declare_service(). The firm offers a work contract, the worker responds. Every round the worker delivers the labor and the firm pays.:

class Firm(abce.Agent, abce.Contract)
    def request_offer(self):
        if self.round % 10 == 0:
            self.given_contract = self.request_contract('contractbuyer', 0,
                                                        good='labor',
                                                        quantity=5,
                                                        price=10,
                                                        duration=10 - 1)

    def deliver_or_pay(self):
        self.pay_contract('labor')

class Worker(abce.Agent, abce.Contract):
    def init(self):
        self.create('adult', 1)

    def accept_offer(self):
        contracts = self.get_contract_requests('labor')
        for contract in contracts:
            if contract.price < 5:
                self.accepted_contract = self.accept_contract(contract)

    def deliver_or_pay(self):
        self.deliver('labor')

Firms and workers can check, whether they have been paid/provided with labor using the is_paid() and is_delivered() methods.

The worker can also initiate the transaction by requesting a contract with make_contract_offer().

A contract has the following fields:

sender_group:

sender_id:

deliver_group:

deliver_id:

pay_group:

pay_id:

good:

quantity:

price:

end_date:

makerequest:
‘m’ for make_contract_offer and ‘r’ for request_contract
id:
unique number of contract
accept_contract(contract, quantity=None)[source]

Accepts the contract. The contract is completely accepted, when the quantity is not given. Or partially when quantity is set.

Args:

contract:
the contract in question, received with get_contract_requests or get_contract_offers
quantity (optional):
the quantity that is accepted. Defaults to all.
calculate_assetvalue(prices={}, parameters={}, value_functions={})[source]
calculate_liablityvalue(prices={}, parameters={}, value_functions={})[source]
calculate_netvalue(prices={}, parameters={}, value_functions={})[source]
calculate_valued_assets(prices={}, parameters={}, value_functions={})[source]
calculate_valued_liablities(prices={}, parameters={}, value_functions={})[source]
contracts_to_deliver(good)[source]
contracts_to_deliver_all()[source]
contracts_to_receive(good)[source]
contracts_to_receive_all()[source]
deliver_contract(contract)[source]

delivers on a contract

end_contract(contract)[source]
get_contract_offers(good, descending=False)[source]

Returns all contract offers and removes them. The contract are ordered by price (ascending), when tied they are randomized.

Args:
good:
good that underlies the contract
descending(bool,default=False):
False for descending True for ascending by price
Returns:
list of contract offers ordered by price
offer_good_contract(receiver_group, receiver_id, good, quantity, price, duration)[source]

This method offers a contract to provide a good or service to the receiver. For a given time at a given price.

Args:

receiver_group:
group to receive the good
receiver_id:
group to receive the good
good:
the good or service that should be provided
quantity:
the quantity that should be provided
price:
the price of the good or service
duration:
the length of the contract, if duration is None or not set, the contract has no end date.

Example:

self.given_contract = self.make_contract_offer('firm', 1, 'labor', quantity=8, price=10, duration=10 - 1)
pay_contract(contract)[source]

delivers on a contract

request_good_contract(receiver_group, receiver_id, good, quantity, price, duration)[source]

This method requests a contract to provide a good or service to the sender. For a given time at a given price. For example a job advertisement.

Args:

receiver_group:
group of the receiver
receiver_id:
id of the receiver
good:
the good or service that should be provided
quantity:
the quantity that should be provided
price:
the price of the good or service
duration:
the length of the contract, if duration is None or not set, the contract has no end date.
was_delivered_last_round(contract)[source]
was_delivered_this_round(contract)[source]
was_paid_last_round(contract)[source]
was_paid_this_round(contract)[source]
abce.contracts.contracting.bound_zero(x)[source]

asserts that variable is above zero, where foating point imprecission is accounted for, and than makes sure it is above 0, without floating point imprecission

abce.contracts.contracts module

class abce.contracts.contracts.Contracts(par=set())[source]

Bases: set

add(entry)[source]

Add an element to a set.

This has no effect if the element is already present.

calculate_assetvalue(parameters, value_functions)[source]
calculate_liablityvalue(parameters, value_functions)[source]
calculate_netvalue(parameters, value_functions)[source]
calculate_valued_assets(parameters, value_functions)[source]
calculate_valued_liablities(parameters, value_functions)[source]
possession(typ)[source]
possessions()[source]
remove(entry)[source]

Remove an element from a set; it must be a member.

If the element is not a member, raise a KeyError.

abce.contracts.flexiblecontracting module

class abce.contracts.flexiblecontracting.Credit(sender_group, sender_id, deliver_good_group, deliver_good_id, pay_group, pay_id, amount, interest)[source]

Bases: object

amount
deliver_good_group
deliver_good_id
interest
pay_group
pay_id
sender_group
sender_id
class abce.contracts.flexiblecontracting.FlexibleContracting[source]

Bases: object

This is a class, that allows you to create contracts. For example a work contract. One agent commits to deliver a good or service for a set amount of time.

For example you have a firm and a worker class. ‘Labor’ is set as a service meaning that it lasts not longer than one round and the worker how has an adult gets one unit of labor every round see: abce.declare_service(). The firm offers a work contract, the worker responds. Every round the worker delivers the labor and the firm pays.:

class Firm(abce.Agent, abce.Contract)
    def request_offer(self):
        if self.round % 10 == 0:
            self.given_contract = self.request_contract('contractbuyer', 0,
                                                        good='labor',
                                                        quantity=5,
                                                        price=10,
                                                        duration=10 - 1)

    def deliver_or_pay(self):
        self.pay_contract('labor')

class Worker(abce.Agent, abce.Contract):
    def init(self):
        self.create('adult', 1)

    def accept_offer(self):
        contracts = self.get_contract_requests('labor')
        for contract in contracts:
            if contract.price < 5:
                self.accepted_contract = self.accept_contract(contract)

    def deliver_or_pay(self):
        self.deliver('labor')

Firms and workers can check, whether they have been paid/provided with labor using the is_paid() and is_delivered() methods.

The worker can also initiate the transaction by requesting a contract with make_contract_offer().

A contract has the following fields:

sender_group:

sender_id:

deliver_group:

deliver_id:

pay_group:

pay_id:

good:

quantity:

price:

end_date:

makerequest:
‘m’ for make_contract_offer and ‘r’ for request_contract
id:
unique number of contract
accept_contract(contract, quantity=None)[source]

Accepts the contract. The contract is completely aceppted, when the quantity is not given. Or partially when quantity is set.

Args:

contract:
the contract in question, received with get_contract_requests or get_contract_offers
quantity (optional):
the quantity that is accepted. Defaults to all.
calculate_assetvalue(prices={}, parameters={}, value_functions={})[source]
calculate_liablityvalue(prices={}, parameters={}, value_functions={})[source]
calculate_netvalue(prices={}, parameters={}, value_functions={})[source]
calculate_valued_assets(prices={}, parameters={}, value_functions={})[source]
calculate_valued_liablities(prices={}, parameters={}, value_functions={})[source]
contracts_to_deliver(good)[source]
contracts_to_deliver_all()[source]
contracts_to_receive(good)[source]
contracts_to_receive_all()[source]
deliver_contract(contract)[source]

delivers on a contract

end_contract(contract)[source]
get_contract_offers(good, descending=False)[source]

Returns all contract offers and removes them. The contract are ordered by price (ascending), when tied they are randomized.

Args:
good:
good that underlies the contract
descending(bool,default=False):
False for descending True for ascending by price
Returns:
list of contract offers ordered by price
pay_contract(contract)[source]

delivers on a contract

request_credit(receiver_group, receiver_id, amount, interest, end_date)[source]

This method offers a contract to provide a good or service to the receiver. For a given time at a given price.

Args:

receiver_group:
group to receive the good
receiver_id:
group to receive the good
deliver:
an array or function that returns a number or dict for each round, the tuple specifies which goods have to be delivered at which price.
receive:
an array or function that returns a number or a dict for each round, the tuple specifies which goods have to be delivered at which price.

Example:

self.given_contract = self.make_contract_offer('firm', 1, 'labor', quantity=8, price=10, duration=10 - 1)
request_good_contract(receiver_group, receiver_id, good, quantity, price, duration)[source]

This method requests a contract to provide a good or service to the sender. For a given time at a given price. For example a job advertisement.

Args:

receiver_group:
group of the receiver
receiver_id:
id of the receiver
good:
the good or service that should be provided
quantity:
the quantity that should be provided
price:
the price of the good or service
duration:
the length of the contract, if duration is None or not set, the contract has no end date.
was_delivered_last_round(contract)[source]
was_delivered_this_round(contract)[source]
was_paid_last_round(contract)[source]
was_paid_this_round(contract)[source]
abce.contracts.flexiblecontracting.bound_zero(x)[source]

asserts that variable is above zero, where foating point imprecission is accounted for, and than makes sure it is above 0, without floating point imprecission

Module contents