Giter Club home page Giter Club logo

nseindia_lob's Introduction

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.

Requirements

The code requires the following software for installation (older versions may work, but haven't been tested):

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.

nseindia_lob's People

Contributors

lebedov avatar

Watchers

James Cloos avatar Srinivasa Rao Somu avatar

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.