Giter Site home page Giter Site logo

kiedanski / pymarket Goto Github PK

View Code? Open in Web Editor NEW
26.0 1.0 4.0 665 KB

PyMarket is a python library aimed to ease the design, simulation and comparison of different market mechanisms.

Home Page: https://pymarket.readthedocs.io/en/latest/

License: MIT License

Makefile 1.66% Python 75.76% TeX 8.81% Ruby 10.16% Shell 3.61%
market-mechanisms market energy simulation auctions game-theory

pymarket's Introduction

PyMarket

Build Status

Documentation Status

PyPI version

DOI

PyMarket is a python library designed to ease the simulation and comparison of different market mechanisms.

Marketplaces can be proposed to solve a diverse array of problems. They are used to sell ads online, bandwith spectrum, energy, etc. PyMarket provides a simple environment to try, simulate and compare different market mechanisms, a task that is inherent to the process of establishing a new market.

As an example, Local Energy Markets (LEMs) have been proposed to syncronize energy consumption with surplus of renewable generation. Several mechanisms have been proposed for such a market: from double sided auctions to p2p trading.

This library aims to provide a simple interface for such process, making results reproducible.

Getting Started

import pymarket as pm
import numpy as np

r = np.random.RandomState(1234)

mar = pm.Market()
bids = pm.datasets.uniform_bidders.generate(20, 20, 1, 1, r)
for b in bids:
    mar.accept_bid(*b)
    
mar.plot()

png

Access the bids

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

Run a market algorithm

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

Documentation and Examples

Docs can be found here (click me!)

Installation

pip install pymarket

pymarket's People

Contributors

danielskatz avatar dependabot[bot] avatar kiedanski avatar taqtiqa-admin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pymarket's Issues

Platforms (OS) tested and know to run on.

Description

New users are in the dark about which platforms PyMarket is tested and known to run on: All?
There are no platform specific gotchas in the package dependencies?

Clarify statement of need and target audience

Disclosure:
Carl Chiarella was a teacher then colleague of mine.

Description

It would be worth clarifying that the scope/target audience is not the financial economics domains or financial market microstucure domains.

These fields have developed deep and sophisticated specialties.
A flavor is given by:

@Article{doi:10.1088/1469-7688/2/5/303,
author = { Carl Chiarella and Giulia Iori },
title = {A simulation analysis of the microstructure of double auction markets},
journal = {Quantitative Finance},
volume = {2},
number = {5},
pages = {346-353},
year = {2002},
publisher = {Routledge},
doi = {10.1088/1469-7688/2/5/303},
URL = {https://www.tandfonline.com/doi/abs/10.1088/1469-7688/2/5/303},
eprint = {https://www.tandfonline.com/doi/pdf/10.1088/1469-7688/2/5/303},
abstract = { Abstract We introduce an order-driven market model with heterogeneous agents trading via a central order matching mechanism. Traders set bids and asks and post market or limit orders according to exogenously fixed rules. We investigate how different trading strategies may affect the dynamics of price, bid-ask spreads, trading volume and volatility. We also analyse how some features of market design, such as tick size and order lifetime, affect market liquidity. The model is able to reproduce many of the complex phenomena observed in real stock markets. *Paper presented at Applications of Physics in Financial Analysis (APFA) 3, 5โ€“7 December 2001, Museum of London, UK. }}

@Article{doi:10.1088/1469-7688/1/2/307,
author = { B. LeBaron },
title = {A builder's guide to agent-based financial markets},
journal = {Quantitative Finance},
volume = {1},
number = {2},
pages = {254-261},
year = {2001},
publisher = {Routledge},
doi = {10.1088/1469-7688/1/2/307},
URL = { https://doi.org/10.1088/1469-7688/1/2/307},
eprint = { https://doi.org/10.1088/1469-7688/1/2/307},
abstract = { This paper is intended to guide researchers interested in building their own agent-based financial markets. Key design questions are outlined, along with some of the major controversies about which directions to take. }
}

Error when generating uniform bidders

  • pymarket version: 0.7.5
  • Python version: 3.6.7
  • Operating System: Windows 10

Description

Generating uniform bidders with a number of buyers or sellers greater than 1/eps returns a ValueError.

ValueError                                Traceback (most recent call last)
<ipython-input-48-62e55ce4d0c0> in <module>
      2 
      3 mar = pm.Market()
----> 4 bids = pm.datasets.uniform_bidders.generate(10001, 10001, 10, 10)
      5 for b in bids:
      6     mar.accept_bid(*b)

~\Anaconda3\lib\site-packages\pymarket\datasets\uniform_bidders.py in generate(cant_buyers, cant_sellers, offset_sellers, offset_buyers, r, eps)
     55     for i, (o_, q_) in enumerate(zip(offset, quantities)):
     56         range_ = np.arange(0, 1, eps)
---> 57         qs = r.choice(range_, q_, replace=False)
     58         vs = r.choice(range_ + o_, q_, replace=False)
     59         for j in range(q_):

mtrand.pyx in mtrand.RandomState.choice()

ValueError: Cannot take a larger sample than population when 'replace=False'

I think this can be solved just by setting eps accordingly.

What I Did

pm.datasets.uniform_bidders.generate(10001, 10001, 10, 10)

Blocking: Tested working install instructions.

  • pymarket version: latest
  • Python version: 3.6
  • Operating System: Ubuntu Bionic

Description

I followed the install instructions.

However, after upgrading pip via pip install --user --upgrade pip pip refuses to start and raises this instead:

Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'

This apparently a well known thing, previously reported.

I hope you can appreciate how frustrating this is? You have broken a users pip installation on their computer!!

Given that you appear to refuse to test your instructions and just wave your hand that this works everywhere:

The only way I can close this issue is:

  1. Update the vagrant scripts such that they work. then update your install instructions accordingly.
  2. Remove all references to install instructions for Linux, and state the only way to get this to run is to use the docker container you provide, and give the link to the built container.

As I commented here, the fastest way to publish this package is the second of the above options.

What I Did

git clone https://github.com/gus0k/pymarket
pushd pymarket/dev/bionic
vagrant up

Instructions incomplete on Ubuntu 16.04

  • pymarket version: pip installed version (version 0.7.5 ?)
  • Python version: python3-pip=8.1.1-2ubuntu0.4
  • Operating System: Ubuntu 16.04

Description

Trying to install pymarket following the instructions.
The instructions result in an error.

Example of an instance of issues #5 and #8.

What I Did

On Ubuntu 16.04, with latest packaged pip installed....

apt install --yes python3-pip=8.1.1-2ubuntu0.4

the instructions abend:

$ pip3 install pymarket
Collecting pymarket
    default:   Downloading https://files.pythonhosted.org/packages/84/53/d74deabe429cbd7cf809b6a272302db251d74c06509f74b86d0f4d1899f2/pymarket-0.7.5-py2.py3-none-any.whl
    default: Collecting pandas>=0.24 (from pymarket)
    default:   Downloading https://files.pythonhosted.org/packages/d9/05/38875a81040e679c196a854865dbafe4dfe5f92e8365ddfff21f2817d89d/pandas-0.25.1-cp35-cp35m-manylinux1_x86_64.whl (10.3MB)
    default: Collecting pulp (from pymarket)
    default:   Downloading https://files.pythonhosted.org/packages/2d/33/3ae6d9d2ac8c7068937af6372fd8828ac605e62a8b17106fe57110930d38/PuLP-1.6.10.zip (13.6MB)
    default: Collecting numpy>=1.16 (from pymarket)
    default:   Downloading https://files.pythonhosted.org/packages/9b/21/2b18339d24a2f73dcefb2f10f48aff6182e16da83e3a612684443c6cfb29/numpy-1.17.2-cp35-cp35m-manylinux1_x86_64.whl (20.1MB)
    default: Collecting networkx (from pymarket)
    default:   Downloading https://files.pythonhosted.org/packages/85/08/f20aef11d4c343b557e5de6b9548761811eb16e438cee3d32b1c66c8566b/networkx-2.3.zip (1.7MB)
    default: Collecting Click>=6.0 (from pymarket)
    default:   Downloading https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl (81kB)
    default: Collecting matplotlib (from pymarket)
    default:   Downloading https://files.pythonhosted.org/packages/12/d1/7b12cd79c791348cb0c78ce6e7d16bd72992f13c9f1e8e43d2725a6d8adf/matplotlib-3.1.1.tar.gz (37.8MB)
    default:     Complete output from command python setup.py egg_info:
    default:     
    default:     Beginning with Matplotlib 3.1, Python 3.6 or above is required.
    default:     
    default:     This may be due to an out of date pip.
    default:     
    default:     Make sure you have pip >= 9.0.1.
    default:     
    default:     
    default:     ----------------------------------------

Error when two bids submitted that cannot be settled

  • pymarket version: 0.7.6
  • Python version: 3.9
  • Operating System: windows 10

Description

When two bids are submitted that cannot be settled I receive an error:

i.e.:

r = np.random.RandomState(1234)
mar = pm.Market()

mar.accept_bid(1, 5, 4, True, 0)
mar.accept_bid(1, 5, 5, True, 0)

mar.accept_bid(1, 6, 6, False, 0)
mar.accept_bid(1, 6, 7, False, 0))

What I Did

The command I ran:

bids = mar.bm.get_df()
transactions, extras = mar.run('p2p')
stats = mar.statistics()

The error message:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-128-a1f818cf5b34> in <module>
      1 bids = mar.bm.get_df()
----> 2 transactions, extras = mar.run('uniform')

c:\projects\colombiadata\venv\lib\site-packages\pymarket\market.py in run(self, algo, *args, **kwargs)
    150         df = self.bm.get_df()
    151         mec = MECHANISM[algo](df, *args, **kwargs)
--> 152         transactions, extra = mec.run()
    153         self.transactions = transactions
    154         self.extra = extra

c:\projects\colombiadata\venv\lib\site-packages\pymarket\mechanisms\mechanism.py in run(self)
    170     def run(self):
    171         """Runs the mechanisms"""
--> 172         trans, extra = self._run()
    173         trans = self._cleanup(trans)
    174         return trans, extra

c:\projects\colombiadata\venv\lib\site-packages\pymarket\mechanisms\mechanism.py in _run(self)
    133         N = bids.shape[0]
    134         if (bids.loc[bids['buying']].shape[0] not in [0, N]):
--> 135             trans, extra = self.algo(self.bids, *self.args, **self.kwargs)
    136             return trans, extra
    137         else:

<ipython-input-125-14a8cb0a7b32> in uniform_price_mechanism(bids)
     16 
     17     ## Filter only the trading bids.
---> 18     buying_bids = buying_bids.iloc[: b_ + 1, :]
     19     selling_bids = selling_bids.iloc[: s_ + 1, :]
     20 

TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

Incomplete install instructions

Is there not a clearly-stated list of system and python package dependencies
There are no instructions about how to handle these with an automated package management solution.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.