Learn Quant Trading From One Open-Source Book
This open-source quant trading book dey map the full journey from raw data to live order, show where beginners dey stop, and wetin fit transfer to US stocks.
Open-source quant trading book na free public syllabus: e write the complete journey from raw data reach live order, for the same sequence wey beginner dey meet am. The manuscript for XQuant: Everyone Can Be a Quantitative Trader, wey xingwudao publish for GitHub, na clear example with 686 stars as of August 2026. E get nine chapters wey follow the same path wey almost every quant curriculum dey follow. This page go take that path stage by stage, show the particular problem wey dey happen for each stage, and mark which parts still work when person move from Chinese A shares go US equities.
Wetin open source quant trading book dey contain?
If you remove the branding from any beginner syllabus, five stages remain in this order: collect and clean the data, build signal from am, test the signal against historical data, decide how much to bet, then send the order and pay the costs. The XQuant contents, as e dey for commit 016b66e on July 14, 2026, cover the same ground across nine chapters.
- Preparation, then chapter one: run one complete strategy from start to finish.
- Chapter two, wetin 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, how to judge whether strategy good: four perspectives.
- Chapter six, no celebrate early: prevent overfitting.
- Chapter seven, from ideal to real: execute trades.
- Chapter eight, life after launch: monitoring, diagnosis, iteration.
- Chapter nine, finding new opportunities: introduction to factor research.
The order deserve attention. Sizing come for chapter three, before both backtest chapters, while factor research come last. People wey teach themselves normally arrange am the other way: factor idea first, backtest second, and no sizing rule at all. The companion exercise repository, with 333 stars on the same date, dey organised around written task specifications instead of finished code. The reader directs an AI assistant to implement dem. To read code wey you no write still be the skill wey decides everything below, because every failure wey follow dey hide inside one implementation detail.
Stage one: data collect first, then define the universe
Data clean-up na the visible part of data work: bad prints, missing sessions, split and dividend adjustments. To choose which names to study na the hidden part. Na there survivorship bias fit enter, before any strategy code even dey exist. Take every US ticker wey printed trade for one week in June, year by year, then ask how many still dey trade for that same week in 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 yearOut of the 8224 tickers wey traded for that week of 2016, 50% still dey trade for the same week of 2026. Dem others don get acquired, merged, renamed, or delisted. Backtest wey use today's roster dey study only the names wey survive. E dey also pay strategy for holding companies wey dem pick after the fact. Beginner feed fit give you that survivor list without warning label: the free stock market data API guide explain wetin those feeds carry and wetin dem no carry.
Stage two: turn data into a signal
Signal na rule wey dey score stock for one particular time, and factor na signal wey you believe say e dey work across many stocks at once. Momentum, value, and low volatility na textbook examples. The problem for this stage na to test rules until one work. Twenty versions of moving-average crossover for one decade of one index go always produce one winner, and na the one wey fit noise pass go win. The protections no too exciting: set the rule before you measure am, keep one part of the history wey you no go ever look, count every version wey you try, and prefer fewer tunable numbers. XQuant use one whole chapter for this before factor research, and na the correct order.
Stage three: the backtest, wey most beginners dey stop
Na this stage dey end most self-taught projects. E dey end dem quietly, with equity curve wey look very good. Survivorship wey we mention before na the first of the two errors. Look-ahead bias na the second one: the strategy dey use a number wey the clock never deliver when the order suppose enter. The commonest version na rule wey dem calculate from today closing price, then fill for that same closing price. Measure the distance wey that assumption dey skip.
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 monthFor July 2026, the average distance between one close and the next opening print measure 40.8 basis points for SPY and 107.4 for NVDA. One basis point na one hundredth of one percentage point. All 24 months for the panel, starting from August 2024, dey above zero. Backtest wey decide for the close and fill for that same close dey collect that distance free for every trade, but no live order ever dey do that. Look-ahead bias for backtesting dey break down the mechanism, and why stocks dey gap overnight dey explain the gap itself.
Stage four: decide how much to buy
The main problem na say dem no get rule. Most traders wey teach themselves never write sizing rule. So dem get one by accident. Usually, na equal dollars for each name or any cash wey remain. Equal dollars no mean 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 DESCFor the twelve months wey end July 31, 2026, COIN move with annualized volatility of 68%. 12.7% get SPY for the calm end of the panel. The worst single session for COIN close 13.34% below the previous close. But the worst day for SPY na 2.69%. The same amount of dollars for each name fit produce very different daily swings. Na the swing, not the signal, wey beginner actually go experience. Kelly criterion position sizing explain one formal answer, while concentration risk show how the informal answer fit look.
Stage five: execution and the costs a backtest forgets
Two costs, one visible. Commissions and regulatory fees dey show for statement. Slippage no dey show: na di difference between di price wey dey for screen and di price wey you finally get. Its floor na di bid-ask spread, di distance between di best buying quote and di best selling quote for that moment. Buyers pay di ask and sellers hit di bid, so one round trip cross am two times. Di spread no be 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_timeDi panel cover 16 half-hour buckets for one Friday, from di 09:00 bucket before di opening bell reach di 16:30 bucket after di close. AAPL quote 10.53 basis points wide for di first bucket and 3.27 for di last one, while KO get 28.87 and 8.04. Di tightest quotes for di day dey for di middle of di chart, between those two ends. Strategy wey trade di open for two of di market’s most liquid names go pay different cost from di midday version of itself, and backtest wey assume zero cost no price either one correctly. Di bid-ask spread define di number, why spreads dey widen for di open explain di curve, and wetin e cost to trade stock add up one complete round trip. Between clean backtest and real money, one more step dey: paper trading before real money.
Which parts of an A share curriculum transfer to US stocks?
XQuant and im peers na Chinese A shares and ETFs dem write for. The method fit transfer complete: the stage order, the definitions, the overfitting discipline, the habit of writing costs as line item instead of afterthought, and every part of the sizing arithmetic. Price bars na price bars. Wetin no transfer na the rule book wey dey around dem.
- A shares get real T+1 restriction: stock wey you buy today, you no fit sell until the next session. US T+1 na settlement convention, and e no block any intraday trade. But the pattern day trader rule limit margin accounts wey dey below $25,000 to three day trades inside five business days.
- Main-board A shares stop when daily move reach 10%, while growth boards get 20%. US stocks no get daily cap. Instead, volatility bands and news halts dey cause pauses.
- A share orders dey trade in lots of 100 shares. Many US brokers fit fill fractional shares. This one change wetin sizing rule fit even express.
- China dey charge stamp duty for sell side. US sellers dey pay small regulatory fees wey get different size and structure.
- Session structure no be the same, including midday break for Shanghai and Shenzhen. US stock market hours dey run continuously and end with closing auction.
Any cost or timing constant wey you copy from course enter your own code na bug wey dey wait for the first live order.
Pin the reference, no be README
As of August 2026, repository no get any tagged release, so the citation wey go last na commit: 016b66e, dated July 14, 2026. This matter because dem still dey write the book. Chapter numbers fit change, dem fit rewrite README files, headings fit move, and link wey bin point to chapter seven fit quietly begin point to another thing. Cite the commit and the date. Record the chapter title wey you read instead of the number. That way, your notes go remain easy to check one year later. Dem publish the manuscript under CC BY-NC-SA 4.0, while build scripts dey under MIT. Na the syllabus itself teach this same discipline last: if you no fit run a strategy again from a pinned data snapshot, na story e be, no be result.
FAQ
Person fit learn quant trading from free open source book?
For the roadmap, yes. Open manuscript dey let you check every claim against the original source. But book no fit give you data, costs, and rules for your own market. Na for this place syllabus wey dem write for one exchange fit stop to match your broker.
Which stage for quant curriculum dey stop most beginners?
Na backtest. Two errors dey hide there, and both dey make result look better: survivorship, when dem build universe after the fact, and look-ahead, when dem fill trade with price wey the clock never print yet. Na only 50% of the tickers wey dey trade for that June week of 2016 still dey trade ten years later.
Wetin be the difference between survivorship bias and look-ahead bias?
Survivorship bias na universe problem: dem choose the names wey dey under test because dem survive. Look-ahead bias na timing problem: strategy use number wey no exist when dem suppose place the order. The first one dey make the roster look better; the second one dey make the fill look better.
Quant course for Chinese A shares fit work for US stocks?
The method fit work. But market rules no be the same. Keep the stage order, overfitting discipline, and cost accounting. Then replace the data plumbing, T+1 selling restriction, daily price limits, and lot sizes with US equivalents before any money move.
Every panel above na stored query with the SQL underneath. Open one, change the tickers or dates, and run am yourself for the Strasmore terminal.