Supervised machine learning is a fortune-teller. You hand it a feature vector, it hands back a number — tomorrow’s return, the probability of a fill, next hour’s volatility — and then it shrugs and goes home. It never tells you how much to buy, when to stop, or what to do once the order you just placed has moved the very price you were trying to predict. Forecasting is a one-shot answer to a question nobody actually asked. Trading is a sequence of decisions unfolding in time, each one changing the board you play the next one on.
Reinforcement learning (RL) is the discipline built for exactly that shape: an agent takes actions, the world answers with a reward and a new situation, and the agent learns a rule — a policy — that maximizes reward over the long run, not just the next tick. That long-run framing is also where our recurring villain returns. Across the machine-learning course the enemy was overfitting: a model that memorized noise and called it signal. It is still the enemy here — only now it wears a craftier disguise, because an RL agent gets to choose its own training experience, and a backtest that looks like free money is usually an agent that has overfit a simulator nobody should have trusted.
Before you read — take a guess
Your model nails next-day return with an out-of-sample R² that makes the desk jealous. Why is that, on its own, still not enough to trade?
The vocabulary of sequential decisions
RL has a small, precise vocabulary, and almost every confusion in the field comes from blurring two of these terms together. Define them once, carefully, and the rest of the course is just engineering.
- State — everything the agent observes at time that is relevant to its decision. In trading: current price, your inventory (position), recent returns, order-book imbalance, time-of-day, remaining order to execute.
- Action — what the agent does. Buy/hold/sell, a target position, a quoted bid–ask pair, or how many child orders to release this minute.
- Reward — the scalar feedback after acting. Often a risk-adjusted, cost-inclusive P&L increment — and designing it correctly is so dangerous it gets its own lesson next.
- Transition / dynamics — the rule of the world: the probability of landing in the next state given the current state and action. In markets this is the price process plus the impact of your own trade. You almost never know it; you sample from it.
- Policy — the agent’s strategy: a (possibly randomized) mapping from states to actions. This is the object you are actually learning.
- Trajectory / episode — one full play-through: A trading episode might be one day, or the lifetime of unwinding one parent order.
- Return — the cumulative (discounted) reward from time onward. The thing the agent maximizes. Not a price forecast — an ugly coincidence of vocabulary we will be very careful about.
| RL term | Symbol | Trading interpretation |
|---|---|---|
| State | Price, inventory, recent returns, book imbalance, time left | |
| Action | Buy / hold / sell, target position, quotes, child-order size | |
| Reward | Risk-adjusted P&L this step, net of costs and impact | |
| Transition | Price dynamics plus your trade’s market impact | |
| Policy | The trading strategy you’re learning | |
| Episode | — | One day, or one full order unwind |
| Return | Cumulative discounted future reward (the objective) |
The two 'returns' trap
In finance, “return” means a percentage price change. In RL, “return” means cumulative future reward. They are unrelated. When this course writes it always means the RL one. When it means a price change, it says so in words.
Slot each idea into its RL term.
Pick the right option for each blank, then check.
The strategy you are learning — a mapping from situations to moves — is the . The rule of the world that says where you land next is the . The scalar feedback you get for acting is the .
A market is a Markov decision process
Stack those pieces together and you have a Markov decision process (MDP) — the formal object RL studies. Mechanically it’s a loop: the agent observes the state, its policy picks an action, the environment returns a reward and the next state, and around it goes, forever.
- Step
- 0
- State (price, inv)
- 100.0, 0
- Last reward
- +0.00
- Episode return
- +0.00
One loop = one decision. The agent reads the state, its policy picks an action, the market returns a reward and a new state — forever. Flip on Market impact and the agent’s own trades push the price against it, shrinking every reward: in trading, unlike a video game, the action moves the environment. That feedback is exactly what supervised learning cannot capture.
The “Markov” in MDP is a promise about the state. A process has the Markov property when the next state depends only on the current state and action — not on the entire history of how you got here:
This is not a law of nature; it is a design constraint on what you put in your state. If “last traded price” doesn’t summarize everything relevant — and in markets it never does — then the price alone is not Markov, and an agent that conditions only on it is flying blind. The fix is not to bolt on memory of the past; it is to enrich the state until it is sufficient: add your inventory (so the agent knows its own exposure), recent returns (momentum/mean-reversion context), and order-book features (imbalance, depth, spread). A well-engineered state makes the Markov property true enough to be useful.
The token only ever looks at where it is now — never where it has been — to decide its next hop. That is the Markov property. Yet keep stepping and the share of time spent in each regime settles toward a fixed long-run mix: the stationary distribution.
The chain above shows the same idea on regimes: the token decides its next hop using only where it is now, yet the long-run share of time in each regime settles to a fixed mix. Memoryless transitions, stable statistics — that is the Markov property earning its keep.
Worked example — a tiny 2-state trading MDP
Picture a toy market with two regimes as the relevant state: Calm and Volatile. Each step the agent picks a position size, but first the world transitions. From Calm, the dynamics are:
Suppose your policy in Calm goes long, and the reward (P&L increment) is if you stay in Calm and if you tip into Volatile while still long. The expected one-step reward of being long in Calm is
Notice what made that number: the transition probabilities, not a forecast of price. The agent isn’t predicting the next return — it’s weighing actions against the dynamics of the world, which is exactly what an MDP forces you to do.
In the toy MDP above, you decide the agent should also know its current inventory before choosing a size. Why?
The return and the discount factor γ
The agent doesn’t maximize the next reward — it maximizes the return, the cumulative discounted reward from now on:
The discount factor decides how far the agent looks ahead. At the agent is purely myopic — it cares only about and would happily blow up next step for a penny now. As it becomes far-sighted, treating a reward ten steps out almost like a reward today. Discounting also keeps the infinite sum finite and encodes a preference for sooner-rather-than-later profit.
Worked example — discounting a reward stream
Take a short episode with rewards and a discount of . The return from is:
Compute the weights: and . So
Now redo it myopically with : flat — the agent never even sees the shock or the recovery. Same reward stream, completely different sense of “good,” set entirely by one knob.
If far-sightedness is better, why not just set γ = 1?
Answer. Two reasons. Mathematically, with an infinite horizon can make diverge, so the objective stops being well-defined. Practically, markets are non-stationary — a reward 500 steps out is forecast through a world that will have changed — so weighting the far future as heavily as the present invites the agent to optimize a fantasy. A discount slightly below 1 (say 0.99) buys far-sightedness without betting the policy on a distant, unknowable future.
Reward design is a whole lesson
We’ve quietly assumed the reward is handed to us. It isn’t — turning “make money carefully” into a single scalar is the hardest, most dangerous step in applied RL, and it’s the entire subject of lesson 2.
Prediction vs control — the deep difference
Here is the chasm between the previous course and this one. Supervised learning is prediction; RL is control.
In prediction, your data is (roughly) i.i.d., you estimate a fixed mapping to a label that exists independently of you, and — crucially — your prediction does not change the world. Guessing tomorrow’s rain doesn’t alter the weather. The label was going to be whatever it was going to be.
In control, you choose actions, and those actions change which states you visit next — they change the future data distribution your agent will learn from. In markets this is not a metaphor: a large buy moves the price (market impact), consumes liquidity, and shifts the order book the next decision is conditioned on. The environment is not a passive label generator; it’s a counterparty that reacts to you.
| Supervised learning (prediction) | Reinforcement learning (control) | |
|---|---|---|
| Data | (roughly) i.i.d., fixed distribution | Generated by your own actions; distribution shifts |
| Output | A prediction of a fixed label | A policy choosing actions over time |
| Objective | Match a label (loss vs. truth) | Maximize cumulative discounted return |
| Feedback | The label exists regardless of you | Your action changes the next state |
| In markets | Forecast a return; market ignores you | You trade; the market moves because of you |
| Failure mode | Overfit static noise | Overfit a simulator you chose to live in |
Flip on “Market impact” in the loop island above and you can watch this directly: the agent’s own trades push the price against it, shrinking every subsequent reward. That feedback — your action moves the environment — is the one feature a video game and a market share and a forecasting model can never represent.
Pitfall — sizing is not classification
A tempting shortcut: train a classifier on {buy, hold, sell} labels and call the argmax your “policy.” It looks like RL; it isn’t. A classifier optimizes per-example accuracy against a fixed label, assuming your choice doesn’t change anything. But position size, timing, and the impact of your fill are sequential, self-affecting decisions with no ground-truth label to copy. Treating control as classification throws away the exact thing — the feedback loop — that made you reach for RL in the first place.
Match each statement to the paradigm it describes.
Pick a term, then click its definition.
The policy and the value function — a preview
The policy is the whole game: a (possibly stochastic) rule that, given a state, hands you an action — or a probability distribution over actions, so the agent can explore rather than always exploiting its current best guess. Everything in this course is, ultimately, a method for finding a good .
But how do you know a policy is good without playing infinitely many episodes? You estimate value. The state-value is the expected return from state if you follow policy forever after; the action-value is the expected return from taking action in state and following thereafter. These two functions are the load-bearing beams of nearly every RL algorithm — they let you compare actions without enumerating the future — and lesson 3 builds them properly.
Checkpoint — the MDP frame
An agent uses γ = 0.95 and receives rewards r₀ = 4, r₁ = 10. What is the contribution of r₁ to the return G₀?
Check your answer to continue.
Recap
Big picture
Markets as an MDP
- Markets as an MDP
- The five pieces
- State s — what you observe
- Action a — what you do
- Reward r — scalar feedback
- Transition P — rule of the world
- Policy π(a|s) — your strategy
- Markov property
- Next state depends only on now
- Enrich state until sufficient
- Add inventory, returns, book features
- Return and γ
- G = Σ γᵏ r
- γ → 0 myopic
- γ → 1 far-sighted
- Prediction vs control
- Prediction: output ignores world
- Control: action changes future states
- Markets: your trade moves the price
- Coming next
- V(s) and Q(s,a) — lesson 3
- Reward design — lesson 2
- The five pieces
You now speak MDP: you can frame a trading problem as states, actions, rewards, transitions and a policy, you know why a price-only state is rarely Markov, and you can see the one feature — your action moves the environment — that makes this control rather than forecasting. But notice how much we leaned on the reward simply existing. Next, in Reward Design & Its Pitfalls, we put the whole weight of the agent on that single scalar — and watch what happens when “make money carefully” is even slightly mistranslated into math. It’s where most RL trading projects quietly die, and where our old villain, overfitting, finds its craftiest disguise yet: an agent that hacks the reward you wrote instead of the goal you meant.