MultiCurrencyTrade

class abce.multicurrencytrade.MultiCurrencyTrade

Bases: abce.trade.Trade

This class replaces the abceagent.Trade class if you have multiple currencies or barter, just overload the all agents with the MultiCurrencyTrade class. In one simulation you can use either MultiCurrencyTrade or Trade so all agent groups in one simulation need to inherit from MultiCurrencyTrade or Trade.

Agents can trade with each other. The clearing of the trade is taken care of fully by ABCE. Selling a good works in the same way as in abceagent.Trade:

  1. An agent sends an offer. sell()

    The good offered is blocked and self.possession(...) does shows the decreased amount.

  2. Next subround: An agent receives the offer get_offers(), and can accept(), reject() or partially accept it. accept()

    The good is credited and the price is deducted from the agent’s possessions.

  3. Next subround:

    • in case of acceptance the money is automatically credited.
    • in case of partial acceptance the money is credited and part of the blocked good is unblocked.
    • in case of rejection the good is unblocked.

Analogously for buying: buy()

Example:

# Agent 1
def sales(self):
    self.remember_trade = self.sell('Household', 0, 'cookies', quantity=5, price=self.price, currency='dollars')

# Agent 2
def receive_sale(self):
    oo = self.get_offers('cookies')
    for offer in oo:
        if ((offer.currency == 'dollars' and offer.price < 0.3 * exchange_rate)
            or (offer.currency == 'euros' and dollars'offer.price < 0.3)):

            try:
                self.accept(offer)
            except NotEnoughGoods:
                self.accept(offer, self.possession('money') / offer.price)
        else:
            self.reject(offer)

If we did not implement a barter class, but one can use this class as a barter class, using the currency as the second good e.G:

self.remember_trade = self.sell('Household', 0, good='cookies', currency='wheels' quantity=5, price=self.price, )
accept()

The buy or sell offer is accepted and cleared. If no quantity is given the offer is fully accepted; If a quantity is given the offer is partial accepted

Args:

offer:
the offer the other party made
quantity:
quantity to accept. If not given all is accepted
epsilon (optional):
if you have floating point errors, a quantity or prices is a fraction of number to high or low. You can increase the floating point tolerance. See troubleshooting – floating point problems
Return:
Returns a dictionary with the good’s quantity and the amount paid.
buy()

commits to sell the quantity of good at price

The goods are not in haves or self.count(). When the offer is rejected it is automatically re-credited. When the offer is accepted the money amount is credited. (partial acceptance accordingly)

Args:
receiver_group:
group of the receiving agent
receiver_id:
number of the receiving agent
‘good’:
name of the good
quantity:
maximum units disposed to buy at this price
price:
price per unit
currency:
is the currency of this transaction (defaults to ‘money’)
epsilon (optional):
if you have floating point errors, a quantity or prices is a fraction of number to high or low. You can increase the floating point tolerance. See troubleshooting – floating point problems
sell()

commits to sell the quantity of good at price

The good is not available for the agent. When the offer is rejected it is automatically re-credited. When the offer is accepted the money amount is credited. (partial acceptance accordingly)

Args:
receiver_group:
group of the receiving agent
receiver_id:
number of the receiving agent
‘good’:
name of the good
quantity:
maximum units disposed to buy at this price
price:
price per unit
currency:
is the currency of this transaction (defaults to ‘money’)
epsilon (optional):
if you have floating point errors, a quantity or prices is a fraction of number to high or low. You can increase the floating point tolerance. See troubleshooting – floating point problems
Returns:
A reference to the offer. The offer and the offer status can be accessed with self.info(offer_reference).

Example:

def subround_1(self):
    self.offer = self.sell('household', 1, 'cookies', quantity=5, price=0.1)

def subround_2(self):
    offer = self.info(self.offer)
    if offer.status == 'accepted':
        print(offer.final_quantity , 'cookies have be bougth')
    else:
        offer.status == 'rejected':
        print('On diet')
abce.multicurrencytrade.Offer()

This is an offer container that is send to the other agent. You can access the offer container both at the receiver as well as at the sender, if you have saved the offer. (e.G. self.offer = self.sell(...))

it has the following properties:
sender_group:
this is the group name of the sender
sender_id:
this is the ID of the sender
receiver_group:
This is the group name of the receiver
receiver_id:
this is the ID of the sender
good:
the good offered or demanded
quantity:
the quantity offered or demanded
price:
the suggested tansaction price
buysell:
this can have the values ‘b’ for buy; ‘s’ for sell; ‘qb’ for a nonbinding buy quote; and ‘qs’ for a nonbinding sell quote
status:
‘new’:
has been created, but not answered
‘accepted’:
trade fully accepted
‘rejected’:
trade rejected
‘pending’:
offer has not yet answered, and is not older than one round.
‘perished’:
the perishable good was not accepted by the end of the round and therefore perished.
final_quantity:
If the offer has been answerd this returns the actual quantity bought or sold. (Equal to quantity if the offer was accepted fully)
id:
a unique identifier