Purchases a good from another agent and pays for it using the monetary good specified in a Goods.add()
command. Similar to agent.trade()
except that the second good does not have to be specified. Note that this function will raise a RuntimeError
if no monetary good has been specified.
Parameters
partner — Agent, required
The agent object of the trading partner. The agent object can be retrieved by ID with
model.agent()
.good — str, required
The good to be purchased. This good must have been previously registered with
Goods.add()
.q — num, required
The quantity of the good to purchase. If the partner does not possess at least
q
ofgood
, the agent purchases the partner's entire stock, and the difference is added to that period's shortage counter. Note that a negativeq
can be passed in order to sell a quantity of the good to the partner.p — num, required
The price at which to purchase the good.
Return Value — num
The amount actually traded. This will equal q
unless the trading agent has an insufficient stock of the good, in which case the function returns the agent's stocks and records the difference as a shortage.
Notes and Examples