For most people, using these brokers will be something that they will be quite familiar with, even though the actual trading of their shares will happen somewhere in the background. Brokers in fact do not always have to go to an exchange directly, and many will route (send) client orders to various third parties such as market makers or other brokers. This was made quite apparent in 2020 when it was noticed that the broker RobinHood was selling client order flow (client orders) to the hedge fund Citadel.
Online brokers have been doing this forever. TD Ameritrade is by far the worst offender in this regard, way worse than Robinhood.
Yes, brokerages have all been doing this for a while, but while TD Ameritrade pays more overall than Robinhood, does it also do more trades (not in terms of number of trades, but dollar value)? Without that info, it's hard to tell who's worse.
> Notice that this method is a lot simpler than the other two, but because you have to use average price, you are exposed to floating point imprecision which is a lack of accuracy that computers have when computing decimals.
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.
You are absolutely correct, and in general no-one should use floating point for any monetary values. I was trying to keep it as simple as possible without going into the nuances of float vs decimal. I might rephrase it to just "precision" in general, and skip the floating point part. Thank you for pointing this out.
Floating point is fine for monetary values where you are not performing accounting calculations. Most front-office finance applications work just fine using floating point, there's not much point trying to calculate compound interest, price an option or bootstrap a yield curve using anything but floating point.
This makes intuitive sense, but I still can't quite wrap my head around this idea of "no floating point for monetary values?," or actually, the opposite.
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?"
Floating point is good enough when you need to display something, and also for certain scientific calculations where high precision is necessary.
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.
Most decimal numbers cannot be represented exactly by floating point, so there is error in decimal to floating point conversion. You can see how this conversion works using this calculator: https://www.h-schmidt.net/FloatConverter/IEEE754.html
Most real numbers cannot be presented exactly, including most decimals and some larger (positive) integers.
The smallest such integer in single-precision floating point is 16777217. This number cannot be represented exactly: the next floating point number after 16777216 is 16777218. Above that number you can no longer represent whole numbers.
Even at one decimal place of precision most numbers cannot be represented exactly. For example, 0.1, 0.2, 0.3 and 0.4 cannot and 0.5 is the first positive number that can be.
At two decimal places, there are virtually no numbers that can be represented exactly (0.25 is the first one that can be), so there's always some error and therefore the possibility of rounding errors. Even if you accept that, after 131072.01, some numbers cannot be represented exactly at all even with rounding: 131072 can be represented exactly, but the next number is 131072.015625 which rounds to 131072.02. No single-precision floating point numbers round to 131072.01.
Of course I'm using single-precision floating point here. These same problems exist for double-precision but at much larger numbers: the first integer that cannot be represented in double-precision is 9007199254740993. Either way, using floating point exposes you to the risk of errors in your calculations.
As mentioned, it's when you must make sure that you have perfect precision. Money and counting items is one such example. If I am a bank and get audited, if I have a transaction that has kept rounding up, and creating eg. 1 cent every time. After 10k transactions I will have "created" $100 from nowhere. The auditing firm will not be happy about this.
Floating point is ideal for scientific applications, where the numbers are measurements/observations/approximations that have a margin of error built into them anyway, which is likely to be much larger than any additional imprecision introduced by floating point use.
Given that the average is just a means to an end (total P&L), why would they not simply rescale by total shares to make that technical difficulty go away?
Sorry, I probably wasn't clear enough --- the only reason there exists an arithmetical difficulty in the first place is because we're materializing an intermediate value we don't really care about with any kind of precision and using it to compute a value which needs perfect precision.
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.
Let's say you buy three shares at prices of $5, $5 and $10. You paid a total of $20 for the three shares.
Now you sell 2 of them for $20 each ($40 in total), and have 1 share remaining. You want to calculate realized P&L using the average cost method. The average cost per share is $20/3, so the P&L is $40-(20/3).
So quick question: is it correct to assume that FIFO/LIFO doesn't matter if you want to get your overall profit (sum the cost column which consists of side x quantity x price for each trade)? In other words, FIFO/LIFO only applies when trying to find the profit of a single trade, but as a whole it doesn't matter? Or is that incorrect.
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.
So all of these methods converge when the position is fully closed out. They are actually designed mostly for regular businesses that are buying and selling items, but it works for anything.
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!
So basically to simplify all this (more for myself), looking at total cost column tells you all costs and all "revenue" (money received), but considering you're only partially selling your inventory the total summed cost column is skewed if you thought of it as profit, as it includes unsold inventory, and that's why you must use an inventory method such that you match exact quantity for buys and sells. Makes sense!
Ooooh, great point. Thank you, that makes perfect sense.
So that's an interesting point that I never actually realized (pun intended 1000%)... is that FIFO/LIFO doesn't actually change your profit amount when the position is fully closed, it only matters, as you said, when "showing" that profit, ie... if you are trading over multiple years and you need to do your taxes, the tax years up front might show more profit, but less in later years, or vice versa, but over all the years the profit would be the same. That's obvious in retrospect, and I can't believe I didn't get that before. Thanks!
I feel like I should point out here that there is also SpecID (Specific Share Identification), which is another way of identifying which of your inventory/lots you want to sell.
SpecID can come in very useful if you want to maximize control of the amount of capital gain/loss that you take on when partially selling your position after dollar cost averaging or otherwise buying into it over many purchases.
For example, assume you've been dollar cost averaging into a security over the course of 5 years, and now want to start selling. You can use SpecID to sell only the specific lots that you bought between 1 and 2 years ago, so that you get taxed at long term gain rates, but otherwise realize the least amount of gains of all your lots (assuming the security has been appreciating at a stable rate). Neither FIFO nor LIFO would allow you to do that: FIFO would grab the oldest, most appreciated lots, while LIFO would grab the lots that have not yet aged into LT gain.
That's so funny you mentioned this because I asked one time on a forum if something like that were possible and got absolutely roasted for "such a stupid question"... I'm super glad my thinking was on the right track. Thanks for the explanation. What brokers allow you to do that, btw?
Thanks for pointing this out. As mentioned I am not an accountant, but the specific stock method did come up also. I decided to skip it in the interest of brevity (article was already getting way too big). However this is an interesting insight, thank you.
> By definition, this order must be the top of the book, because it’s price already had to be aggressive, and there could be no other bids above us. Therefore, the new best bid increases from $99 to $102, since that is the limit price of our order.
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?
Order books will almost always be single threaded or something similar. Only one order action is allowed at a time in each book, otherwise it would be chaos. Exchanges are very strict on "fairness" since if there is a (legal) edge to be had, you can bet that someone will find it and try and exploit it. That's just the game.
I just sent your article to a lot of different people trying to learn. You have a natural gift for teaching, I'd highly recommend you keep making posts.
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).
I work in a vanilla MM space and have had limited exposure to systems/technical side in the crypto space, would love to see the weird/cute crypto-specific problems that exist.
For instance I was surprised to learn the other day that FPGAs are becoming standardized in the crypto space now as well, since to my knowledge network bottlenecks are more difficult to be precise about due to the common usage of websockets, the non-standardized colocation services offered, etc. But what crypto MMs are using FPGAs for, is to do actual JSON (maybe it's FIX by now?) parsing since that became a common bottleneck due to the lack of binary protocols from crypto exchanges.
That's very interesting! I myself have not worked as a MM before so I don't know much about it. I can imagine it is possible since these days there is a lot of cross pollination between traditional finance and crypto. Most exchanges will do Json, though I know of several who have FIX interfaces also.
Honestly I think the hardest thing to date that is nearly impossible to find information on is how a market maker actually works. I've googled for hours before only to get very vague definitions, nothing concrete with actual examples/formulas.
Thank you, i will put "how market making works" on my list. Obviously that is a very detailed subject, but I think the basics can be covered pretty easily.
I agree, I'm sure it is wildly complicated, but something more than "market makers provide liquidity!!!" would do wonders. Something on par with the detail of your existing 2 posts would be 10/10...
Here's my understanding, starting with some background terminology:
Everything that's tradable on an exchange (an "instrument") has a bid/ask spread that represents the highest price someone's willing to pay to buy (the bid), and the lowest price that someone's willing to pay to sell (the ask). There is _always_ a bid/ask spread, because as soon as anyone places an order that would reduce the spread to zero, that means they're willing to pay what someone's asking, or vice-versa, and therefore the exchange immediately converts it into a trade--done deal!--and now there's a spread again. Incidentally, executing a trade this way is "crossing the spread", you're opting to "pay the difference" between the bid and ask to get your trade done.
Someone that crosses the spread is said to be "taking liquidity." They're willing to pay the surcharge of the bid/ask spread to get their trade executed right now. On the other hand, someone that sits at the bid/ask spread, waiting for someone to cross to execute, is said to be "offering liquidity," they're willing to patiently wait in order to save money equal to the spread.
Now, a market maker is a participant that is _solely_ interested in making money off that bid/ask spread, basically like a sports bookie. They're willing to always be in the market, on both sides, and take the spread whenever someone crosses over. So if say AMZN is trading at 3332.95 x 3333.05, they'll be offering to buy at 3332.95, and sell at 3333.05, and any time people take those offers, they make a dime. Do this thousands of times a day, on many different instruments, and you've got a business. That said, there's real risks in market making, and understanding them requires the idea of "informed" versus "uninformed" trading.
An uninformed trader comes to the market simply because they want to trade for some external goal unrelated to trading. Maybe they're selling stock for a house downpayment, or buying agricultural futures because they make potato chips and don't want to deal with the price shocks of a sudden drought. They're willing to cross the spread, and they don't particularly care if they lose a few pennies on the transaction, because that's not their goal. These traders are the meat and potatoes for market makers, because they don't move the fundamental price of the instrument, they're effectively noise. In a market of nothing but uninformed traders, you would expect your position as a market maker to fluctuate around zero, because you're buying roughly as much as you're selling.
An informed trader, on the other hand, "knows something". They're aware of some material fact (or at least a strong hypothesis) that indicates the price of the instrument is going to move dramatically in the near future. They're willing to cross the spread, because they know the spread is going to move with them anyway. These are danger for market makers, because they will all pile in on one side of the trade, all buying, or all selling, and now the market maker will end up in a losing position--short when the price is going up, or long when the price is going down.
Imagine running a Gamestop store: on a normal day, you might see half your customers buying a PS4 and half selling a PS4, but on the day that the PS5 is announced, suddenly everyone wants to sell their PS4 at the same time before you lower what you're offering.
The classic market maker algorithm looks at "inventory", basically your absolute outstanding position, and tries to keep inventory as low as possible. When uninformed trading is taking place, your inventory is around zero, and you can stay very close to the minimum spread. As your inventory grows, and you become either increasingly more long or short, you start pulling your bids or asks away from the best bid/ask to try and bias future trades back into a 50/50 ratio. All market makers doing this simultaneously means the bid/ask spread starts to widen as there's increased uncertainty about the price.
Another key element to market making comes down to trade volumes. You could, today, start market making, all you need to do is put in limit orders at the bid and ask and wait. However, you'd probably not make that much, because you're losing money to various trading commissions, exchange fees, roundtrip network latency, etc. Professional market makers make tens of thousands of automated trades in a day, and as a result, are able to negotiate substantially lower costs that make it worth doing. Many exchanges even have "designated market makers" that have special trading permissions in exchange for guaranteeing that they will _always_ provide some best bid/ask offer even in the worst case conditions, otherwise you in a sufficiently large event you could get a "liquidity crisis" (i.e. there's no one willing to buy or sell that instrument at any price).
That ended up being more text than I thought it would--apologies.
> Now, a market maker is a participant that is _solely_ interested in making money off that bid/ask spread, basically like a sports bookie. They're willing to always be in the market, on both sides, and take the spread whenever someone crosses over. So if say AMZN is trading at 3332.95 x 3333.05, they'll be offering to buy at 3332.95, and sell at 3333.05,
I guess my question is, how is that different, what they're doing, vs someone crossing over but the money goes directly to the other party? I notice you said the market maker is listing the same prices, I'm trying to visualize how their action is any different than the exact same spread/scenario but the buyer crosses over to the seller and the same trade happens. What is actually different?
> you start pulling your bids or asks away from the best bid/ask to try and bias future trades back into a 50/50 ratio
Also are you saying that the market maker dictates the bid ask spread and not the highest bidder/lowest seller
They are the other party--a market maker isn't (outside of the "designated market makers" I referenced earlier) a special participant in trading, they're just like you or me.
If I put a limit order in to buy at 3332.95, and someone takes it, I now have one stock. If I put in a limit order to sell at 3333.05, I sell that stock and make a dime. In aggregate, if I'm doing that many many times, and the price stays roughly around 3333, I'm making a dime on every round trip.
A "market maker" just means that I don't really care about investing or speculating, all I'm really in for is to collect that dime on the round-trip and sit at the bid/ask spread.
> Also are you saying that the market maker dictates the bid ask spread and not the highest bidder/lowest seller
No, as you've said, the highest bidder/lowest seller set the bid/ask spread. It's just, in any high volume market, chances are the incidental traders that want to improve the best offer clear very quickly--at any given point the market is probably going to clear until you hit the market makers. By definition, they're the folks willing to wait it out.
That said, market makers can compete with each other--if you are more ambitious than your competition, you might be willing to improve (narrow the spread) on your competitors. You'll make money by filling trades that they will miss out, but on the other hand, you're getting less spread and less profit per-trade. If that lower profit doesn't cover the statistical risk of losses from price movements, then you won't be profitable. The bid/ask spread narrows or widens based on the interactions of all market participants, just, if a particular instrument looks very risky, the market makers, acting as backstops, might want more money in the form of spread to warrant trading.
In practice, the most liquid instrument in the market these days trade pretty close to the minimum spread all of the time--high-frequency market makers are very efficient and so you rarely have to pay more than a penny to cross the spread. As a result, it's also not terribly profitable to make markets, since you're only earning a penny per round-trip for the risk you have to take.
(Compared to say, real estate, where the "bid/ask spread" is basically unknown and has to be discovered through the very expensive agent mechanism.)
Really detailed explanation! This is essentially it. While there's obviously a bunch more complexity, the essence of market making is just trying not to own a stock, but just buy and sell immediately.
Think about how when you go on holiday and want to change money. Admittedly it's becoming more online now, but when you go to a foreign exchange shop they will have a "we buy" and "we sell" price. They are essentially a market maker. They don't care about having a load of pounds, or dollars or rupees. They just want to buy low and sell high to you, and make the difference!
Question: suppose i bought some security through a broker, and 2 business days have passed. How can i independently (of broker) check that it is indeed now in my name?
Good question. I am actually not super familiar with it, but in general your shares are owned under the name of the broker (called "street name"). That broker will then deal with portioning out dividends etc. I believe you can request to have personal ownership assigned, but this is expensive from what I have read. Unless you don't trust your broker (why are you using them?) it is unlikely to matter to an individual investor. You still have the legal right to the shares.
Well, it would be stupid to trust the broker. What technically prevents them to run away with all stocks?
I currently manage it by simply having accounts with several to avoid putting all eggs in one basket. But this is hardly a solution.
That is where your personal judgement comes in of course, but it would be hard for them to "run away with the stocks". These are not physical certificates, but just registrations in a central organisation.
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.
What prevents them is custody. Funds, brokers, etc. are all required to use custody providers to keep track of assets and handle the actual transfer of assets.
> What technically prevents them to run away with all stocks?
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.
Online brokers have been doing this forever. TD Ameritrade is by far the worst offender in this regard, way worse than Robinhood.