pymarket.mechanisms.mechanism module¶
-
class
pymarket.mechanisms.mechanism.
Mechanism
(algo, bids, *args, merge=False, **kwargs)[source]¶ Bases:
object
Implements a standard interface for mechanisms
-
algo
¶ Algorithm to execute to solve the market.
Type: Callable
-
bids
¶ Collection of bids to use, with processing.
Type: pd.DataFrame
-
old_bids
¶ Collection of bids previous to proecssing.
Type: pd.DataFrame
-
merge
¶ Wheather to merge different players with the same price into one player. Useful for algorithms that require players to have different prices.
Type: bool
Examples
Run p2p mechanism channging parameters with default parameters.
>>> bm = pm.BidManager() >>> bm.add_bid(1, 3, 0) 0 >>> bm.add_bid(1, 0.5, 1) 1 >>> bm.add_bid(1, 1, 2, False) 2 >>> bm.add_bid(1, 2, 3, False) 3 >>> r = np.random.RandomState(420) >>> p2p = pm.mechanisms.p2p_random >>> mec = Mechanism(p2p, bm.get_df(), r=r) >>> trans, extra = mec.run() >>> extra {'trading_list': [[(0, 3), (1, 2)]]} >>> trans.get_df() bid quantity price source active 0 0 1 2.5 3 False 1 3 1 2.5 0 False 2 1 0 0.0 2 True 3 2 0 0.0 1 True
>>> r = np.random.RandomState(420) >>> mec = Mechanism(p2p, bm.get_df(), r=r, p_coef=1) >>> trans, extra = mec.run() >>> extra {'trading_list': [[(0, 3), (1, 2)]]} >>> trans.get_df() bid quantity price source active 0 0 1 3.0 3 False 1 3 1 3.0 0 False 2 1 0 0.0 2 True 3 2 0 0.0 1 True
-