Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Orderbook implementation #12

Open
femtotrader opened this issue May 19, 2019 · 6 comments
Open

Improve Orderbook implementation #12

femtotrader opened this issue May 19, 2019 · 6 comments

Comments

@femtotrader
Copy link
Member

femtotrader commented May 19, 2019

Improving orderbook implementation to support dynamic features (insertion, deletion, cancellation, and modification of orders) might be considered

AVL tree
https://en.wikipedia.org/wiki/AVL_tree
seems to be a quite common used datastructure for implementing such features (thanks @brilhana for sharing this)

See also
https://csce.ucmss.com/cr/books/2018/LFS/CSREA2018/FCS3665.pdf
https://www.doc.ic.ac.uk/~wl/papers/17/fpl17ch.pdf

Related issue
Implementing a limit order book matching engine JuliaFinance/Roadmap#17

@femtotrader
Copy link
Member Author

Julia doesn't seem to have currently an AVL tree implementation (except https://github.com/torgausen/JuliaAVL which is 7 years old)

Maybe a first step could be add such an implementation to DataStructures.jl

@StephenVavasis
Copy link

StephenVavasis commented May 20, 2019

DataStructures.jl already has balanced trees: 2-3 trees are the basis for SortedDict, SortedSet and SortedMultiDict. Their performance is comparable (same up to constant factors) to AVL trees. My testing, now several years old, seemed to indicate that the main performance bottleneck with SortedDict, SortedSet and SortedMultiDict is poor memory locality of reference. There is work on "cache oblivious" balanced B-trees by Bender, Demaine and Farach-Colton, which have superior memory locality, but to the best of my knowledge this work has not been implemented in Julia.

@femtotrader
Copy link
Member Author

femtotrader commented May 20, 2019

Hi @StephenVavasis thanks for this comment but maybe comments about AVL tree implementation should occurred in DataStructures.jl repository.

@lorrp1
Copy link

lorrp1 commented Dec 26, 2020

@femtotrader the repository is 2 years old and there is no documentation, I’m looking to create an order book as well but I’m not sure if this is a good place to start since it’s pretty old

@p-casgrain
Copy link

p-casgrain commented May 1, 2021

I have begun working on an LOB implementation using AVL trees. I am roughly following along the lines of this Python implementation . I have found the implementation of the AVL tree in DataStructures.jl to be list-like so I have opted to use the following dict-like implementation which is closer to what is needed. Should the current DataStructures.jl implementation be replaced or amended in the future, it should be easy to modify the code accordingly. I have found both libraries have comparable performance anyways.

The current implementation is intended to be relatively barebones: i.e. trading a single asset, with no built-in message parsing. I am also a Julia novice, so I will definitely require a code review once completed.

@p-casgrain
Copy link

I am at the point of forking and uploading my changes but I realize that the OB implementation has a dependency on the AVLTrees package hosted in the following repo. It's not currently listed in Pkg.jl, do any of you have some tips on how to go forward?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants