Every price you have ever clicked was placed there by a machine solving an equation you have never seen
Lets dive into it
When you click buy, you think you are taking a price off the market. You are not. You are accepting an offer that a machine calculated to the cent, microseconds before your cursor even moved
That offer was not your fair value. It was not the company's fair value. It was the optimal price for the machine on the other side, given everything it was already holding and everything it was afraid of.
Most traders believe the market maker is their opponent. It is not. The market maker does not care which direction the stock goes. It does not have an opinion on the company
It is not betting against you
It is solving a completely different problem than the one you think you are playing, and the price you see is the output of that problem, not yours.
The market maker has exactly two enemies. The first is getting picked off by someone who knows more than it does. The second is its own inventory piling up on the wrong side right before the price moves. Every quote it posts, on every instrument, on every exchange, is the mathematical answer to balancing those two fears at once
In 2008, two researchers wrote down the cleanest version of that answer. Marco Avellaneda, a mathematician at NYU's Courant Institute, and Sasha Stoikov published a paper called High-Frequency Trading in a Limit Order Book. It is one of the most quietly influential papers in modern trading, and almost no retail trader has ever read it
It takes the entire job of a market maker and collapses it into two numbers. Get those two numbers right and you make money on the spread for decades. Get them wrong and the market hands your inventory back to you at the worst possible moment until you are gone.
This article is those two numbers
Where they come from, what they actually mean, and why understanding them changes how you read every single quote on your screen
Chapter 1 - The Problem Nobody Explains To Retail Traders
To understand the two numbers, you first have to understand the job. The job of a market maker is not to predict price. The job is to quote a bid and an ask at the same time, buy from sellers, sell to buyers, and pocket the difference, while surviving the two ways that game kills you.
The first killer is adverse selection
This was formalized in 1985 by Lawrence Glosten and Paul Milgrom. Their insight was brutal. Some of the people hitting your quote know something you do not. When an informed trader buys from you, the price is about to go up, and you just sold low. When an informed trader sells to you, the price is about to go down, and you just bought high
You cannot tell the informed traders from the noise traders in the moment. All you see is order flow. So every quote you post is exposed to the possibility that the person taking it is smarter than you, and the wider the gap between price and true value, the more aggressive those informed players become
Chapter 2 - The Two Numbers
Start with the setup, because the assumptions are the whole game. The mid-price moves as a driftless random walk. The market maker is risk averse, with a risk aversion parameter γ (gamma)
The asset has volatility σ (sigma). There is a time horizon T, and the clock runs down toward it. The maker currently holds an inventory of q units
And orders arrive at the maker's quotes with an intensity that falls off the further the quote sits from the mid-price, controlled by a liquidity parameter k. Hold those symbols in your head: γ, σ, T minus t, q, and k. Every number that follows is built out of them.
Number one is the reservation price.
This is the single most important idea in the entire model, and it is the one retail traders have never heard of. The reservation price is not the mid-price. It is the market maker's private fair value, adjusted for the inventory it is currently stuck holding. It is the price at which the maker would be genuinely indifferent between holding what it has and giving one unit away
Read what this equation actually does. Start at the mid-price s. Then shift it by the inventory term. If the maker is long inventory, q is positive, so the reservation price drops below the mid
The maker has quietly decided its personal fair value is lower than the market's, because it is desperate to sell down its position, so it skews both its quotes lower to attract buyers and discourage more sellers. If the maker is short, q is negative, the reservation price rises above the mid, and it skews everything upward to buy inventory back
The more volatile the asset and the more time left on the clock, the harder it skews, because both of those make a wrong-side inventory more dangerous to carry
This is why the price you see is almost never the true mid. It is skewed by inventory you cannot observe. When a market maker is loaded long and quietly leaning on the offer, you are not seeing fair value. You are seeing a machine trying to bleed off a position. That skew is the reservation price talking.
Number two is the optimal spread
The reservation price tells the maker where to center its quotes. The spread tells it how far to place the bid and the ask on either side of that center
Quote too tight and you get picked off by informed traders faster than you earn. Quote too wide and the order flow goes to a competitor and you earn nothing. There is one optimal width, and the model gives it to you in closed form
This number is two fears added together
The first term, gamma times variance times time remaining, is the risk premium. The more risk averse the maker, the more volatile the asset, and the more time left for something to go wrong, the wider it quotes to protect itself
The second term, two over gamma times the log of one plus gamma over k, is the competition premium. It depends on k, the liquidity and order-arrival intensity. In a deep, fast, competitive book where orders rain in, k is large and this term shrinks, so spreads compress toward zero. In a thin, illiquid name where fills are rare, the maker demands a much wider spread to make the risk worth taking.
Now put the two numbers together. The maker centers its quotes on the reservation price, not the mid. Then it places the bid half the optimal spread below that center, and the ask half the optimal spread above it
That is it. That is the entire job, distilled. A reservation price that quietly moves the center based on hidden inventory, and an optimal spread that sets the width based on risk and competition
Two numbers. Every bid and ask you have ever traded against was the output of some version of this calculation, whether the firm used this exact paper or a far more complex descendant of it.
This is the math that runs Citadel Securities, which makes billions a year market making and executes a huge share of all US retail equity orders
It is the logic underneath Jane Street, Virtu, and every other firm that quotes two-sided markets across millions of instruments at once
They are not predicting the stock. They are solving for r and the spread, faster and more accurately than anyone else, billions of times a day
Chapter 3 - How To Actually Use This As A Trader
You will never out-quote Citadel. That is not the point. The point is that once you understand the two numbers, you stop misreading the price on your screen, and you stop handing free money to the machine on the other side.
Step one: stop treating the quoted price as fair value.
The price you see is the reservation price plus half a spread, and the reservation price is skewed by inventory you cannot see
When the bid is unusually firm and the offer keeps refreshing slightly low, you are very likely looking at a maker that is loaded long and leaning to unload. That is information. The quote is not neutral. It is a position talking.
Step two: respect the spread as a signal of who has the edge
A structurally tight spread means a deep, competitive, fast book, which means k is large, which means you are in a game dominated by professionals quoting razor-thin. That is exactly the game where you are the noise being quoted around
A structurally wide spread means thin liquidity and high risk premium, which is where makers are nervous and where, occasionally, your slower and more patient edge can actually matter. Match your style to the book, not the other way around.
Step three: stop paying the spread when you do not have to
Every time you cross the spread with a market order, you are paying the maker its optimal width in full, and over thousands of trades that width is most of what separates you from breakeven
Sitting on the bid or the offer with a limit order flips you to the other side of the equation. You become the one earning the spread instead of the one paying it, at the cost of execution certainty. That trade-off is the entire retail-versus-maker relationship in one decision.
Step four: understand that volatility widens everyone's spread, including the price of your impatience
When σ spikes, the risk term in the optimal spread blows up, makers pull back, spreads gap, and the cost of crossing explodes exactly when you most want to panic-trade
The model tells you why slippage is worst in a crash. It is not a glitch. It is gamma times variance times time, doing precisely what it is supposed to do, transferring the cost of chaos onto whoever is desperate enough to cross.
If you want to go deeper, start with three sources:
High-Frequency Trading in a Limit Order Book by Avellaneda and Stoikov, the original 2008 paper, for the two numbers themselves.
Trading and Exchanges by Larry Harris, for how real market structure works around those numbers.
Algorithmic and High-Frequency Trading by Cartea, Jaimungal and Penalva, for the modern stochastic-control version that every quant desk builds on today.
Bookmark this and Read those and you will understand more about why prices sit where they sit than almost anyone clicking buy and sell next to you
Finally
The price on your screen is not fair value and it was never meant to be.
It is a reservation price, the market maker's private fair value skewed by inventory you cannot see, plus or minus half of an optimal spread set by risk, volatility, time, and competition.
The reservation price answers where to quote. The optimal spread answers how wide. Together they produce every bid and every ask you have ever traded against.
Adverse selection and inventory risk are the two enemies. The two numbers are the defense. And the firms that solve them fastest and cleanest extract a few cents from your impatience, billions of times a day, without ever once needing to know which way the stock will go.
So here is the question to sit with. The next time you click buy and the fill comes back instantly, ask yourself who priced that fill, what inventory they were carrying, and which of their two fears you just paid for.
Because someone solved for two numbers before you clicked
Conclusion
For anyone serious about algorithmic prediction market trading, the best starting points remain the official documentation, real-world trading experience, and open-source implementations such as the GitHub repository discussed in this article.
Further Reading:
Official Docs: https://docs.polymarket.com
GitHub Repository: https://github.com/Benjam1nCup/Polymarket-trading-bot-python-V2
Beginner Guide: https://medium.com/@benjamin.bigdev/how-to-build-a-polymarket-trading-bot-in-python-2026-deep-dive-guide-a1fa00059246
The future of prediction market automation belongs not to traders with the most indicators, but to those who build robust, measurable, and continuously improving systems.
💬 Get in Touch
If you have ideas, questions, or would like to collaborate or want these trading bots, don’t hesitate to reach out directly.
Feedback on your repo (based on your description & strategy)
Contact Info
Telegram
https://t.me/BenjaminCup
You can read more articles through these links. They provide additional guides, tutorials, and strategies on Medium and Dev.to.





Top comments (0)