Quant500 Academy

6. Reinforcement learning: agent, environment and reward

Level 10: Machine Learning Applied to Trading

Reinforcement learning is influenced by behavioral psychology and its reward system. We can think of it as playing with a dog. We have a dog (which in the terminology is called the agent) and we have a park (the environment) where it can do whatever it likes. Every time the dog brings you a stick, you reward it with food. After a while, the dog starts developing better strategies for finding other sticks nearby. That is, it learns from the reward system. That process inside the dog's head is what we call reinforcement learning. We have an agent, an environment and a reward.

The difference from supervised learning lies in the output data. In reinforcement learning, while the dog is wandering around, it does not know whether it will get a reward or not. It may never get one. But when it finds one, it has learned how to win. So the output data can arrive much later. In supervised learning, by contrast, we know the output in advance and make predictions while looking at it.

That delayed credit assignment is what makes reinforcement different and hard. If the dog ran twelve laps, sniffed three bushes and then found the stick, which of those actions deserves the credit? The algorithm has to spread a scarce, delayed reward across a long chain of decisions.

In trading the analogy is direct, and that is why reinforcement generates so much interest:

There are three practical consequences worth internalizing before you touch a single line of code.

First: the reward is delayed and noisy. An excellent purchase can be down for three days and up six weeks later. The agent has to learn that a good action does not always bring an immediate reward; that is exactly the dog's problem.

Second: the exploration versus exploitation dilemma. If the agent only repeats what has already worked, it will never discover a better strategy. If it explores too much, it burns money experimenting. In a park, exploring is free. In a market, exploring costs commissions and real losses.

Third, and most important: the market is not a park. The dog's environment is stable; the market changes regime, and other participants react to what you do. An agent trained on a historical record can memorize the specific path of those years instead of learning a robust policy. Overfitting, in reinforcement learning, is especially insidious, because the agent also chooses which data it sees when it chooses its actions.

In short: supervised is learning from a teacher who already has the answers; unsupervised is looking for structure without answers; reinforcement is learning by acting, on the back of rewards that arrive late, badly and sometimes never.

The rest of Quant500

What you are learning, applied to the index every day:

The model portfolio, weekly in your inbox

Every Saturday, its week in one minute: how it went, the best and the worst, and which insiders bought with their own money. Plus, the day the model is rebuilt, which stocks come in and which go out. A simulation, not advice. At most one email a week, no ads, no account; one-click unsubscribe. Made by one person: Pol Gracia.

A model portfolio with simulated results, not a personalized recommendation. Your email is used for this only: privacy.

Behind the Academy and the rest of Quant500 there is one person: Pol Gracia Serrahima.