I realize that we should use BigDecimal for all monetary values, but what about stock prices in dollars?
I noticed that data feed API from major vendors uses the type double for stock quotes. Does anyone know why?
Does that mean my application can use the type double to store stock quotes that come from these vendors?
I work in the field. BigDecimal is obviously ideal from a precision perspective, but it sucks from a performance perspective. doubles are an option in some circumstances (particularly when dealing with normal equity prices, doubles are easily – with appropriate precautions – able to represent the entirety of the price range of all the equity exchanges I regularly deal with).
Another option is, if you know the range of DP used by the exchanges in question, to use fixed-point and a normal int or long. To take an example I know well, Xetra (the German electronic exchange) currently has at most 3 decimal places. Using 3dp, you can represent prices up to 2,147,483.647 with a normal int. Fine for an individual price, no good for representing the total of a day’s trading.
It’s all a question of what data you’re receiving, what the precision of that data is and how you’re processing it.