10 ms·
Summary: Nasdaq computers store stock prices as a 32-bit number representing the number of 1/100'ths of a penny, which means the highest dollar amount it can st
by derekp7 5y ago
Summary: Nasdaq computers store stock prices as a 32-bit number representing the number of 1/100'ths of a penny, which means the highest dollar amount it can store is $429,496.7296 (2 ^ 32 / 10000).
- repiret 5y agoThe highest they can store is (2^32-1)/10000.
- zeusk 5y ago((2^32)-1)/10000 assuming they don't care about negative equity price.
- repiret 5y agoIf they were storing it in a signed 32-but integer, it would have already overflowed.
- sgtnoodle 5y agoThey could also be applying an arbitrary offset to support some range of negative value. This whole tangent seems a bit pedantic though. :-) They probably should have used uint64!
- eru 5y agoOr perhaps just move to arbitrary-length integers. (Eg what Python gives you by default.) Or even rational numbers. Both are a bit slower than using ints built into the machine, but exchanges don't have to be particularly fast. (In contrast to HFT participants. But they just need to be faster than their competitors.)
- sgtnoodle 5y agoMy suspicion is that the field is a fixed size for serialization inside a database table or something. Truly variable length fields are trickier to store and then subsequently iterate over non-sequentially. When you say rational numbers, do you literally mean a fraction, or are you talking about a floating point representation? I'm not sure what a fraction would do over fixed point in this usage, and floating point is best avoided for anything finance related due to the fact that they're approximate. They probably regret not just using 64-bit from the start, but on the other hand somebody likely saved a measurable amount of money on storage over the years. Potentially not worth the cost to figure out a workaround now, though. Perhaps they could implement a rule where if the field equals MAX_UINT32, then the value must be looked up in an auxiliary database table. Depending on how much crufty code there is assuming 32-bit though, it may be their equivalent of y2k.
- eru 5y agoI meant a genuine fraction. So you have arbitrary precision. Yes, variable length fields are a bit annoying. But my argument is that the exchange itself doesn't need to be that fast. And the market makers just need to be faster than each other. (For anyone else, exchanges just need to be fast enough.) Yes, just using a 64 bit integers is probably the easiest here. Floats would be worse than my suggestion to use variable length rational numbers, for exactly the reasons you know.
- Thorrez 5y agoThat's the exact same thing that repiret said, I think. I think power (^) has higher precedence than subtract (-). So (2^32-1)/10000 == ((2^32)-1)/10000 WolframAlpha agrees: https://www.wolframalpha.com/input/?i=%282%5E32-1%29%2F10000+%3D%3D+%28%282%5E32%29-1%29%2F10000 https://www.wolframalpha.com/input/?i=%282%5E32-1%29%2F10000...
- Uptrenda 5y agoHonestly, I always found precedence rules horribly ambiguous. I just use brackets for clarity and forget about it. Or is this considered 'bad practice'?
- LorenPechtel 5y agoI've never found it to be an issue with math. Unary minus > powers > multiplication/division > addition/subtraction. I have seen differences in the precedence of logical operators between languages (and > or but what happens when you have both math and logic in the same statement isn't entirely consistent) and always use parenthesis in those cases--although these days if Resharper says it's redundant I let it remove them.
- Thorrez 5y agoI don't consider it bad practice to insert parentheses, especially with exponentiation because many people are less familiar with its precedence rules.
- throwaway2037 5y agoI don't understand why this was down voted. It is an interesting comment! I always assume the floor for equity is the first tick above zero, e.g., 1 US cent or 1 Euro cent or 1 Japanese yen. Honestly, I don't know if any traditional stock exchanges allow zero price or less for shares. If anyone knows an example, please post about it! Another reason why this comment matters: Does anyone remember when oil futures went negative? (April 2020) I am sure more than a few computer systems were unprepared for that scenario. I remember when short-end Japanese rates were zero and negative after the 2008 Global Financial Crisis. It was a real monkey wrench in the machine!
- t0mas88 5y agoProbably downvoted because 2^32-1 is the same as (2^32)-1, it's 2^(32-1) you're confused with. Although downvoting just for that feels a bit pedantic to me. The the intention of both comments was clear... To discuss signed vs unsigned integer.
- beejiu 5y agoThere's a reason futures can go negative, that is when the contracts get close to expiry, the holder becomes legally liable to receive the oil. Since the speculators have no way to actually do this (and that storage was at capacity anyway), it makes sense to sell to shift the liability to someone else. There is not such analog for shares that I can see.
- throwaway2037 5y agoYou wrote: <<the holder becomes legally liable to receive the oil>> Very good point! We should be clear for other readers: For many commodities futures, there are two types: physical and cash settle. (From my experience, liquidity can vary wildly!) Example: Physical oil futures require you to deliver (short)/receive (long) oil at expiry. Cash (settle) futures only require an exchange of cash at expiry.
- tacostakohashi 5y agoThis seems like a strange decision given that: * Until 2000, stocks were priced in fractions of a dollar (8ths, 16ths, etc) before moving to cents (https://www.sec.gov/hot/decimal.htm https://www.sec.gov/hot/decimal.htm) * These days, prices on exchanges must be in one cent increments, and not smaller (https://www.sec.gov/divisions/marketreg/subpenny612faq.htm https://www.sec.gov/divisions/marketreg/subpenny612faq.htm) Perhaps they're using the same software as for overseas markets, or its some future-proofing gone wrong or something.
- ed312 5y agoFrequently if the bid is say 40.10 and the ask is 40.09, the mark is shown as 40.095. Not sure if that's why they have hundredths, or just to support those legacy cases of odd fractions.
- luckman212 5y agoNitpick: I think you meant bid 40.09 x 40.10 ask. Otherwise you'd have a crossed market or a trade executed.
- bdonlan 5y agoOrders are generally quoted in cents, but trades execute off-book at fractional cent prices on a regular basis (e.g. when a HFT firm is providing price improvement).
- travisjungroth 5y agoI had forgotten that prices were fractional. I remember prices like 7 3/4 when I was a kid.
- blibble 5y agoCME still uses fractions
- deleted 5y ago[deleted]
- 5y ago
- Jiocus 5y ago"32-bit number representing the number of 1/100'ths of a penny ought to be enough for anybody."
- nightski 5y agoIt probably would be for quite some time. The article lists the next highest stock is $5,100. This is all due to stubbornness on the part of Warren Buffet, for better or worse.
- coliveira 5y agoThis should be easy for Nasdaq to solve: just force companies to split their shares before they reach certain limits. Markets can create rules that listed companies need to follow, and this seems to be a useful one.
- eru 5y agoExchanges can create rules, but there's a limit to how far they can push it: If Nasdaq makes too many rules that investors or companies dislike, they'll list respectively trade elsewhere. Developments in the rest of the market make stock splitting less of an imperative than in the past. Eg Robinhood and many other retail brokerages allow you to own partial shares now. If you follow the logic of these recent developments, individual shares might become a thing of the past, and we will just directly trade fractions of whole companies. (On your computer, rational numbers are easy to implement: just represent them as a pair of arbitrary-length integers. Operations will be a lot slower than on floats or ints, but the exchange doesn't need to do too many operations per second. And market makers and hedge funds etc can use whatever approximation scheme they want in their internal systems.)
- berkes 5y agoBut how can you own part of a share?
- 5y ago
- cout 5y agoAt a previous job (over a decade ago), I worked on software that stored prices in centipennies. I'm pretty sure it's no longer in production. At least, I hope it isn't. But these things sometimes surprise me. A few years ago I paid a visit to my coworkers at the job I had in high school in the mid nineties. I had written some sort of email processing program in C; I don't even remember what it did any more. I was told they are still using it, 25 years later. Awesome or scary, I don't know which.
- aazg 5y ago$429,496.7295 $429,496.7296 would overflow