用python模拟市场的简单库
pymarket的Python项目详细描述
Pymarket
pymarket是一个python库,旨在简化模拟和 不同市场机制的比较
市场可以用来解决各种各样的问题。他们 用于在线销售广告、波段、能量等。 pymarket提供了一个简单的环境来尝试、模拟和比较不同的 市场机制,这是建立一个新的 市场。
作为一个例子,地方能源市场(lems)已经被提议同步能源消费。 可再生能源发电过剩。针对这样一个市场提出了几种机制: 从双边拍卖到p2p交易。
这个库旨在为这样的过程提供一个简单的接口,使结果可重复。
开始
importpymarketaspmimportnumpyasnpr=np.random.RandomState(1234)mar=pm.Market()bids=pm.datasets.uniform_bidders.generate(20,20,1,1,r)forbinbids:mar.accept_bid(*b)mar.plot()
获取出价
bids=mar.bm.get_df()bids.head()
quantity price user buying time divisible
0 0.2374 1.0234 0 True 0 True
1 0.1784 1.1770 1 True 0 True
2 0.6301 1.5789 2 True 0 True
3 0.1600 1.8008 3 True 0 True
4 0.7920 1.5478 4 True 0 True
运行市场算法
transactions,extra=mar.run('p2p',r=r)transactions=transactions.get_df()transactions.head()
bid quantity price source active
0 16 0.0000 0.0000 34 True
1 34 0.0000 0.0000 16 True
2 0 0.0000 0.0000 23 True
3 23 0.0000 0.0000 0 True
4 12 0.0786 1.3828 26 False
文档和示例
Docs can be found here (click me!)
安装
pipinstallpymarket