r/quant • u/RealisedGains • 12d ago
Technical Infrastructure Decimals, floats, kdb
It's often touted not to use floating point types in finance, and instead store as integers with some multiplier or use fixed decimal types.
Yet kdb is/was rather popular for storing tick and derived data, and has no concept of a decimal data type.
What gives here?
18
Upvotes
42
u/Regular-Hotel892 12d ago
It may be touted but it’s not rooted in reality, firms do use floats
12
u/EngineeringApart4606 12d ago edited 12d ago
I’m still waiting to see the real problem case that double-precision can’t handle, after ~2 decades in the industry
Like not a vague description of a problem, or an “if you get it wrong, then it’s wrong” type statement, but a specific number and set of operations that you would encounter in a real system that couldn’t work in binary double precision.
I’ve even seen string decimal to binary double and back be provably lossless to the limits of double precision (almost 16 sig figs), so long as the decimal strings had enough precision (from memory, 17 sig figs in, 15 out.
I’ve also met a surprising number of educated people who think floating-point numbers are either magical infinite precision, or some completely arbitrary bit-mangling machine that cannot be trusted to do anything without discarding precision in a completely unfathomable way
3
u/starostise 12d ago
In our case, floats are sent as strings from the data source.
We store them as strings in database and we convert them to floats in RAM for computations. We never round during computations.
We only round the output (display and API requests).
1
u/lordnacho666 12d ago
You either just use floats and figure out some rounding, or you store the number as an int and have a table that tells you how many decimals it has.
1
u/Stunning_Carry784 12d ago
Just don't use unsigned ints for quantities, that's a sure fire way to go broke pretty quickly.
1
u/desi_cutie4 12d ago
Use floats where accuracy is not required.
For example, I would run my entire pipeline in floats and only round to ticks before sending orders. Btw this is for sub-minute options strategy so it doesn't matter.
1
u/jeffjeffjeffw 12d ago
Interesting as coincidentially I've encountered so many float64 vs float32 issues recently
1
u/algoseekHQ 9d ago
I think it really depends on what you're doing with the data. Float64 is perfectly reasonable for most market data analysis and modeling. But when you need exact values, like cash balances, settlement, or tick-level price comparisons, decimals or scaled integers make more sense. You don't necessarily need the same representation for storage and computation.
1
u/supercoco9 11d ago
Disclaimer: I work at QuestDB.
We had a lot of users working at crypto or market data complaining that not having a proper decimal type was an issue for them, forcing them to use workarounds like some of the ones described at the comments here.
We eventually added a decimal datatype about a year ago https://questdb.com/blog/questdb-9-2-release/. Most users still go with DOUBLE by default, as it is lighter and good enough, but when you really need a decimal, nothing beats storing your numbers and knowing arithmetic will work
0
u/nrs02004 12d ago
I think strings are the safest -- prices aren't meant to be mutable.
0
u/Academic-Village2923 11d ago
Genuine question how popular is kdb really and is this thing going to stay with pandas etc being so handy?