Skip to content

Instantly share code, notes, and snippets.

@halfelf
halfelf / how_to_build_a_fast_limit_order_book.md
Created February 11, 2019 02:18
How to Build a Fast Limit Order Book

https://web.archive.org/web/20110219163448/http://howtohft.wordpress.com/2011/02/15/how-to-build-a-fast-limit-order-book/

The response to my first few posts has been much larger than I’d imagined and I’d like to thank everyone for the encouragement.

If you’re interested in building a trading system I recommend first reading my previous post on general ideas to keep in mind.

My first really technical post will be on how to build a limit order book, probably the single most important component of a trading system. Because the data structure chosen to represent the limit order book will be the primary source of market information for trading models, it is important to make it both absolutely correct and extremely fast.

To give some idea of the data volumes, the Nasdaq TotalView ITCH feed, which is every event in every instrument traded on the Nasdaq, can have data rates of 20+ gigabytes/day with spikes of 3 megabytes/second or more. The individual messages average about 20 bytes each so this means handling

@halfelf
halfelf / type_name.cpp
Created May 14, 2019 05:02
Get C++ type name
template <class T>
constexpr std::string_view type_name() {
#ifdef __clang__
std::string_view p = __PRETTY_FUNCTION__;
return std::string_view(p.data() + 34, p.size() - 34 - 1);
#elif defined(__GNUC__)
std::string_view p = __PRETTY_FUNCTION__;
# if __cplusplus < 201402
return std::string_view(p.data() + 36, p.size() - 36 - 1);
# else
@halfelf
halfelf / completion.sh
Created July 2, 2019 02:21
case insensitive bash completion
# If ~/.inputrc doesn't exist yet: First include the original /etc/inputrc
# so it won't get overriden
if [ ! -a ~/.inputrc ]; then echo '$include /etc/inputrc' > ~/.inputrc; fi
# Add shell-option to ~/.inputrc to enable case-insensitive tab completion
echo 'set completion-ignore-case On' >> ~/.inputrc
# add option to /etc/inputrc to enable case-insensitive tab completion for all users
# echo 'set completion-ignore-case On' >> /etc/inputrc
@halfelf
halfelf / garch11.cpp
Created May 5, 2020 07:23
GARCH(1, 1) MLE in C++
// Parameter estimation for GARCH(1,1) model
// Fitted to S&P500 index levels
// By Fabrice Douglas Rouah, 2009
// For Visual C++.Net Version 7.1
//#include "stdafx.h"
//using <mscorlib.dll>
#include <iostream>
#include <fstream>
#include <iomanip>
cmake_minimum_required(VERSION 3.16)
project(odr_test)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_executable(odr_test main.cpp)
add_library(odrl SHARED lib.cpp)