76 points · by is0tope · 5y ago · 53 comments
Online brokers have been doing this forever. TD Ameritrade is by far the worst offender in this regard, way worse than Robinhood.
Using average price and floating point imprecision are two separate, unrelated issues. You don't have to, and probably shouldn't use floating point to calculate the average price, and it's perfectly possible to use decimal arithmetic or fractions rather than floating point.
The real issue here is that 2/3 does not have a decimal representation, not floating point imprecision. No matter what you do, if you need to express it as a decimal of finite length it will need to be rounded, and that's where the imprecision is. In practice, you can generally get away with using floats because the floating point error ends up being less than the rounding imprecision.
I'm trying to get what floating point is really good or necessary for, then. Would it be something like "huge or tiny scale, generally theoretical, scientific things?"
You only start to see errors after a while, and it is likely good enough for the calculations being done. For something like money, you need to be very exact since 0.123541234123 cents is not a real value. Every trade you might "lose some cents" eg 0.00000001 or something like that. Over billions of transactions that starts to build up, and you start to either create or lose money arbitrarily.
In finance, if you are keeping track of money you want to use integer values where at all possible.
The proposed solution is to never mess with division in the first place when computing P&L; operate on "total" values: cost basis, total profit, ....
Edit: and as a super minor point of contention, I don't think it's wrong to call it a technical difficulty. You can represent the involved quantities exactly with a decimal ratio type, and the existence of a technical solution indicates that the problem is at least somewhat technical in nature.
Thanks
Edit: Nevermind, I forgot this is for REALIZED gains. I feel like what I wrote above would only make sense if the entire position was closed flat. Ultimately I was trying to figure out the difference between summing the cost column (which seems to be profit/loss depending on sign?) vs matching trades with FIFO/LIFO but I have a hunch it has to do with realized vs unrealized gains.
You always end up making the same amount of money, but when you need to figure out profit, it is hard to do before you have sold all of your stock! These systems provide different ways of answering the question: "What is my profit _so far_?). Summing up all of the costs will give you the cost so far, but if you are half way through selling all of your items, it is not that useful, as you have no way of telling if you are making a profit or not on your sales!
FIFO vs LIFO can matter depending on what you are trying to "show". I am not an accountant, but imagine if you bought a bunch of stock really cheap in the first half of the year, and in the second half bought a bunch more stock at a higher price. If you use FIFO, you will realise a big profit initially, followed by a smaller profit or loss in the second half when you start to use up your more expensive stock. With FIFO, you do the opposite (big loss up front), and with Average Cost it's more spread out.
If you have mid year report coming up, and you want to look good, you might be tempted to use FIFO, in order to show that you made a higher profit initially. I'm guessing real accountants see right through this though!
I really wonder here, in this part of "Introduction to Limit Orders", how they handle race conditions. Do you think they use a synchronous queue that queues orders while it's transacting, or do they try to also handle inserting orders during the process of filling orders?
I went down the rabbit hole learning a lot of this stuff about 1/2 a year ago and good information is quite challenging to find, it's all hyper dumbed down or hyper generalized and vague (investopedia).
Brokers (in traditional finance) are regulated, audited, and also are often subject to insurance policies in case they went bankrupt, or similar. If you are dealing with a large and reputable institution, you are unlikely to gain any benefit by assigning the shares to yourself I would suspect. Someone please correct me if I am missing something though.
It's called the law.
> Well, it would be stupid to trust the broker. [..] I currently manage it by simply having accounts with several[...]
If you believe it's "stupid" to trust brokers, spreading your exposure across several of them may protect against a complete loss. But it also increases the risk of some loss and, on balance, has exactly the same expected value. The law diminishing marginal utility may put your strategy slightly ahead, but the difference is similarly marginal.
SIPC insurance is supposed to protect you in case they run away anyway.
What protects a bank from running away with your cash?