Paper trading after a backtest: about two weeks before live money
Hands-on, part 5. A good backtest is not a reason to use real money. Slippage, limit locks, halts, and your own hand sit in between.
Short answer: after the backtest passes, run about two weeks of paper trading before any live money. Start with a SQLite ledger that books the next open, and freeze the rules for the whole paper period.
How to choose: After a backtest passes, and before any live money, run about two weeks of paper trading. Start with a paper ledger you build yourself: the strategy emits a signal each day, and a script books the next day's open into SQLite. This page freezes fees at a commission of 2.5 per 10,000 plus stamp tax of 1 per 1,000 on sells. That is not the same pair of numbers as the backtrader walkthrough, whose runnable line is commission=0.0003 and whose prose adds a 0.05% sell-side stamp tax. Match the numbers that backtest actually used, and do not change them during the paper period. Use backtrader's realtime mode if you want the engine to keep the books on the same code. The fills are still the assumptions you wrote. Use a Tonghuashun or Xueqiu paper portfolio only to watch your own behavior: the export is awkward to reconcile in code. Skip a client bridge such as easytrader on the first round. It is the closest to a real order path, and the setup cost is high. This page is not the tool-order guide and not the site FAQ.
Who it is for: Someone whose strategy already stands on a historical backtest, and who wants to see slippage, limit-up and limit-down locks, trading halts, and their own hesitation before risking money. Use the paper account as a live comparison on the same definitions as that backtest, not as a second backtest.
Who it is not for: Someone who has not finished a backtest, or who wants this page to replace a broker's official simulated account. China A-shares have no single official paper-trading API. The method here is a ledger you build yourself, to check a research process. Two weeks of paper trading do not predict live returns. This page is not the tool-order guide and not the site FAQ.
The same walkthrough in Chinese is paper trading after a backtest. The previous part, which this page assumes has already passed, is backtrader: a first strategy. The same walkthrough in Chinese is the backtrader walkthrough (Chinese). The pass bar is also summarized on the beginner learning path. Open-source bots that should simulate before live orders are in how to choose a trading bot. None of those is a language version of this page. This page is not the tool-order guide and not the site FAQ.
Facts below follow the Chinese walkthrough. The ledger snippet was not re-run for this English page. This site has no commercial relationship with backtrader, Tonghuashun, Xueqiu, or easytrader. This is not investment advice. Two weeks of paper trading are not a forecast.
01 · Why a layer has to sit between the backtest and live trading
A backtest has three blind spots. The fill is idealized. The signal price is treated as the fill. Live trading has slippage, and some orders never fill. Lookahead can slip through. Careful code can still use one fact that was only known that day. The backtest does not include you. It does not hesitate. You do. Paper trading uses data that is still arriving, and a rule you do not edit, so those three show up before any real money.
02 · Four setups
- 1. A paper ledger you build yourself (start here). The strategy emits a signal each day. A script books the next day's open into SQLite. It is the most transparent, the definitions match the backtest, and it can be stood up in half an hour. This page follows this path.
- 2. backtrader realtime mode. Swap the data feed for a daily increment and let backtrader keep the books. It is the same code as the backtest, so the two stay consistent. The fills are still the assumptions you wrote.
- 3. A broker or community paper account. Tonghuashun, a Xueqiu portfolio, and similar tools feel closer to a real screen. Exporting the fills is awkward, so a programmatic reconciliation is hard. Use one to watch your own behavior, not as the ledger.
- 4. A client bridge such as easytrader. It walks the real order path, so it is the closest to live trading. The environment and the upkeep are heavy. Do not start the first paper round here.
03 · The paper ledger (setup 1)
Run it once after the close. Three tables hold the whole record:
import sqlite3
conn = sqlite3.connect("paper.db")
conn.executescript("""
CREATE TABLE IF NOT EXISTS signals( -- raw signals from the strategy
date TEXT, code TEXT, side TEXT, note TEXT);
CREATE TABLE IF NOT EXISTS fills( -- virtual fill at the next open
date TEXT, code TEXT, side TEXT, price REAL, shares INTEGER);
CREATE TABLE IF NOT EXISTS equity( -- mark to the close each day
date TEXT, cash REAL, market_value REAL);
""")# Fill rules (frozen in code; do not change them during the paper period):
# buy price = next day's open after the signal; limit-up and no fill -> record "missed"
# sell price = next day's open after the trigger; limit-down and no fill -> wait until a day you can sell
# commission of 2.5 per 10,000, plus stamp tax of 1 per 1,000 on sellsThe frozen comment is a commission of 2.5 per 10,000 (0.00025), plus stamp tax of 1 per 1,000 (0.1%) on sells. The backtrader walkthrough actually sets commission=0.0003, and its prose adds a 0.05% sell-side stamp tax. Those are not the same numbers as 2.5 per 10,000 and 1 per 1,000. Matching the backtest means using the numbers that backtest actually ran. Do not switch to another set during the paper period.
After about two weeks you have a live comparison on the same definitions as that backtest.
04 · Reconciliation: where the gap goes
At the end of the paper period, compare the two fill lists day by day. The gap usually lands in four buckets:
- Fill prices. The backtest used the signal's close. The paper ledger uses the next open. A systematic shift is normal. Measure it.
- Orders that do not fill. A limit-locked bar, or a temporary halt. Count the
missedshare. If it is high, add the same constraint to the backtest. - Signal mismatches. The backtest has a signal that day and the paper run does not, or the reverse. About nine times out of ten that is lookahead. Go back through the data timestamps line by line.
- Cash and fees. Rounding to a minimum of 100 shares, and the commission, are small. They still drift the equity curve.
05 · When it passes, and a small live account is allowed
- At least 10 trading days, and those days include a decline. A rising-only sample proves nothing.
- The gap versus the backtest over the same dates can be explained (slippage or fees). An unexplained hole means stop.
- Zero unexplained signal mismatches. That is the check that lookahead was not caught hiding.
- The maximum drawdown is one you can accept if you imagine the money is real.
When all four pass, use an amount you could lose entirely for a small live account, and keep the log. Any miss means go back and fix the rule. For a China A-share account, the terminal choice after that is how to choose between QMT and PTrade. That comparison is not this ledger. Charting, a screener, and alerts, without this research ledger, are the TradingView setup. That page is not this ledger either. A machine that stays on so a daily job can run when the laptop is off is opening a cloud server. Conda, cron, and a model API on that machine are the cloud quant desk. Neither page is this ledger. Broker terminals are how to choose a quant trading platform. The order of what to learn is the learning path.
06 · Pitfalls
- Changing parameters during the paper period. If you tune because the paper account lost, the paper period will always just pass. Freeze the strategy. Write the problem down. Change it on the next round.
- Paper-trading only a rising market. Two good weeks do not count. You need at least one drawdown.
- Treating it as a game. Skipping the process because the money is not real trains a bad habit. Paper trading practices the execution itself.
This is the end of the main line: a workbench, then data, then a backtest, then paper trading. To extend the data to US stocks, see the EODHD walkthrough (Chinese). All English guides are on the guides index.
This tutorial is not investment advice. China A-shares have no single official paper-trading API. The method here is a ledger you build yourself, to check a research process.
Frequently asked questions
How to choose paper trading after a backtest?
After a backtest passes, and before any live money, run about two weeks of paper trading. Start with a paper ledger you build yourself: the strategy emits a signal each day, and a script books the next day's open into SQLite. This page freezes fees at a commission of 2.5 per 10,000 plus stamp tax of 1 per 1,000 on sells. That is not the same pair of numbers as the backtrader walkthrough, whose runnable line is commission=0.0003 and whose prose adds a 0.05% sell-side stamp tax. Match the numbers that backtest actually used, and do not change them during the paper period. Use backtrader's realtime mode if you want the engine to keep the books on the same code. The fills are still the assumptions you wrote. Use a Tonghuashun or Xueqiu paper portfolio only to watch your own behavior: the export is awkward to reconcile in code. Skip a client bridge such as easytrader on the first round. It is the closest to a real order path, and the setup cost is high. This page is not the tool-order guide and not the site FAQ.
Who it is for?
Someone whose strategy already stands on a historical backtest, and who wants to see slippage, limit-up and limit-down locks, trading halts, and their own hesitation before risking money. Use the paper account as a live comparison on the same definitions as that backtest, not as a second backtest.
Who it is not for?
Someone who has not finished a backtest, or who wants this page to replace a broker's official simulated account. China A-shares have no single official paper-trading API. The method here is a ledger you build yourself, to check a research process. Two weeks of paper trading do not predict live returns. This page is not the tool-order guide and not the site FAQ.
Why sit between the backtest and live trading?
A backtest has three blind spots. The fill is idealized: the signal price is treated as the fill, while live trading has slippage and orders that do not fill. A lookahead bug can slip through, even in careful code, if one line uses information known only that day. And the backtest does not include you. It does not hesitate. You do. Paper trading uses data that is still arriving, and a rule you are not allowed to edit, so those three show up before any real money.
What are the four paper-trading setups?
A self-built paper ledger is the recommended start, because the definitions stay comparable to the backtest. backtrader's realtime mode keeps the books on the same code, and the fills are still assumptions you wrote. A Tonghuashun or Xueqiu paper portfolio is for watching your own behavior, and it is hard to reconcile in code. A client bridge such as easytrader is the closest to a real order path. Skip it on the first round.
When does paper trading pass?
All four bars have to pass. At least 10 trading days, and those days include a decline. The gap versus the backtest over the same dates can be explained by slippage or fees, not by a hole you cannot name. No unexplained missing or extra signal. The maximum drawdown is one you can accept if you imagine the money is real. Then use an amount you could lose entirely for a small live account, and keep the log. Any miss means go back.
Where does the gap versus the backtest go?
It usually lands in four buckets. Fill prices: the backtest used the signal's close, and the paper ledger uses the next open. Unfilled orders: a limit-locked bar or a halt, recorded as missed. Signal mismatches: one side has a signal that day and the other does not, which is lookahead about nine times out of ten. Cash and fees: rounding to a minimum of 100 shares, and the commission, which drift the equity curve.
What pitfalls does this walkthrough call out?
Do not change parameters because the paper account lost. The paper period would then always just pass. Freeze the strategy, write the problem down, and change it on the next round. Do not paper-trade only a rising market. Two good weeks do not count until you have seen a drawdown. Do not treat the exercise as a game. Skipping the process because the money is not real trains the habit you will take live. Paper trading practices execution.