Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lebedov/nseindia_lob
National Stock Exchange of India Limit Order Book Simulation
https://github.com/lebedov/nseindia_lob
limit-order-book simulation stock-market
Last synced: 3 months ago
JSON representation
National Stock Exchange of India Limit Order Book Simulation
- Host: GitHub
- URL: https://github.com/lebedov/nseindia_lob
- Owner: lebedov
- License: other
- Created: 2013-08-11T23:52:59.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2020-10-01T15:07:52.000Z (over 4 years ago)
- Last Synced: 2024-01-29T20:44:17.245Z (about 1 year ago)
- Topics: limit-order-book, simulation, stock-market
- Language: Python
- Size: 441 KB
- Stars: 27
- Watchers: 4
- Forks: 14
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
.. -*- rst -*-
National Stock Exchange of India Limit Order Book Simulation
============================================================
This package implements a limit order book that simulates the
processing of limit/market orders on India's National Stock Exchange (NSE).Requirements
------------
The code requires the following software for installation (older versions may
work, but haven't been tested):* Python 2.7 or later.
* `cython `_ 0.19.1 or later.
* `numpy `_ 1.7.0 or later.
* `pandas `_ 0.10 or later.
* `odict `_ 1.5.0 or later.
* `rbtree `_ 0.9.0 or later.Installation
------------
Build the extension by running: ::python setup.py build_ext --inplace
Running the Simulation
----------------------
To run the simulation, invoke the simulation script with a specified firm name,
output directory, and list of input files. For example: ::python lob.py INCI ./output INCI-orders-03092013.csv.gz INCI-orders-03102013.csv.gz
A sample data file (``EXAMPLE-orders.csv``) is included. A script for launching
the code on a Sun Grid Engine cluster is also included; the script requires the
`drmaa-python `_ package. To use the script, replace
the listed security names accordingly.Input File Format
-----------------
The simulation requires input files in CSV format comprising the following
columns with the indicated byte lengths. The input file may be compressed with
gzip.record indicator (2)
Ignored.
segment (4)
Ignored.
order number (16)
8 left-most digits are date YYYYMMDD, followed by 00000001-99999999.
transaction date (10)
MM/DD/YYYY
transaction time (14)
HH:MM:SS.XXXXXX, where XXXXXX is microseconds.
buy/sell indicator (1)
Must be either 'B' or 'S'.
activity type (1)
Must be 1 (order add), 3, (order cancel), or 4 (order modify).
symbol (10)
Firm identifier.
instrument (6)
Ignored.
expiry date (10)
MM/DD/YYYY
strike price (variable)
Integer.
option type (2)
Ignored.
volume disclosed (variable)
Integer.
volume original (variable)
Integer.
limit price (variable)
Float.
trigger price (variable)
Float.
market flag (1)
'Y' for market order, 'N' for limit order.
stop loss flag (1)
'Y' for stop loss order, 'N' for regular lot order.
Immediate-or-Cancel (IOC) flag (1)
'Y' for IOC, 'N' for non-IOC.
spread/combination type (1)
Ignored.
algo indicator (1)
Ignored.
client identity flag (1)
Ignored.Methodology and Implementation
------------------------------
The limit order book is implemented as two red-black trees of queues
corresponding to different buy and sell price levels. The use of red-black trees
accelerates determination of the bid and ask prices at any step of the
simulation. Further acceleration is achieved by compiling the simulation with Cython.Order processing is restricted to the orders with the first futures expiration date
observed during processing; all other orders are ignored.Submitted orders may be add requests, modification requests, or cancellation
requests. Both market and limit orders are supported; during processing, the
former are discarded if they fail to match any orders already in the
book. Residual volume for IOC orders is discarded. Orders that have explicitly
disclosed (i.e., non-zero) volumes are assumed to be hidden; if any such orders
in a price level queue, they are matched against a new incoming order AFTER
orders with zero disclosed volume.Daily stats are accumulated during the simulation and are reset when the date
associated with the processed orders changes.Author
------
The code was written by Lev Givon in 2012-2013 for Prof.
Costis Maglaras at Columbia Unversity's Business School.License
-------
See included LICENSE file.