Static Order Book Imbalance (SOBI) Strategies

Updated: September 27, 2002

Strategy Summary

The underlying idea behind this family of strategies is rather simple. Imagine visualizing the distribution of volume at different prices in the buy and sell order books, as can be done nicely with Island's GUI tool (go to the "Order Book Chart" on the right). If the "shape" of the buy and sell distributions away from the last price differ sharply, it might be an indication of upcoming price movement that can be profitably acted upon. In this family of strategies, we investigate this idea only very crudely and superficially, looking for large imbalances in one distribution compared to the other. We also only do this statically, as opposed to computing the movements of the distributions. Clearly, refinement of these basic ideas is a major avenue for further research.

To describe the SOBI strategy family more precisely, we need to introduce some terminology.

Terminology

lastPrice: The most recently updated market price
bi (i=1,2,3,4) : The volume-weighted average price of the top i*25% of the volume in the buy order book. Thus b1 is computed by taking the top 25% of the buy order volume, and computing the average price offered per share. Note that b4 is simply the volume-weighted average of the entire buy order book.
si (i=1,2,3,4) : The volume-weighted average price of the top i*25% of the volume in the sell order book.

Si: si - lastPrice
Bi: lastPrice - bi

Note that Si and Bi will always be positive numbers. They can be interpreted as a measure of the "distance" from the last price of the top i*25% of the respective order book.

The SOBI Strategies

1. Basic SOBI. The basic SOBI strategy perpetually computes Si and Bi and places buy or sell orders according to the following rules:

    If (Si - Bi > theta), place an order to buy orderVolume shares at (lastPrice-orderPrice);
    If (Bi - Si > theta), place an order to sell orderVolume shares at (lastPrice+orderPrice);

We refer to SOBI as a family of strategies because we leave the choices of i=1,2,3,4, theta, orderPrice, and orderVolume as parameters.

2. Hedging SOBI. Here we introduce a new parameter hedgeOrderPrice, the "hedge" parameter.

    If (Si - Bi > theta), place an order to buy orderVolume shares at (lastPrice-orderPrice);
                                    and also place an order to sell orderVolume shares at (lastPrice+hedgeOrderPrice);
    If (Bi - Si > theta), place an order to sell orderVolume shares at (lastPrice+orderPrice);
                                    and also place an order to buy orderVolume shares at (lastPrice-hedgeOrderPrice);

Running the SOBI Strategies

1. NEW INSTRUCTIONS, 9/29/02: We have simplified and centralized the use of the pxs and sobi executables. We have created an account on gradient with the username pxs that we will use for administration purposes, and we will make executables and source code available under the file system of pxs. Please send requests for project systems help to the project account pxs@gradient.cis.upenn.edu.

Thus, the most recent goodies will generally be available in directory /home/pxs/bin on gradient. We thus now recommend that you execute pxs and sobi using the following commands:

  • To execute pxs: nohup /home/pxs/bin/pxs -p port_number >& out.pxs & where port_number is one of your assigned ports
  • To execute sobi: nohup /home/pxs/bin/sobi -p port_number >& out.sobi & You can of course also specify other sobi parameters following the -p option. General sobi syntax:
    sobi -p port_number [-q i] [-t theta] [-r orderPrice] [-h hedgeOrderPrice] [-v orderVolume] > out.sobi &
    Here the arguments to the various flags modify the trading strategy executed in the way described above in "Basic SOBI" and "Hedging SOBI".

    Some comments and explanation on the command syntax:

  • Note that these commands will execute whatever code is in /home/pxs/bin, and thus you are no longer copying exectuables to your local directory. This is good because it allows us to modify and improve the code without everyone having to recopy. If we make changes you should know about (e.g. changing the format of the output), we will let it be known on this page.
  • The output files out.pxs and out.sobi will still be written in your local directory.
  • The "nohup" at the beginning is necessary to let your job continue running even if you log out of gradient. Again, remember to manage and monitor your jobs!
  • The redirect ">& out.pxs" above (for example) makes sure that any error messages written to stderr by the programs will also go to the same output file as the normal output. This will prove very helpful in debugging, so please run things this way.

    Notes:
    1. to avoid port collision, users must use only their assigned port numbers!

    2. 'quartile' determines which quartile value your strategy will use.  The possible values for this are 1(25%), 2(50%), 3(75%), 4(100%)
    3. orderPrice and hedgeOrderPrice determine (hedge)order price. For example, if you write "-r 0.5",  the agent place buyOrder at (lastPrice - 0.5) and sellOrder at (lastPrice+0.5).
    4. If you do not specify a parameter on the command line, default values are as follows.
                     quartile = 2; // 50%
                     theta = 0.07;
                     orderPrice = 0;
                     orderVolume = 333;
     

    Some Handy Unix Commands

  • I suggest that people consider the Unix utility "gnuplot", which can be invoked from the command line on gradient, for plotting purposes. Within gnuplot, you can do "help plot" to learn about the various options. As one simple example, within gnuplot you can simply type plot "foo.dat" with lines to get a plot of the data points in the file foo.dat. Please see below, for a brief note on how to crate a postscript file for a plot.
  • It is very important that project members manage their own processes, and prevent runaway jobs on gradient. We expect you to be responsible for monitoring and ending your processes. Towards this goal, the unix command ps is essential. The command ps -aux | grep pxs might result in the following output:

    mkearns 9586 0.1 0.2 2552 2032 pts/81 S 08:13:55 0:01 ./pxs -p 9800
    mkearns 10272 0.1 0.1 976 744 pts/81 S 08:18:17 0:00 grep pxs

    This simply indicates that among all users, there are two jobs running involving the string "pxs". One of these is the ps command itself, but the other, number 9586, is a simulator job. This job can be terminated by the command kill -9 9586. You can learn more about ps via doing "man ps".

  • You will find the Unix utility grep very useful for extracting specific lines from files. Do "man grep". [See below for some examples.]

    How to create a postcript file of a plot in gnuplot

  • Briefly, to write a plot of the data file "foo.dat" in postscript format to the file "foo.ps", the commands are

    set terminal postscript
    set output "foo.ps"
    plot "foo.dat" with lines
    set terminal x11
    set output

    Please, read below for more information.

  • In gnuplot, a terminal determines the "format" in which a plot will be "displayed." The default terminal is x11, which just opens a X window and displays the plot there.

    To make gnuplot to write the plot in "postscript" format, just execute the following command in the gnuplot interpreter

    set terminal postscript

    We also want gnuplot to write the plot to a file. To write to file "foo.ps", type

    set output "foo.ps"

    Finally, to plot the data file "foo.dat" as a line, type

    plot "foo.dat" with lines

    Note that when we execute this command, the plot will not be shown as an X window, since we have changed the terminal. So we'll not really see what we are plotting and the current X window will not refresh. The idea is that before we changed the terminal and output, we had plotted the data to the X windows already. The command will instead generate a file "foo.ps" that is a postscript version of the plot. You can then use an external postscript viewer like 'gv' (outside gnuplot!) to display and print the postscript file. When done plotting to the file, we want to get back to the default values for terminal and output in gnuplot. To do this, type

    set terminal x11
    set output

    This will set the terminal so that future plots will be shown in the screen and the output will be written to the X window terminal where gnuplot is running, as it was before we decided to plot to a postscript file. This is important since if the terminal or the output is not changed, gnuplot will keep writting future plots to the output file in the terminal format specified!

    One way to know the current setting of these options is by executing the command 'show'. For instance,

    show terminal
    show output

    displays information about the current settings of the terminal and output options, respectively. Similarly with other options.

    Yet, another way of doing all this in one step is by writing a "gnuplot script"---a file containing a sequence of gnuplot commands. For instance, let's say we write a file, called it 'plotps.gnu', with the following lines

    set terminal postscript
    set output "foo.ps"
    plot "foo.dat" with lines
    set terminal x11
    set output

    Then at the gnuplot prompt ('gnuplot>'), we type

    load "plotps.gnu"

    This will plot the data in the file 'foo.dat' and write it to the file 'foo.ps'. So, as you can see, when using the gnuplot command 'load' with a "script" file, it will just execute the gnuplot commands sequentially as if they were entered interactively (in the same sequence) at the gnuplot prompt. In general, you can create many different scripts of this kind that suit your needs. In general, we encourage you to play with gnuplot and create your own scripts.

    You can always learn more by using the help provided in gnuplot. For instance, typing

    help

    will display the main help menu. From there you can get additional help on different sub-topics. You can also go immediate to the help for a specific command, option, or keyword in gnuplot, by typing

    help [command | option | keyword]

    For example,

    help plot

    displays help on how the plot command works. Similarly, you can execute 'help set', 'help terminal', 'help output', 'help with', 'help lines', etc. You can also find more information, and even manuals on how to use gnuplot, by doing a web-search.

    Some useful scripts

    The following are some useful scripts to extract information from your output files 'out.pxs' and 'out.sobi'. You can find at '/home/leortiz/ '.

  • getpxs is a "bash script" that extracts information from the output of pxs during execution.

    Usage: getpxs OPTION IFILE OFILE

    where

    OPTION : --price (extract "Last price" field values from IFILE)
    IFILE : name of file containing pxs output (i.e., 'out.pxs')
    OFILE : name of file where extracted data will be written out (i.e., 'price.dat')

    Example usage:

    getpxs --price out.pxs price.dat

    writes the price of the stock throughout the execution of the simulator from the file 'out.pxs' to the file 'price.dat'.

  • getsobi is a "bash script" that extracts information from the output of sobi during execution.

    Usage: getsobi OPTION IFILE OFILE

    where

    OPTION : --value (extract "Present Value" field values from IFILE), --share (extract "Share" field values), --cash (extract "Cash" field values)
    IFILE : name of file containing pxs output (i.e., 'out.sobi')
    OFILE : name of file where extracted data will be written out (i.e., 'value.dat')

    Example usage:

    getsobi --value out.sobi value.dat

    writes the value of sobi trategy throughout its the execution from the file 'out.sobi' to the file 'value.dat'.