Machine Learning for Trading: Supervised Models, Reinforcement Learning and LLMs
Machine learning for trading means training models on market data to score trades, size positions or choose actions. Supervised models predict a label such as next-day direction, reinforcement learning learns a policy by trial and error in a simulator, and LLMs read text. All three overfit easily, so out-of-sample testing matters more than the model.
What machine learning for trading means
Machine learning for trading means a model is fit to market data, then used to score a trade, to size it, or to choose an action. The fit is the part that sounds scientific. The score is the part that can be an accident of the sample you happened to feed it. Three families cover most of what people mean. Supervised models, reinforcement learning, and large language models. They fail in the same boring way: they look brilliant on the data they studied.
Supervised models predict a label such as next-day direction. You show the model examples. Each example has inputs and a label. The model learns a function from inputs to that label. Reinforcement learning learns a policy by trial and error in a simulator: actions, rewards, and a lot of chances to memorize the simulator. Large language models read text. They can summarize a filing or a headline. They are not a supervised price model unless someone builds that second system around them.
All three overfit easily. Out-of-sample testing matters more than the model. Out of sample means a stretch of data, or a stretch of text, that was not used to choose the rule. If you only ever score the model on the days it studied, you are grading a memory. Algorithmic trading is the rule the model is supposed to become. A rule you cannot write down is not yet a rule. It is a fit.
Supervised models
The label is the whole game. Next-day direction is a common label because it is easy to build and easy to overfit. A model that is right on the days you tuned is not a model that will be right on the next year. Features sneak in the future: a column that was only knowable after the close, a rank that used the whole sample, a target that was edited until the chart smiled. Backtesting with AI is the catalog of those leaks. The backtest demo is a place to rehearse a rule once you have frozen it.
Freeze the label, the features, and the cost before you look at the score. Put a round trip in the test. A direction label that ignores a 1.5% round trip will congratulate rules that lose money after fees. The worked example on this page is harsher and simpler. It ignores prices entirely and still produces a "winner." If coin flips can do that, a flexible model with a hundred knobs can do it faster.
Reinforcement learning
Reinforcement learning does not start with a label for each row. It starts with a reward. In a simulator the reward might be the change in account value. The policy tries actions, sees the reward, and updates. That is a real method. It is also a method that will exploit any bug in the simulator. If the simulator lets the policy see tomorrow's price, the policy will. If the simulator charges no fee, the policy will trade constantly. You then take that policy to a market that does charge fees, and the constant trading is a tax.
Trial and error needs a lot of trials. Markets do not hand you independent trials. One regime can dominate a decade of data. A policy that learned that decade has learned one weather system. Crypto paper trading is the honest next step after a simulator: the same rules, a live tape, no real size yet. If you skip it, you are trusting the simulator's bugs. Paper trading will not create an edge. It will show you whether the policy still acts when the tape is not the file it studied.
Large language models in the stack
An LLM reads text. That can be a filing, a headline, a chat log, or the rule you are trying to write. Useful jobs are summary, translation of a checklist into questions, and a first draft of code. Build a trading bot in Python is the coding page if the draft becomes a script. The script is then an algorithm, and it overfits like any other algorithm if you tune it on one path.
Do not ask the language model to be the label. "Will this be up tomorrow?" is a request for a confident sentence. The sentence can be fluent and still be a coin flip. AI trading agent harnesses is about wrapping a model in checks so the fluent sentence cannot send an order by itself. Agentic trading is the connection if a checked order is even something you want. The harness does not fix a bad label. It stops the label from clicking.
A fund-shaped pitch often stacks all three families and a staff. AI hedge fund describes that category. A stack of models is still a stack of fits. The out-of-sample question does not get easier because the stack is taller.
Worked example: 100 coin-flip rules
Assumed numbers for the math, not a quote and not a price call. Example, not a recommendation. The script below does not look at a market. It flips a fair coin. There are 100 rules. Each rule gets 50 flips. A "win" is a flip under 0.5. The seed is fixed, so you can run the same file and see the same lines. The point is the leaderboard, not the market.
import random
random.seed(7)
wins = []
for _rule in range(100):
wins.append(sum(1 for _ in range(50) if random.random() < 0.5))
avg = sum(wins) / len(wins) / 50 * 100
best = max(wins)
n60 = sum(1 for w in wins if w >= 30)
print(f"average win rate {avg:.1f}%")
print(f"best rule {best}/50 = {best / 50 * 100:.0f}%")
print(f"{n60} of 100 rules at 60% or better")
Run it and you get:
average win rate 51.0%
best rule 34/50 = 68%
12 of 100 rules at 60% or better
The average win rate is 51.0%, near the coin. The best rule is 34/50, which prints as 68%. Twelve of the 100 rules land at 60% or better. Nobody designed those twelve. They are the right-hand tail of luck. If you publish the best rule and hide the other 99, you have a strategy deck. If you then run that same rule on a fresh 50 flips, you should expect it to fall back toward the coin. That second run is the out-of-sample test. Skipping it is how a 68% print becomes a product.
Trading models add knobs the coin does not have. More knobs, more ways to land in the tail by accident. Fees mean the tail has to be far enough from the coin to pay the round trip, not merely far enough to look good in a notebook. A 68% print on 50 trades, with no fee and no second sample, is the screenshot. It is not the test.
How to test so the tail cannot fool you
Split the data before you choose the rule. Fit on one part. Touch the other part once. If you touch it, hate the result, and retune, you have used it up. The next split is the real holdout, and you only get that discipline if you write it down first. Put fees in both parts. A rule that only wins when the test is free is a rule that loses in the account.
Then paper trade. The live tape is a third sample the file did not contain. If the policy or the label falls apart there, believe the tape. Do not add a feature to explain the week. That feature is a new knob, and the script above is what knobs do. You set your agent's per-trade and daily spending limits and market-cap range; Moby blocks red-rated tokens. Limits are only as tight as you set them. Sells and exits skip the market-cap and safety checks, and tokens with no safety rating are not blocked. Turn on Ask before every trade and your AI asks you first. Moby does not hold or approve trades. One agent per user, with its own wallet. Agents trade Solana tokens only. The agent cannot withdraw, transfer or send funds. If a model is allowed to send orders, the caps are the part that is not a fit. The fit can be wrong. The cap should still be a number you chose while the model was silent.
Where Moby sits in this stack
Moby is not the model and not the simulator. It is the wallet, the orders, and the limits if you decide to trade Solana tokens at all. Swaps and agent market trades pay 0.75% with a $0.90 minimum per swap. Limit, take-profit, stop-loss and trailing orders pay a flat 0.75% with no minimum. Onchain fees apply too. A 0.75% swap fee (minimum $0.90 per swap), plus onchain fees. Fees on your agent's trades earn up to 10% cashback in USDC. It is not a discount on the swap fee. AI Trading and copy trading currently need an access pass in the app. Supported hosts: Codex, Claude Code (CLI), Gemini CLI (with a paid Gemini API key or enterprise access) and Grok CLI. ChatGPT: works on Business, Enterprise and Edu workspaces that allow custom MCP servers (web). Moby does not run a schedule for your agent; the schedule lives in your AI client. Your resting orders (limit, take profit, stop loss, trailing stop, DCA) keep working on Moby even when your app is closed. Download Moby for the app. A schedule that refits a model every hour lives in your AI client, and it is a good way to overfit faster. Resting orders you placed on purpose keep working when the app is closed. A refit does not need to. Most weeks the right output of the script's lesson is to trade less, not to crown rule number 34.
How to read a model claim
Ask four questions. What was the label or the reward? What did the model never see? Were fees in the number? How many other rules were tried and discarded? If the answer to the last question is "a lot" or "we are not sure," you are looking at the left side of a search, and the printed winner is the 68% line. If the answer to the fee question is "gross," subtract a round trip before you feel anything.
Then ask whether you could lose the whole sample to one regime. A year of one kind of market is one weather system, even if it contains thousands of rows. Rows are not independent trials. The coin in the script is kinder than a market, because each flip really is a new flip. If a strategy cannot survive a kinder test, it will not survive a meaner one. Keep the code. Throw away the leaderboard. Build the next test on data you have not opened yet, and do not open it until the rule is frozen.
Frequently asked questions
What is machine learning for trading?
It means fitting models to market data to score trades, size them, or choose actions. Supervised models predict a label such as next-day direction. Reinforcement learning learns a policy in a simulator. Large language models read text. All three can look skilled on the sample they studied.
How is reinforcement learning different from a supervised model?
A supervised model learns a label you already attached to each row. Reinforcement learning learns a policy from rewards in a simulator, by trial and error. It will exploit bugs in that simulator, including missing fees. A policy that trades constantly in a free simulator is a tax in a real account.
What do large language models do in a trading stack?
They read and draft. Summaries, checklists, and a first pass at code are real uses. A fluent answer to "will this be up tomorrow" is still a sentence. Do not treat it as a tested label. Wrap it so the sentence cannot send an order by itself.
Why do most trading backtests overfit?
Because the rule was chosen after seeing the same data used to praise it, and because flexible models have many knobs. The coin-flip script on this page makes 12 of 100 rules look like 60% or better with no market at all. Showing the best one and hiding the other 99 is the usual deck.
Can a lucky rule look skilled in a small sample?
Yes. With seed 7, the best of 100 coin-flip rules is 34/50, printed as 68%, and the average is only 51.0%. That best rule was not designed. A fresh sample should pull it back toward the coin. Publishing the winner and skipping the fresh sample is the mistake.
How should I test a model out of sample?
Split the data before you pick the rule. Touch the holdout once. Put fees in both parts. Then paper trade on a live tape the file did not contain. If you retune after seeing the holdout, you have used it up. Write the split down first.
Does a machine learning model remove risk?
No. A fit can be wrong, a simulator can be kind, and fees can erase a small edge. Caps are the part that is not a fit. You set per-trade and daily spending limits. The model does not get to raise them because a backtest looked neat.