pymarket.statistics.profits module

pymarket.statistics.profits.calculate_profits(bids, transactions, reservation_prices=None, fees=None, **kwargs)[source]

Extras from the transactions and the bids the profit of each player and the market maker

Parameters:
  • bids (pd.DataFrame) – Collections of bids to be used
  • transactions (pd.DataFrame) – Collection of transactions to be taken into account
  • reservation_prices (dict, (Default value = None)) – Maping between users and their reservation prices. If None, it is assumed that each user bided truthfully and the information is extracted from the bid.
  • fees (np.ndarray, (Default value = None)) – List of fees that each user has to pay to trade in the market.
Returns:

profit – A dictionary with three values: * player_bid: A list with the profits of each user using their bids as reservation prices * player_reservation: Same as above but using their reservation prices, if none are provided, it is the same as player_bid * market: profit of the market maker

Return type:

dict

Examples

>>> tm = pm.TransactionManager()
>>> bm = pm.BidManager()
>>> bm.add_bid(1, 3, 0)
0
>>> bm.add_bid(1, 2, 1)
1
>>> bm.add_bid(1.5, 1, 2, False)
2
>>> tm.add_transaction(0, 1, 2, 2, False)
0
>>> tm.add_transaction(2, 1, 2, 0, False)
1
>>> rp = {2: 0}
>>> profits = calculate_profits(bm.get_df(), tm.get_df(),
...        reservation_prices=rp)
>>> profits['player_bid']
array([1., 0., 1.])
>>> profits['player_reservation']
array([1., 0., 2.])
>>> profits['market']
0.0
pymarket.statistics.profits.get_gain(row)[source]

Finds the gain of the row

Parameters:row (pandas row) – Row obtained by merging a transaction with a bid dataframe
Returns:The gain obtained by the row
Return type:gain