Contracting

Warning

Contracting is experimental and the API is not stable yet

class abce.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]