Interlude - Precise Decimals In Quant Systems (Part 2/2)
How to implement an efficient fixed-point decimal for high-frequency market data.
Last week we covered the role and different implementations of precise decimals in a Quant trading system.
In this article, we show how to implement an efficient fixed-point decimal on top of a native integer. This implementation will be suitable for handling and storage of market data, particularly high-frequency order book data.
The technique is attractive to us for the following reasons:
It is just as performant as regular integers for many operations.
It uses the same space and representation as a regular integer, usually 64 or 128 bits, which makes it possible to store it as such.
It is portable across languages, in particular, we can use it directly from Python and R.
To the best of my knowledge, it is the simplest, fastest and most memory-efficient representation of precise decimals.
Its caveat is that it is constrained by range:
The 64-bit variant with 8 decimal digits is suitable for Crypto futures markets.
The 128-bit variant with 16 decimal digits is preferred to cover spot markets due extreme cheapness of certain shitcoins.
Here we implement the 64-bit variant. The 128-bit variant can be implemented in an analogous way or at the same time via generics/codegen.
The complete source code was released early with Subscriber Materials for Part 1. We attach it to the end of this article again for the reader’s convenience.
Keep reading with a 7-day free trial
Subscribe to TaiwanQuant's Newsletter to keep reading this post and get 7 days of free access to the full post archives.