Learn Quant Trading From an Open Source Book
An open source quant trading book lays out the whole syllabus. See what each stage teaches, where most beginners stop, and which parts transfer to US stocks.
An open source quant trading book is a free public syllabus: the whole path from raw data to a live order, written down in the sequence a beginner meets it. The manuscript for XQuant: Everyone Can Be a Quantitative Trader, published on GitHub by xingwudao, is a clean specimen at 686 stars as of August 2026, and its nine chapters walk the arc that almost every quant curriculum walks. This page follows that arc stage by stage, names the specific failure that lives at each one, and marks which parts survive the trip from Chinese A shares to US equities.
What does an open source quant trading book contain?
Strip the branding off any beginner syllabus and five stages remain, in this order: acquire and clean the data, build a signal from it, test that signal against history, decide how large to bet, then send the order and pay the costs. The XQuant contents, read at commit 016b66e of July 14, 2026, cover the same ground in nine chapters.
- Preparation, then chapter one: run one complete strategy end to end.
- Chapter two, what to buy: start with three ETFs.
- Chapter three, how much to buy: three allocation methods, measured against each other.
- Chapter four, when to trade: rebalancing, stop loss, take profit.
- Chapter five, judging whether a strategy is any good: four perspectives.
- Chapter six, do not celebrate early: preventing overfitting.
- Chapter seven, from the ideal to the real: executing trades.
- Chapter eight, life after launch: monitoring, diagnosis, iteration.
- Chapter nine, finding new opportunities: an introduction to factor research.
The ordering deserves attention. Sizing arrives in chapter three, ahead of both backtest chapters, and factor research arrives last. Self-taught paths usually run the other way: a factor idea first, a backtest second, a sizing rule never. The companion exercise repository (333 stars, same date) is organised around written task specifications rather than finished code, with the reader directing an AI assistant to implement them. Reading code you did not write is still the skill that decides everything below, since each failure that follows hides inside one implementation detail.
Stage one: get the data, then define the universe
Cleaning is the visible half of data work: bad prints, missing sessions, split and dividend adjustments. Choosing which names to study is the invisible half, and it is where survivorship bias enters, before a line of strategy code exists. Take every US ticker that printed a trade during one week of June, one year at a time, and ask how many were still trading in the same week of 2026.
The exact SQL behind every number
WITH june_week AS (
SELECT toYear(toTimeZone(window_start, 'America/New_York')) AS year,
ticker
FROM global_markets.delayed_stocks_minute_aggs
WHERE toMonth(toTimeZone(window_start, 'America/New_York')) = 6
AND toDayOfMonth(toTimeZone(window_start, 'America/New_York')) BETWEEN 10 AND 16
AND toYear(toTimeZone(window_start, 'America/New_York')) BETWEEN 2016 AND 2026
AND volume > 0
GROUP BY year, ticker
),
survivors AS (
SELECT ticker FROM june_week WHERE year = 2026
)
SELECT year,
uniqExact(ticker) AS tickers_traded,
uniqExactIf(ticker, ticker IN (SELECT ticker FROM survivors)) AS still_trading_2026,
round(100 * uniqExactIf(ticker, ticker IN (SELECT ticker FROM survivors))
/ uniqExact(ticker), 1) AS still_trading_pct
FROM june_week
GROUP BY year
ORDER BY yearOf the 8224 tickers that traded in that week of 2016, 50% were still trading in the same week of 2026. The others were acquired, merged, renamed, or delisted. A backtest built from today's roster studies only the names that made it, and pays a strategy for holding companies picked after the fact. A beginner feed will hand you that survivor list without a warning label: the free stock market data API guide covers what those feeds do and do not carry.
Stage two: turn data into a signal
A signal is a rule that scores a stock at a point in time, and a factor is a signal you believe holds across many stocks at once. Momentum, value, and low volatility are the textbook examples. The failure at this stage is testing rules until one works. Twenty variants of a moving-average crossover on one decade of one index will always produce a winner, and the winner is the one that fit the noise best. The defences are unglamorous: fix the rule before you measure it, hold back a slice of history you never look at, count every variant you tried, and prefer fewer tunable numbers. XQuant puts a whole chapter on this ahead of factor research, which is the right order.
Stage three: the backtest, where most beginners stop
This is the stage that ends most self-taught projects, and it ends them quietly, with a great-looking equity curve. Survivorship, above, is the first of the two errors. Look-ahead bias is the second: the strategy uses a number the clock had not delivered when the order was supposed to go in. The most common version is a rule computed from today's closing price and filled at that same closing price. Measure the distance that assumption skips.
The exact SQL behind every number
WITH sessions AS (
SELECT ticker,
toDate(toTimeZone(window_start, 'America/New_York')) AS session,
argMin(open, window_start) AS session_open,
argMax(close, window_start) AS session_close
FROM global_markets.delayed_stocks_minute_aggs
WHERE ticker IN ('SPY', 'NVDA')
AND toDate(toTimeZone(window_start, 'America/New_York')) >= toDate('2024-08-01')
AND toDate(toTimeZone(window_start, 'America/New_York')) <= toDate('2026-07-31')
AND (toHour(toTimeZone(window_start, 'America/New_York')) * 60
+ toMinute(toTimeZone(window_start, 'America/New_York'))) BETWEEN 570 AND 959
GROUP BY ticker, session
),
gaps AS (
SELECT ticker,
session,
toFloat64(session_open) AS open_px,
toFloat64(lagInFrame(session_close) OVER (PARTITION BY ticker ORDER BY session)) AS prev_close
FROM sessions
)
SELECT formatDateTime(toStartOfMonth(session), '%Y-%m') AS month,
formatDateTimeInJodaSyntax(toStartOfMonth(session), 'MMMM yyyy') AS month_label,
round(avgIf(abs(open_px / prev_close - 1) * 10000, ticker = 'SPY'), 1) AS spy_gap_bps,
round(avgIf(abs(open_px / prev_close - 1) * 10000, ticker = 'NVDA'), 1) AS nvda_gap_bps
FROM gaps
WHERE prev_close > 0
GROUP BY month, month_label
HAVING countIf(ticker = 'SPY') > 0 AND countIf(ticker = 'NVDA') > 0
ORDER BY monthIn July 2026, the average distance between one close and the next opening print measured 40.8 basis points for SPY and 107.4 for NVDA. A basis point is one hundredth of a percentage point. All 24 months on the panel, starting from August 2024, sit above zero. A backtest that decides on the close and fills at that close collects that distance free of charge on every trade, and no live order ever does. Look-ahead bias in backtesting takes the mechanism apart, and why stocks gap overnight explains the gap itself.
Stage four: decide how much to buy
The failure here is absence. Most self-taught traders never write a sizing rule, which means they have one by accident, usually equal dollars per name or whatever cash is free. Equal dollars is not equal risk.
The exact SQL behind every number
WITH daily AS (
SELECT ticker,
toDate(toTimeZone(window_start, 'America/New_York')) AS session,
argMax(close, window_start) AS session_close
FROM global_markets.delayed_stocks_minute_aggs
WHERE ticker IN ('SPY', 'KO', 'JNJ', 'MSFT', 'AAPL', 'NVDA', 'TSLA', 'COIN')
AND toDate(toTimeZone(window_start, 'America/New_York')) >= toDate('2025-08-01')
AND toDate(toTimeZone(window_start, 'America/New_York')) <= toDate('2026-07-31')
AND (toHour(toTimeZone(window_start, 'America/New_York')) * 60
+ toMinute(toTimeZone(window_start, 'America/New_York'))) BETWEEN 570 AND 959
GROUP BY ticker, session
),
rets AS (
SELECT ticker,
toFloat64(session_close) AS close_px,
toFloat64(lagInFrame(session_close) OVER (PARTITION BY ticker ORDER BY session)) AS prev_close
FROM daily
)
SELECT ticker,
round(stddevSamp(close_px / prev_close - 1) * sqrt(252) * 100, 1) AS annualized_vol_pct,
round(abs(min(close_px / prev_close - 1)) * 100, 2) AS worst_day_pct
FROM rets
WHERE prev_close > 0
GROUP BY ticker
ORDER BY annualized_vol_pct DESCOver the twelve months ending July 31, 2026, COIN moved at an annualized volatility of 68%, against 12.7% for SPY at the calm end of the panel. Its worst single session closed 13.34% below the prior close, while the worst day in SPY was 2.69%. The same dollars in each name buy very different daily swings, and the swing, not the signal, is what a beginner actually experiences. Kelly criterion position sizing sets out one formal answer, and concentration risk shows the shape of the informal one.
Stage five: execution and the costs a backtest forgets
Two costs, one visible. Commissions and regulatory fees appear on the statement. Slippage does not: it is the difference between the price on the screen and the price you get. Its floor is the bid-ask spread, the distance between the best buying and best selling quote at that instant. Buyers pay the ask and sellers hit the bid, so a round trip crosses it twice. The spread is not a constant.
The exact SQL behind every number
WITH quotes AS (
SELECT ticker,
toStartOfInterval(toTimeZone(sip_timestamp, 'America/New_York'), INTERVAL 30 MINUTE) AS bucket,
toFloat64(ask_price - bid_price) / toFloat64((ask_price + bid_price) / 2) * 10000 AS spread_bps
FROM global_markets.cache_stocks_quotes
WHERE ticker IN ('AAPL', 'KO')
AND sip_timestamp >= toDateTime('2026-07-17 13:00:00')
AND sip_timestamp < toDateTime('2026-07-17 21:00:00')
AND bid_price > 0
AND ask_price > bid_price
)
SELECT formatDateTime(bucket, '%H:%i') AS et_time,
round(avgIf(spread_bps, ticker = 'AAPL'), 2) AS aapl_spread_bps,
round(avgIf(spread_bps, ticker = 'KO'), 2) AS ko_spread_bps
FROM quotes
WHERE spread_bps > 0 AND spread_bps < 500
GROUP BY et_time
HAVING countIf(ticker = 'AAPL') > 0 AND countIf(ticker = 'KO') > 0
ORDER BY et_timeThe panel covers 16 half-hour buckets of one Friday, from the 09:00 bucket before the opening bell to the 16:30 bucket after the close. AAPL quoted 10.53 basis points wide in that first bucket and 3.27 in the last, with KO at 28.87 and 8.04. The tightest quotes of the day sit in the middle of the chart, between those two ends. A strategy that trades the open on two of the market's most liquid names pays a different cost than the midday version of itself, and a backtest with a zero-cost assumption prices neither. The bid-ask spread defines the number, why spreads widen at the open explains the curve, and what it costs to trade a stock adds up a full round trip. Between a clean backtest and real money sits one more step: paper trading before real money.
Which parts of an A share curriculum transfer to US stocks?
XQuant and its peers are written for Chinese A shares and ETFs. The method transfers intact: the stage order, the definitions, the overfitting discipline, the habit of writing costs in as a line item rather than an afterthought, and every piece of the sizing arithmetic. Price bars are price bars. What does not transfer is the rule book around them.
- A shares run a genuine T+1 restriction: stock bought today cannot be sold until the next session. US T+1 is a settlement convention and blocks nothing intraday, although the pattern day trader rule limits margin accounts under $25,000 to three day trades in five business days.
- Main-board A shares stop at a 10% daily move, with 20% on the growth boards. US stocks carry no daily cap, and pauses come from volatility bands and news halts instead.
- A share orders trade in lots of 100 shares. Many US brokers fill fractional shares, which changes what a sizing rule can even express.
- China charges a stamp duty on the sell side. US sellers pay small regulatory fees of a different size and shape.
- Session structure differs, including a midday break in Shanghai and Shenzhen. US stock market hours run continuously and end in a closing auction.
Any cost or timing constant copied from a course into your own code is a bug waiting for the first live order.
Pin the reference, not the README
The repository carries no tagged releases as of August 2026, so the durable citation is a commit: 016b66e, dated July 14, 2026. That matters for a book still being written. Chapter numbers shift, README files get rewritten, headings move, and a link that pointed at chapter seven quietly points at something else. Cite the commit and the date, record the chapter title you read rather than its number, and your notes stay checkable a year later. The manuscript is published under CC BY-NC-SA 4.0, with build scripts under MIT. The same discipline is the last lesson of the syllabus itself: a strategy you cannot re-run from a pinned data snapshot is a story, not a result.
FAQ
Can you learn quant trading from a free open source book?
For the map, yes, and an open manuscript lets you check every claim against its source. What a book cannot supply is your own market's data, costs, and rules, which is exactly where a syllabus written for one exchange stops matching your broker.
Which stage of a quant curriculum stops most beginners?
The backtest. Two errors live there and both flatter the result: survivorship, from a universe assembled after the fact, and look-ahead, from filling at a price the clock had not printed yet. Only 50% of the tickers trading in that June week of 2016 were still trading a decade later.
What is the difference between survivorship bias and look-ahead bias?
Survivorship bias is a universe problem: the names under test were selected by having lasted. Look-ahead bias is a timing problem: the strategy uses a number that did not exist when the order was supposed to go in. The first inflates the roster, the second inflates the fill.
Does a Chinese A share quant course work for US stocks?
The method does. The market rules do not. Keep the stage order, the overfitting discipline, and the cost accounting, then replace the data plumbing, the T+1 selling restriction, daily price limits, and lot sizes with US equivalents before any money moves.
Every panel above is a stored query with its SQL underneath. Open one, swap the tickers or the dates, and run it yourself on the Strasmore terminal.