Leanpub Header

Skip to main content

Build Your Own Quant Backtest Engine

Minimum price

$9.99

$24.99

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
About

About

About the Book

Share this book

Author

About the Author

Contents

Table of Contents

7.4 Limit and stop orders

  1. 7.5 Commission models
  2. 7.6 Slippage models
  3. 7.7 Why this component earns its keep
  4. Key Takeaways
  5. Action Steps

8. Performance Metrics: The Real Formulas

  1. 8.1 Metrics you can trust
  2. 8.2 Period returns and CAGR

src/metrics/performance.py

  1. 8.3 Sharpe ratio
  2. 8.4 Sortino ratio
  3. 8.5 Maximum drawdown
  4. 8.6 Win rate and profit factor
  5. 8.7 Turnover

Sum of absolute weight changes over the year.

  1. 8.8 Reporting a metric table
  2. Key Takeaways
  3. Action Steps

9. Walk-Forward Analysis

  1. 9.1 Why a single train/test split is not enough
  2. 9.2 The rolling window

src/validation/walk_forward.py

  1. 9.3 What you optimize
  2. 9.4 Reading the result
  3. 9.5 Avoiding leakage
  4. 9.6 When walk-forward is overkill
  5. Key Takeaways
  6. Action Steps

10. Look-Ahead and Survivorship Bias

  1. 10.1 The two biases that silently inflate backtests
  2. 10.2 Look-ahead bias
  3. 10.3 Target shift test
  4. 10.4 Survivorship bias
  5. 10.5 Point-in-time fundamentals
  6. 10.6 The honesty test
  7. Key Takeaways
  8. Action Steps

11. Parameter Sensitivity and the Plateau

  1. 11.1 A peak is not a robust edge
  2. 11.2 Sweeping a grid

src/validation/sensitivity.py

  1. 11.3 Reading the surface
  2. 11.4 Threshold of robustness
  3. 11.5 Number of parameters
  4. 11.6 Out-of-sample consistency
  5. Key Takeaways
  6. Action Steps

12. Monte Carlo and Stress Testing

  1. 12.1 Your equity curve is one path
  2. 12.2 Resampling trade order

src/validation/monte_carlo.py

  1. 12.3 Reading the distribution
  2. 12.4 Stress scenarios
  3. 12.5 Why this matters in deployment
  4. 12.6 Limitations
  5. Key Takeaways
  6. Action Steps

13. A Minimal Usable Engine, End to End

  1. 13.1 Putting it together
  2. 13.2 The full listing

src/minimal_engine.py

  1. 13.3 How to extend it
  2. 13.4 What it deliberately omits
  3. Key Takeaways
  4. Action Steps

14. The Trusted-Backtest Checklist

  1. 14.1 Run this before believing any result
  2. 14.2 Data
  3. 14.3 No look-ahead
  4. 14.4 Costs and fills
  5. 14.5 Validation
  6. 14.6 Risk
  7. 14.7 Reporting
  8. 14.8 The final question
  9. Key Takeaways
  10. Action Steps

15. From Backtest to Paper Trading

  1. 15.1 The backtest is not the strategy
  2. 15.2 Paper trading means
  3. 15.3 Logging everything
  4. 15.4 Comparing backtest to paper
  5. 15.5 What is normal
  6. 15.6 When to stop paper trading
  7. Key Takeaways
  8. Action Steps

16. Common Engine Bugs and How to Find Them

  1. 16.1 Bugs you will write
  2. 16.2 Order direction reversed
  3. 16.3 Position not updated
  4. 16.4 Double-shifted signal
  5. 16.5 Off-by-one in warm-up
  6. 16.6 Slippage applied only to buys
  7. 16.7 Commission on notional but not cash
  8. 16.8 Using adjusted prices for fills
  9. 16.9 Reconciliation test
  10. 16.10 The self-audit loop
  11. Key Takeaways
  12. Action Steps

17. Scaling and Optimizing Your Engine

  1. 17.1 When the loop gets slow
  2. 17.2 Profile first
  3. 17.3 Vectorize indicators inside the loop
  4. 17.4 Avoid per-bar DataFrame construction
  5. 17.5 When to move to a faster language
  6. 17.6 Parallelizing walk-forward
  7. 17.7 Keep the engine honest while fast
  8. Key Takeaways
  9. Action Steps

18. Closing: What a Credible Backtest Looks Like

  1. 18.1 You now have the pieces
  2. 18.2 The credible backtest has these traits
  3. 18.3 The next step
  4. 18.4 Final disclaimer

19. Designing Your Event Loop: Synchronous vs Asynchronous

  1. 19.1 The loop is the heart
  2. 19.2 Synchronous loop
  3. 19.3 Why not asynchronous
  4. 19.4 Bar-level vs tick-level
  5. 19.5 Order of operations within a bar
  6. 19.6 Multiple events per timestamp
  7. Key Takeaways
  8. Action Steps

20. Modeling Order Types Realistically

  1. 20.1 More than market orders
  2. 20.2 Market orders
  3. 20.3 Limit orders
  4. 20.4 Stop orders
  5. 20.5 Stop-limit orders
  6. 20.6 The intrabar path problem
  7. Key Takeaways
  8. Action Steps

21. Position Sizing and Risk Controls in the Engine

  1. 21.1 Sizing is a portfolio responsibility
  2. 21.2 Fixed fractional sizing
  3. 21.3 Volatility targeting
  4. 21.4 Maximum position size
  5. 21.5 Total heat limit
  6. 21.6 Drawdown circuit breaker
  7. Key Takeaways
  8. Action Steps

22. Multi-Instrument Portfolios in the Engine

  1. 22.1 Moving from one to many
  2. 22.2 Position storage
  3. 22.3 Order routing
  4. 22.4 Cash allocation
  5. 22.5 Correlation awareness
  6. 22.6 Rebalancing
  7. Key Takeaways
  8. Action Steps

23. Tax Lots and Cost Basis

  1. 23.1 Why tax lots matter
  2. 23.2 FIFO
  3. 23.3 Average cost
  4. 23.4 Which to use
  5. 23.5 Partial fills
  6. Key Takeaways
  7. Action Steps

24. Performance Attribution: Where Do Returns Come From?

  1. 24.1 A total return number hides the story
  2. 24.2 Market exposure (beta)
  3. 24.3 Timing versus selection
  4. 24.4 By regime
  5. 24.5 By trade type
  6. Key Takeaways
  7. Action Steps

25. Data Quality Monitoring in the Engine

  1. 25.1 Bad data quietly corrupts backtests
  2. 25.2 Pre-load validation
  3. 25.3 Gap detection
  4. 25.4 Outlier detection
  5. 25.5 In-loop checks
  6. 25.6 Versioning and provenance
  7. Key Takeaways
  8. Action Steps

26. Logging and Reproducibility

  1. 26.1 A backtest without a log is a guess
  2. 26.2 What to log
  3. 26.3 Determinism
  4. 26.4 Configuration files
  5. 26.5 A results database
  6. 26.6 Reproducibility checklist
  7. Key Takeaways
  8. Action Steps

27. Testing Your Engine with Synthetic Data

  1. 27.1 Unit tests before trust
  2. 27.2 Test cash math
  3. 27.3 Test no look-ahead
  4. 27.4 Test stop fills
  5. 27.5 Test drawdown
  6. 27.6 Test costs
  7. 27.7 Why synthetic tests matter
  8. Key Takeaways
  9. Action Steps

28. When to Use Vectorized vs Event-Driven in Practice

  1. 28.1 The practical decision
  2. 28.2 Use vectorized when
  3. 28.2 Use event-driven when
  4. 28.3 A hybrid workflow
  5. 28.4 The trap of premature optimization
  6. 28.5 The trap of vectorized false confidence
  7. Key Takeaways
  8. Action Steps

29. Common Backtesting Frameworks and When to Reach for Them

  1. 29.1 You do not need to write everything
  2. 29.2 What frameworks provide
  3. 29.3 When a framework helps
  4. 29.4 When to build your own
  5. 29.5 The danger of black-box frameworks
  6. 29.6 Recommended path
  7. Key Takeaways
  8. Action Steps

30. The Developer’s Discipline

  1. 30.1 Engineering is the edge
  2. 30.2 Version control
  3. 30.3 Code review
  4. 30.4 Modular design
  5. 30.5 Continuous testing
  6. 30.6 Document assumptions
  7. 30.7 The closing principle
  8. Key Takeaways
  9. Action Steps

31. Modeling Borrowing and Short Selling

  1. 31.1 The long-only assumption is a limitation
  2. 31.2 What a short position means
  3. 31.3 Borrow costs
  4. 31.4 Margin requirements
  5. 31.5 Short squeezes and risk
  6. 31.6 When to start with longs
  7. Key Takeaways
  8. Action Steps

32. Handling Corporate Actions in the Event Loop

  1. 32.1 Why corporate actions are events
  2. 32.2 A CorporateAction event
  3. 32.3 Processing a split
  4. 32.4 Processing a dividend
  5. 32.5 The ordering rule
  6. 32.6 Look-ahead risk
  7. Key Takeaways
  8. Action Steps

33. Benchmarks and Comparing Your Strategy

  1. 33.1 Without a benchmark, you have no scale
  2. 33.2 Choose the right benchmark
  3. 33.3 Excess returns
  4. 33.4 Relative drawdown
  5. 33.5 Benchmark timing
  6. 33.6 Reporting format
  7. Key Takeaways
  8. Action Steps

34. Volume and Liquidity Constraints

  1. 34.1 You cannot trade more than the market gives
  2. 34.2 Volume participation limit
  3. 34.3 Market impact
  4. 34.4 Illiquid instruments
  5. 34.5 Capacity
  6. Key Takeaways
  7. Action Steps

35. Intraday Data and Bar Resampling

  1. 35.1 Why daily bars are not always enough
  2. 35.2 Intraday data formats
  3. 35.3 Resampling
  4. 35.4 Time-of-day effects
  5. 35.5 Session and holiday handling
  6. 35.6 The cost of finer data
  7. Key Takeaways
  8. Action Steps

36. Stress Testing the Portfolio

  1. 36.1 Beyond historical averages
  2. 36.2 Historical stress scenarios
  3. 36.3 Synthetic stress scenarios
  4. 36.4 Reverse stress testing
  5. 36.5 Correlation breakdown
  6. 36.6 Action from stress tests
  7. Key Takeaways
  8. Action Steps

37. From Backtest to Live: The Bridge

  1. 37.1 The last mile
  2. 37.2 Data feeds
  3. 37.3 Order routing
  4. 37.4 Monitoring
  5. 37.5 Fail-safe defaults
  6. 37.6 The bridge principle
  7. Key Takeaways
  8. Action Steps

38. A Worked Example: Moving Average Crossover, Fully Modeled

  1. 38.1 The example
  2. 38.2 The setup
  3. 38.3 The code

Entry signal from previous bar’s close

Stop check on intrabar low

  1. 38.4 What to inspect
  2. 38.5 The lesson
  3. Key Takeaways
  4. Action Steps

39. Choosing a Broker for Programmatic Trading

  1. 39.1 The engine is only half the system
  2. 39.2 API access
  3. 39.3 Commission structure
  4. 39.4 Margin and short availability
  5. 39.5 Reliability
  6. 39.6 Data quality
  7. Key Takeaways
  8. Action Steps

40. Maintaining a Live Engine

  1. 40.1 The engine is a service
  2. 40.2 Daily checks
  3. 40.3 Weekly review
  4. 40.4 Quarterly review
  5. 40.5 Change management
  6. 40.6 When to retire
  7. Key Takeaways
  8. Action Steps

41. Walk-Forward Parameter Refinement

  1. 41.1 Refining, not optimizing
  2. 41.2 The rolling re-optimization
  3. 41.3 Stability of chosen parameters
  4. 41.4 The penalty for complexity
  5. 41.5 Out-of-sample aggregation
  6. Key Takeaways
  7. Action Steps

42. The Research Notebook

  1. 42.1 Treat research as a lab notebook
  2. 42.2 What to record per experiment

Each experiment is a markdown file

experiments/2026-01-15-ma-crossover.md

  1. 42.3 Why this matters
  2. 42.4 Linking to code
  3. 42.5 Review cadence
  4. Key Takeaways
  5. Action Steps

43. Psychological Pitfalls in Backtesting

  1. 43.1 The backtest is the easy part
  2. 43.2 Confirmation bias
  3. 43.3 Over-optimism from a single good run
  4. 43.4 Anchoring on a parameter
  5. 43.5 Hindsight bias
  6. 43.6 Sunk cost
  7. Key Takeaways
  8. Action Steps

44. Documentation for Your Engine

  1. 44.1 Code without documentation is a mystery
  2. 44.2 The README
  3. 44.3 Inline comments
  4. 44.4 The strategy brief
  5. 44.5 Change log
  6. Key Takeaways
  7. Action Steps

45. Comparing Your Engine to Reference Results

  1. 45.1 How do you know your engine is right?
  2. 45.2 Choose a reference
  3. 45.3 Reconcile differences
  4. 45.4 The sanity benchmark
  5. Key Takeaways
  6. Action Steps

46. Common Fill Model Errors

  1. 46.1 The fill model is where optimism hides
  2. 46.2 Filling at the close you signaled on
  3. 46.3 Ignoring slippage entirely
  4. 46.4 Limit orders always filling
  5. 46.5 Gap fills at the limit
  6. 46.6 Commission on one side
  7. 46.7 Volume-agnostic sizing
  8. Key Takeaways
  9. Action Steps

47. Trade Logging and Reconciliation

  1. 47.1 Every trade must be recorded
  2. 47.2 Log fields
  3. 47.3 Reconciliation
  4. 47.4 Why reconciliation matters
  5. Key Takeaways
  6. Action Steps

48. The Limits of Backtesting

  1. 48.1 Know what a backtest cannot tell you
  2. 48.1 Past is not future
  3. 48.2 Execution slippage is unknown
  4. 48.3 Your behavior is untested
  5. 48.4 Structural changes
  6. 48.5 The honest conclusion
  7. Key Takeaways
  8. Action Steps

49. A 30-Day Plan to Build Your Engine

  1. 49.1 From zero to a working backtest
  2. 49.2 Week one: skeleton
  3. 49.3 Week two: components
  4. 49.4 Week three: validation
  5. 49.5 Week four: robustness
  6. Key Takeaways
  7. Action Steps

50. Glossary of Engine Internals

  1. 50.1 A quick reference
  2. 50.2 Architecture terms
  3. 50.3 Fill terms
  4. 50.4 Validation terms
  5. 50.5 Risk terms
  6. Key Takeaways
  7. Action Steps

51. Integrating with a Vectorized Research Workflow

  1. 51.1 Best of both worlds
  2. 51.2 The screening stage
  3. 51.3 The validation stage
  4. 51.4 The deployment stage
  5. 51.5 Why not just use event-driven for everything?
  6. Key Takeaways
  7. Action Steps

52. Reporting Results to Stakeholders

  1. 52.1 If you cannot explain it, you do not understand it
  2. 52.2 The one-page summary
  3. 52.3 The equity curve
  4. 52.4 The trade table
  5. 52.5 The assumptions list
  6. 52.6 The caveats
  7. Key Takeaways
  8. Action Steps

53. The Honest Research Mindset

  1. 53.1 The most important tool is skepticism
  2. 53.2 Assume the backtest is wrong until proven otherwise
  3. 53.3 Prefer the boring conclusion
  4. 53.4 Kill your babies
  5. 53.5 Document what does not work
  6. 53.6 The closing principle
  7. Key Takeaways
  8. Action Steps

54. Handling Time Zones and Trading Sessions

  1. 54.1 The clock matters more than you think
  2. 54.2 Session calendars
  3. 54.3 Time zone alignment
  4. 54.4 Overnight gaps
  5. 54.5 After-hours data
  6. Key Takeaways
  7. Action Steps

55. Testing for Survivorship Bias in Your Data

  1. 55.1 The silent killer
  2. 55.2 Test 1: Are delisted symbols present?

Check if any symbol in your data has a delisting date

  1. 55.3 Test 2: Universe as of a past date
  2. 55.4 Test 3: Small-cap performance
  3. 55.5 What to do
  4. Key Takeaways
  5. Action Steps

56. The Research Pipeline as Code

  1. 56.1 Automate the tedious parts
  2. 56.2 The pipeline script
  3. 56.3 Reproducibility
  4. 56.4 Scheduling
  5. 56.5 Versioning results
  6. Key Takeaways
  7. Action Steps

57. Common Questions About Event-Driven Design

  1. 57.1 Why not just use a framework?
  2. 57.2 How fast does Python need to be?
  3. 57.3 How do I test my engine?
  4. 57.4 What data format should I use?
  5. 57.5 How do I handle multiple timeframes?
  6. 57.6 What if my strategy needs fundamental data?
  7. Key Takeaways
  8. Action Steps

58. Performance Attribution by Trade Type

  1. 58.1 Which trades make money
  2. 58.2 By entry reason
  3. 58.3 By exit reason
  4. 58.4 By holding period
  5. 58.5 The insight
  6. Key Takeaways
  7. Action Steps

59. Backtesting on a Budget

  1. 59.1 You do not need expensive data
  2. 59.1 Free data
  3. 59.2 Low-cost upgrades
  4. 59.3 Software
  5. 59.4 The real cost
  6. 59.5 When to upgrade
  7. Key Takeaways
  8. Action Steps

60. The Final Checklist: Are You Ready to Trade?

  1. 60.1 One last gate
  2. 60.2 Engine
  3. 60.3 Data
  4. 60.4 Strategy
  5. 60.5 Costs
  6. 60.6 Risk
  7. 60.7 Process
  8. Key Takeaways
  9. Action Steps

61. Handling Missing Data and Gaps

  1. 61.1 Gaps are normal, but they must be handled
  2. 61.2 Expected gaps
  3. 61.3 Unexpected gaps
  4. 61.4 Suspensions
  5. 61.5 Gaps and position marks
  6. Key Takeaways
  7. Action Steps

62. The Role of Luck in Backtest Results

  1. 62.1 Your best backtest might be luck
  2. 62.2 The number of tests
  3. 62.3 The sample size
  4. 62.4 Out-of-sample confirmation
  5. 62.5 The honest attitude
  6. Key Takeaways
  7. Action Steps

63. Comparing Two Backtests Fairly

  1. 63.1 Which strategy is better?
  2. 63.1 Compare on the same data
  3. 63.2 Compare risk-adjusted returns
  4. 63.3 Compare drawdowns
  5. 63.4 Compare turnover
  6. 63.5 Compare out-of-sample
  7. Key Takeaways
  8. Action Steps

64. The Ethics of Backtesting and Deployment

  1. 64.1 You are responsible for your claims
  2. 64.1 No misleading returns
  3. 64.2 Disclose assumptions
  4. 64.3 Do not sell signals
  5. 64.4 Respect your own risk
  6. 64.5 The closing thought
  7. Key Takeaways
  8. Action Steps

65. The Minimal Engine, Extended: A Worked Example

  1. 65.1 Putting it all together
  2. 65.2 The imports and events
  3. 65.3 The data handler
  4. 65.4 The portfolio
  5. 65.5 The loop
  6. Key Takeaways
  7. Action Steps

66. Scaling from One Symbol to a Portfolio

  1. 66.1 The engine must handle many instruments
  2. 66.1 The data alignment problem
  3. 66.2 The portfolio-level risk
  4. 66.3 The rebalance loop
  5. 66.4 The backtest speed
  6. Key Takeaways
  7. Action Steps

67. Reading Other People’s Backtests Critically

  1. 67.1 Most published backtests are not trustworthy
  2. 67.1 What data was used?
  3. 67.2 Were costs included?
  4. 67.3 Was there an out-of-sample period?
  5. 67.4 How many parameters?
  6. 67.5 The verdict
  7. Key Takeaways
  8. Action Steps

68. The Difference Between Simulation and Reality

  1. 68.1 The gap is the lesson
  2. 68.1 The timing gap
  3. 68.2 The liquidity gap
  4. 68.3 The data gap
  5. 68.4 The behavior gap
  6. 68.5 The lesson
  7. Key Takeaways
  8. Action Steps

69. Your Research Environment as a Product

  1. 69.1 Treat your tools as a product
  2. 69.1 Fast iteration
  3. 69.2 Clear logs
  4. 69.3 Reproducible configs
  5. 69.4 Version control
  6. Key Takeaways
  7. Action Steps

70. The Final Word: Build, Validate, Repeat

  1. 70.1 The loop never ends
  2. 70.1 Build
  3. 70.2 Validate
  4. 70.3 Deploy
  5. 70.4 Refine
  6. 70.5 The mindset
  7. Key Takeaways
  8. Action Steps

71. The Backtest Engineer’s Reading List

  1. 71.1 What to read next
  2. 71.1 Time series analysis
  3. 71.2 Risk management
  4. 71.3 Market microstructure
  5. 71.4 Machine learning for trading
  6. 71.5 The habit
  7. Key Takeaways
  8. Action Steps

72. Common Engine Bug Patterns

  1. 72.1 Bugs are where edges go to die
  2. 72.1 Off-by-one in signal shifting
  3. 72.2 Using adjusted data for unadjusted fills
  4. 72.3 Forgetting commission on one side
  5. 72.4 Position size from cash, not equity
  6. 72.5 Not handling multiple fills per bar
  7. 72.6 Survivorship in the universe
  8. Key Takeaways
  9. Action Steps

73. The Worked Example: A Complete Walk-Through

  1. 73.1 From idea to backtest
  2. 73.1 The idea
  3. 73.2 The mechanism
  4. 73.3 The rules
  5. 73.4 The backtest
  6. 73.5 The validation
  7. 73.6 The conclusion
  8. Key Takeaways
  9. Action Steps

74. The Research Journal: A Practical Template

  1. 74.1 A journal you will actually use
  2. 74.1 The entry format
  3. 74.2 Why this works
  4. 74.3 The monthly review
  5. 74.4 Link to code
  6. Key Takeaways
  7. Action Steps

75. The Backtest Engineer’s Mindset

  1. 75.1 The right attitude makes the engine better
  2. 75.1 Assume you are wrong
  3. 75.2 Prefer simple over complex
  4. 75.3 Measure twice
  5. 75.4 Kill quickly
  6. 75.5 Learn from failure
  7. Key Takeaways
  8. Action Steps

76. The Final Checklist, Expanded

  1. 76.1 A longer checklist for serious deployments
  2. 76.1 Data
  3. 76.2 Engine
  4. 76.3 Strategy
  5. 76.4 Costs
  6. 76.5 Risk
  7. Key Takeaways
  8. Action Steps

77. The Closing: Your Engine, Your Process

  1. 77.1 You now have everything you need
  2. 77.1 Build the engine
  3. 77.2 Validate rigorously
  4. 77.3 Deploy carefully
  5. 77.4 The reward
  6. 77.5 Final thought
  7. Key Takeaways
  8. Action Steps

78. The Backtest Engineer’s Toolkit

  1. 78.1 The tools you need
  2. 78.1 Core software
  3. 78.2 Data tools
  4. 78.3 Engine components
  5. 78.4 Reporting tools
  6. Key Takeaways
  7. Action Steps

79. The Backtest Engineer’s Daily Routine

  1. 79.1 What a disciplined routine looks like
  2. 79.1 Morning
  3. 79.2 Midday
  4. 79.3 Evening
  5. 79.4 Weekly
  6. 79.5 Monthly
  7. Key Takeaways
  8. Action Steps

80. The Final Word on Backtesting

  1. 80.1 This is the end of the book, not the end of the work
  2. 80.1 Build carefully
  3. 80.2 Validate honestly
  4. 80.3 Deploy slowly
  5. 80.4 The reward
  6. 80.5 Goodbye
  7. Key Takeaways
  8. Action Steps

81. Afterword

  1. 81.1 You have the tools
  2. 81.2 Start today
  3. 81.3 Stay honest
  4. 81.4 Good luck
  5. Key Takeaways
  6. Action Steps

82. Final Note

  1. 82.1 Thank you
  2. 82.2 The journey
  3. 82.3 Goodbye
  4. Key Takeaways
  5. Action Steps

Frequently Asked Questions

  1. Should I use an existing backtesting framework instead of building my own?
  2. What is the difference between vectorized and event-driven backtesting?
  3. Why does my backtest look great but paper trading is worse?
  4. How do I prevent look-ahead bias?
  5. What commission model should I use?
  6. How many parameters can I tune?
  7. What is a good Sharpe ratio?
  8. How do I handle dividends in an engine?
  9. What about splits?
  10. How much historical data do I need?
  11. Can I backtest options or futures with this engine?
  12. How do I know if my engine is correct?
  13. Should I trust a perfect-looking equity curve?
  14. What if walk-forward results are inconsistent?
  15. How do I calibrate slippage?
  16. Do I need a fast engine?

Glossary

About the Author

FREE RESOURCES

Disclaimer

How This Book Is Structured

1. Vectorized versus Event-Driven Backtesting

  1. 1.1 Two ways to replay history
  2. 1.2 Vectorized backtesting

A simplified vectorized backtest

  1. 1.3 The limits of vectorization
  2. 1.4 Event-driven backtesting

A tiny event loop skeleton

  1. 1.5 When to use which
  2. 1.6 What this book builds

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub