I started ExchangeEngine on GitHub in 2015 to experiment with setting up continuous integration and testing on some different services. Back in 2015 I didn't get far with the project after I had finished messing around with the continuous integration systems. I randomly picked it back up recently and got it to a minimal product.

At its most basic, ExchangeEngine is a Node.js library that allows you to create an exchange for any generic thing you wish. Currently, it is very minimal with no explicit architecture defined for users or authentication. In theory, you can use ExchangeEngine to back any type of exchange - be it stocks, Bitcoin, or Pokemon Cards.

The order types supported are Limit and Market orders with FIFO priority execution.


Given the two orders coming in:

var order1 = {
    quantity: 1,
    price: 3,
    side: Order.SIDE.ASK,
    type: OrderTypes.LIMIT,
    owner: "user1",
    status: Order.STATUS.ACTIVE,
    time: new Date()

var order2 = {
    quantity: 1,
    price: null,
    side: Order.SIDE.BID,
    type: OrderTypes.MARKET,
    owner: "user2",
    status: Order.STATUS.ACTIVE,
    time: new Date()

The Exchange Engine will find a match and produce a trade:

[ Trade {
    fillPrice: 3,
    fillQuantity: 1,
    newOrders: [],
    childOrders: [ [Object], [Object] ],
    rejectedOrders: [],
    executionTime: 2019-02-05T04:47:36.119Z } ]


Backing the order matching engine is a fibonacci heap. I picked it because it sounds cool (just kidding). This seems to produce satisfactory performance on my dying MacBook Pro retina. As expected with the heap, the performance depends on the book depth.

Book Depth - Transactions/Second
100 219,257
500 56,879
1,000 26,894
10,000 2,171

Given that the daily volume of SPY today was 60,673,524, if each trade was one share, that'd be around 2,592 trades per second in the 6.5 hour trading day. Not a bad start.

If your application is running on the cheapest MacBook, has books 10k orders deep, and transacting more volume than SPY, you can probably afford something better than this free GitHub project.

Although this performance is more than sufficient for most, I am thinking of implementing a more memory intensive but much faster matching engine. I also have some fun ideas for projects with this. More on this later...

Volatility Surface Visualizer Updates

I finally added some updates to the Volatility Surface Visualizer that will allow you to finally get quantitative data from it (at GitHub). I also added some rudimentary empty fill interpolation to make the surface prettier. Furthermore, I finally added axes and ray casted value reader. Just click on the surface, and you can see the interpolated date, strike, and IV.

Interpolation / Parameterization

I wasn't really aware when I started this project, but this seems to be a subject that is far more complex that I had originally anticipated. The pricing data straight from CBOE becomes fairly ugly very quickly for the illiquid contracts. In order the make the surface less chaotic, I really prefer some sort of interpolation or parameterization.

Currently, the viewer uses a pretty rudimentary strategy. The surface is populated on a grid of all observed strikes and expirations. For all expirations, from the current price, an empty fill is done for all missing values - middle out. This gets the job done for now.

Popular strategies such as Arbitrage-free SVI volatility surfaces (pdf) exist, but for my purposes, I don't know if the juice is worth the squeeze.

Ray Cast Value Viewer

Now you can click anywhere on the surface and see the interpolated strike, price, and Implied Volatility.

Implied Volatility Surface Viewer

The implied volatility is the single most important descriptor of options contracts. There are generally a large number of available contracts given the different strikes and expiries for a given underlying instrument. Generally a table of options contracts quotes looks like this:

Option Chain View on thinkorswim

The table above is still excluding the majority of strikes & dates. You can often see different patterns of implied depending on the beliefs of market participants. Future political or corporate events may show up as bumps of IV. Differences in concerns or beliefs about the future risks of the underlying may show up as a skew.

I've often wanted to view this visualized as a 3D surface, however, I'm to poor to be able to afford a Bloomberg Terminal. I worked on a 3D surface viewer using exported CBOE pricing data that can be run on the browser. This is still very much a work in progress.

You can see the surface, but it's mega ugly in certain parts due to illiquid pricing. In addition to adding more analytical information, I will be adding either some sort of interpolation or parameterization.

You can check out the code & try it out for yourself on github