TaiwanQuant's Newsletter

TaiwanQuant's Newsletter

Share this post

TaiwanQuant's Newsletter
TaiwanQuant's Newsletter
Interlude - Precise Decimals In Quant Systems (Part 2/2)
Copy link
Facebook
Email
Notes
More

Interlude - Precise Decimals In Quant Systems (Part 2/2)

How to implement an efficient fixed-point decimal for high-frequency market data.

TaiwanQuant's avatar
TaiwanQuant
Jun 16, 2023
∙ Paid
6

Share this post

TaiwanQuant's Newsletter
TaiwanQuant's Newsletter
Interlude - Precise Decimals In Quant Systems (Part 2/2)
Copy link
Facebook
Email
Notes
More
Share

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:

  1. It is just as performant as regular integers for many operations.

  2. 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.

  3. It is portable across languages, in particular, we can use it directly from Python and R.

  4. 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:

  1. The 64-bit variant with 8 decimal digits is suitable for Crypto futures markets.

  2. 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.

Let’s dive in.12

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.

Already a paid subscriber? Sign in
© 2025 TaiwanQuant
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share

Copy link
Facebook
Email
Notes
More