Skip to content
QuantMax
QuantMax
  • Overview
  • Curriculum
    • FLUMental maths and numerical fluency
    • COMBCounting and combinatorics
    • PROBProbability
    • GAMEGames, decision theory and puzzles
    • MMMarket making
    • MKTMarkets and products

Practise

  • Question bank
  • Mental arithmetic
  • Market simulator
  • Arbitrage trees
  • Horse racing
  • Bid book
  • Screening tests
  • Mock papers

Reference

  • Formula reference
  • Search

Your record

  • Review queue
  • Progress
  • Leaderboard
  • Profile
  • Invite friends
AccountSend feedback
  1. Formula reference

Python and data for quants

6 lessons · 4 equations. Each lesson below gives its formulas and key rules; open the lesson for the full explanation.

Idiomatic Python: generators, itertools and the gotchas

Key rules

  • Generators are lazy, single-pass and constant-memory.
  • Mutable defaults are created once at definition time.
  • Closures bind late, so loop variables are read when called.

NumPy: broadcasting, axes and vectorisation

Cross-sectional standardisation

zit=xit−xˉtstz_{it}=\frac{x_{it}-\bar x_t}{s_t}zit​=st​xit​−xˉt​​

Compute the mean and spread across assets at each timestamp; broadcasting must align on that axis.

Remember

  • Broadcasting aligns from the trailing dimension; sizes must match or be 1.

pandas: groupby, joins, resampling and time zones

Join row count by key

Njoined=∑knk,leftnk,rightN_{\mathrm{joined}}=\sum_k n_{k,\mathrm{left}}n_{k,\mathrm{right}}Njoined​=k∑​nk,left​nk,right​

Duplicate keys multiply rows. Check join cardinality before trusting a backtest or aggregate.

Remember

  • transform keeps the shape; agg reduces.

Market data in pandas, and where look-ahead hides

Key rules

  • Shift the signal, not the return, and lag by the publication delay rather than by one bar.
  • merge_asof with direction="backward" is the "what did I know then" join.
  • Survivorship, restatement and selection biases sit alongside look-ahead — name all four.

Vectorised backtesting: signal to position to P&L

Annualised Sharpe after costs

SRann=rˉnetsnet252\mathrm{SR}_{\mathrm{ann}}=\frac{\bar r_{\mathrm{net}}}{s_{\mathrm{net}}}\sqrt{252}SRann​=snet​rˉnet​​252​

Use net daily returns after spread, fees and turnover costs; the square-root rule assumes weak serial dependence.

Remember

  • Lag everything one extra period; a real signal degrades, a leak collapses.

Performance: profiling, vectorising and when to leave Python

Amdahl’s law

speedup=1(1−p)+p/s\mathrm{speedup}=\frac{1}{(1-p)+p/s}speedup=(1−p)+p/s1​

If only fraction ppp of runtime is improved by a factor sss, the untouched work caps the total speedup.

Remember

  • Profile first; intuition about bottlenecks is unreliable.

QuantMax · 141 lessons · 1342 questions · c5c0caa

  • Premium
  • Arbitrage trees
  • Horse racing
  • Invite friends
  • Account
  • About QuantMax

Firm names identify publicly reported question patterns and nothing more. QuantMax is not affiliated with, endorsed by, or recruiting for any firm named in the curriculum. Everything you do in lessons and the question bank is kept to your account.