pymarket.market module¶
-
class
pymarket.market.
Market
[source]¶ Bases:
object
General interface for calling the different market mechanisms
Parameters: - bm (BidManager) – All bids are stored in the bid manager
- transactions (TransactionManager) – The set of all tranasactions in the Market. This argument get updated after the market ran.
- extra (dict) – Extra information provided by the mechanisms. Gets updated after an execution of the run.
Examples
If everyone is buying, the transaction dataframe is returned empty as well as the extra dictionary.
>>> mar = pm.Market() >>> mar.accept_bid(1, 2, 0, True) 0 >>> mar.accept_bid(2, 3, 1, True) 1 >>> trans, extra = mar.run('huang') >>> extra OrderedDict() >>> trans.get_df() Empty DataFrame Columns: [bid, quantity, price, source, active] Index: []
If everyone is buying, the transaction dataframe is returned empty as well as the extra dictionary.
>>> mar = pm.Market() >>> mar.accept_bid(1, 2, 0, False) 0 >>> mar.accept_bid(2, 3, 1, False) 1 >>> trans, extra = mar.run('huang') >>> extra OrderedDict() >>> trans.get_df() Empty DataFrame Columns: [bid, quantity, price, source, active] Index: []
A very simple auction where nobody trades
>>> mar = pm.Market() >>> mar.accept_bid(1, 3, 0, True) 0 >>> mar.accept_bid(1, 2, 1, False) 1 >>> trans, extra = mar.run('huang') >>> extra OrderedDict([('price_sell', 2.0), ('price_buy', 3.0), ('quantity_traded', 0)]) >>> trans.get_df() Empty DataFrame Columns: [bid, quantity, price, source, active] Index: []
-
accept_bid
(*args)[source]¶ Adds a bid to the bid manager
Parameters: *args – List of parameters requried to create a bid. See BidManager documentation. Returns: bid_id – The id of the new created bid in the BidManger Return type: int
-
plot_method
(method, ax=None)[source]¶ Plots a figure specific for a given method, reflecting the main characteristics of its solution. It requires that the algorithm has run before.
Parameters: - method (str) – One of p2p, muda, huang
- ax – (Default value = None)
-
run
(algo, *args, **kwargs)[source]¶ Runs a given mechanism with the current bids
Parameters: - algo (str) –
- One of:
- ’p2p’
- ’huang’
- ’muda’
- *args – Extra arguments to pass to the algorithm.
- **kwargs – Extra keyworded arguments to pass to the algorithm
Returns: - transactions (TransactionManager) – The transaction manager holding all the transactions returned by the mechanism.
- extra (dict) – Dictionary with extra information returned by the executed method.
- algo (str) –
-
statistics
(reservation_prices=None, exclude=[])[source]¶ Computes the standard statistics of the market
Parameters: - (dict, optional) (reservation_prices) – the reservation prices of the users. If there is none, the bid will be assumed truthfull
- reservation_prices – (Default value = None)
- exclude – List of mechanisms to ignore will comuting statistics
Returns: stats –
- Dictionary with the differnt statistics. Currently:
- percentage_welfare
- percentage_traded
- profits
Return type: