SlideShare a Scribd company logo
1 of 29
Download to read offline
Should You Build Your Own
Backtester?
Michael Halls-Moore
QuantCon 2016 NYC
About The Talk
● Suitable for beginners to intermediate quants
● Discusses:
– Backtesting pitfalls
– Different types of backtesting methods
– The software landscape
– Whether you should build your own
– Event-driven backtesting design 101
About Me/QuantStart
●
Me:
– Based (near) London
– Background in computational fluid dynamics research
– Started as quant dev in London equity/futures fund
– Key lesson: Vast chasm between backtests and live
trading!
– Very passionate about knowledge sharing and open-
source
●
QuantStart:
– Started in late 2012 (lots has changed in QF since then)
– Topics include trading, careers, data science, ML
– Discusses details that are often ignored, but necessary
– Trying to bring institutional thinking to individual quants
– Provides end-to-end code that can be used immediately
●
Great time to be a quant or data scientist
– Everything is being automated/systematised
– Still need to learn the math(s) and coding though!
What Is A Backtest?
● Trading strategy rules applied to a historical dataset.
● “All [backtests] are wrong, but some are useful.”
● What purpose do they serve?
– Ultimately help decide whether to live-trade a strategy
– Gives us an idea of how a strategy performed in the past
– Allow filtration of bad strategies before live trading
● Backtesting is not live trading
●
Two main types: “For-Loop” or “Event-Driven”
● Backtester design: A trade-off between accuracy and
implementation complexity
Backtesting Pitfalls
The Usual Suspects
● In-sample testing
– Never, ever do this!
● Survivorship bias
– Get better data
● Look-ahead bias
– Very subtle
● Market regime change
– Hard to detect
● Transaction costs:
– Spread
– Fees/commissions
– Market impact
– Slippage
Hiding in plain sight.
Backtesting Pitfalls
Lesser-Spotted Issues
Lurking in the deep, but there to
catch the unwary.
● OHLC data
– Feeds often a mix of multiple exchanges (could
you really have achieved that price?)
– H/L → Don't know it until close!
●
Capacity constraints
– Maximum capital allocation?
– Average Daily Volume (ADV)
● Choice of benchmark
– Does it really reflect your strategy?
●
Robustness to initial condition
●
Overfitting/Bias-Variance Tradeoff
– Big, big problem
– Q: “How to avoid it?”, A: “Extremely difficult!”
●
Psychological tolerance for strategy
– If 50% drawdown is expected from backtests, can
you stomach that in live trading?
●
See Tucker Balch, Ernie Chan and others for
great discussions on these points
For-Loop Backtests
For-Loop Backtests
How do they work?
● For each trading bar (e.g. day/minute)
– do_something_with_price() [e.g. Moving Average
of close]
– buy_or_sell_something() [Often the SAME close]
– next_bar()
For-Loop Backtests
Pros and Cons
● Easy to program
– Can use nearly any coding
language
● Fast to execute
– Can check many parameter
combinations
● Unrealistic
– Often no transaction costs
– Minimal code re-use for live trading
– Immediate market fill at midpoint
● Prone to look-ahead bias
– Is it “i”, “i-1” or “i+1”?
● Should be used as a filtration
mechanism
– Eliminate the obviously bad
– Remain skeptical of the good →
Further research needed!
Advantages Disadvantages
Event-Driven Backtests
Event-Driven Backtests
How do they work?
● While data_still_exists(): [Loop until told otherwise]
– event = get_latest_event() [Think of an “event” as a message]
– If event.type == “tick”: [Market data update]
● calculate_trading_signals(event)
– Else if event.type == “signal”:
● portfolio.handle_signal(event)
– Else if event.type == “order”:
● execution.handle_order(event)
– Else if event.type == “fill”:
● portfolio.handle_fill(event)
– Sleep(10 minutes) [Check market every 10 mins]
Event-Driven Backtests
Pros and Cons
● Tricky to code
– Possibly weeks/months of work
– Healthy market for quant
developers!
● Need an object-oriented language
– Necessary for “modular” design
● Useful to know software engineering
– Logging, unit testing, VCS, CI
● Slower to execute
– Multiple parameter combinations
can take a long time to calculate
Advantages Disadvantages
● Mostly eliminates look-ahead bias
– Event-driven design can't “look ahead”
– Although possible indirect bias through model
● Code re-use
– Only need to “switch out” data and execution
modules for live trading
– Less bugs to fix
● Multiple strategies and instruments
● “Proper” risk and position management
– Kelly criterion/dynamic leverage
– Sector exposures, ADV limits
– Volatility estimates
● Remote deployment and monitoring
– “The cloud” or colocation
Software Landscape
Complex and fragmented...
Software Landscape
For-Loop Backtests
● Mainly open-source, some commercial
● Quant funds/IBs and individual quants use:
– Python (Pandas)
– R (quantmod)
– MatLab
● Plenty of code snippets on quant blogs
– Visit Quantocracy.com and start reading
Software Landscape
Event-Driven Backtests
●
Desktop
– Deltix
– QuantHouse
– Mainly for (some) quant funds, family offices,
prop trading firms
●
Cloud
– Quantopian!
●
Institutional quants?
– They have regulatory constraints, investor
relations, detailed reporting, auditability
– “Nobody ever got fired for choosing IBM”
– Although plenty build their own...
●
Retail quants?
– Cloud & data? → Go with Quantopian
– Roll your own? → AWS & really good data
source(s)!
Commercial Free/Open Source
● Many to choose from...
– Zipline (Quantopian)
– PyAlgoTrade
– PySystemTrade (Rob Carver)
– QSTrader (Me)
– C++ → Only if you need the speed...
● But...use good data
– Else, it's “garbage in, garbage out”
Programming Languages?
● Shouldn't be interested in “language wars” – only so many hours in the day!
● We just want to use what works
● Python
– Standard library talks to everything
– Great quant/data science/ML libraries
– Could be better on classical stats and TSA
– For-loop AND event-driven backtesting
– Can perform end-to-end research,
backtesting, deployment, live trading,
reporting and monitoring
– Could be faster...
● R
– Great for time series, classical and
Bayesian stats, ML, plotting
– Great for for-loop backtesting, not good for
event-driven or live trading
● C++
– Really, really fast
– Painful (compared to Python) for
loading/reading/formatting data
– Used in higher frequency trading and
legacy systems at funds, banks
– C++11/C++14 brought in useful new
features
● Others?
– Java, Scala, C#, Julia, [functional...]
Should You Write Your Own
(Event-Driven) Backtester?
● Answer: Yes! → It is a great learning experience
● Forces you to consider all aspects of trading system
– And the questions you should be asking of commercial/FOSS vendors...
● For example: How does your current live system differ from your
backtest simulation in terms of:
– Algorithmic execution and order routing?
– Spread, fees, slippage and market impact?
– Risk management and position sizing?
● Not easy or quick to write, but it will pay huge educational
dividends later in your quant trading
How Do You Write Your Own
(Event-Driven) Backtester?
● Download zipline, QSTrader, PyAlgoTrade,
PySystemTrade etc.
– Try reading through the documentation and code!
– Python is almost like reading pseudo-code
● Visit QuantStart and Investment Idiocy for
detailed articles on event-driven backtesting
● You don't have to be an expert on day #1!
– Take it slowly, module-by-module
Event-Driven Backtest Design 101
It's not (quite) rocket science...
Common Event-Driven
Backtest Modules
● Securities Master Database
● Trading Strategies
● Portfolio & Order Management System
● Risk & Position Management
● Execution Handling
● Performance & Reporting
● System Deployment & Monitoring
Securities Master Database
● Not just a CSV file from Yahoo Finance!
● Use a “First class” database/file system
– PostgreSQL/MySQL/SQL Server
– HDF5
● Ideally want to obtain and store tick data
– Bid/ask (for spreads)
– Can then make your own OHLC bars, if desired
● Must be aware of:
– Corporate actions (painful and time-consuming)
– Survivorship bias (de-listing)
– Timezones, various exchanges
● Individual quants can compete
– Database technologies are free and mature
– Data is becoming cheaper and “democratised”
(e.g. Quandl)
– Plenty of strategies that are “too small” for funds
Quants need good data.
Trading Strategies
● Generally runs a prediction or
filtering mechanism on new data
● Receives a tick signal “on_tick()”
– Produces a trading signal, e.g. “buy
GOOG at market”
– Notice no quantity – that's done
elsewhere!
● 95% of quant blog discussion is about
trading strategies
– I think it should be more like 20%
– Returns can often be improved
significantly by spending more time on
risk management, position sizing
Just read the crop report!
Portfolio & Order Management
● “Heart” of the event-driven backtester
– Requires extensive dev time and testing
● Goal is to get from the current
portfolio to desired portfolio
– Minimise risk and costs while doing it
● Ties together strategy, risk, position
and order execution
● Also carries out position handling
calculations for backtesting
● Allows a variety of financial
instruments in a single portfolio
– Necessary for institutional-style portfolios
with hedging
– This is very tricky with a for-loop backtester
I [(x^2 + y^2 -1)^3 – x^2 y^3 = 0]
backtesting.
Risk & Position Management
● Risk module can modify, add or veto orders
– Add hedges to maintain market neutrality
– Reduce order sizes (sector exposure or ADV limits)
– Spread could be too wide (or fees too large), for a
minor incremental change, so don't trade
● Position sizing for dynamic leverage
– Kelly leverage (and other portfolio optimisation)
– Volatility estimation
● Under-represented in quant blogosphere
– Biggest difference between how institutional and
some individual quants “think” about trading
– Simplest way to try and get better returns?
Implement risk management and position sizing
The HAL9000 risk manager.
Execution Handling
AKA Transaction Cost Handling
● NOT guaranteed market fill at
midpoint!
● Must consider capacity, spread,
fees, slippage, market impact,
algorithmic execution
– Otherwise returns will be vastly overstated
● Should be able to switch
BacktestExecutionHandler with
LiveExecutionHandler and deploy
● Easily add multiple brokerages
– Use OOP concept of “inheritance”
● Nobody enjoys writing code against
poorly-documented brokerage APIs!
– Have a policy of “trust but verify” when
using third-party libraries
– The devil is in the details...
Optimal execution.
Performance & Reporting
● Retail quants can borrow sophisticated
reporting techniques from institutional quants
– Live “dashboards” of portfolio and risk state
– Current “backtest equity” vs “live equity” difference
– Key metrics: Costs per trade, returns distribution, HWM,
max DD, avg latency, alpha/beta, benchmark
comparison
● Consistent incremental improvements to
infrastructure
– Can really enhance returns over the long term
– Don't just consider the world's greatest strategy (WGS)
● WGS will eventually erode due to “alpha decay”
– Robust trading infrastructure, and continual research
into new strategies will always pay dividends
● Infrastructure more “boring” than strategies?
– Less boring when returns are improved!
Not the WGS.
Deployment & Monitoring
● Crucial for “institutional-grade” systems
– But individual quants can use these ideas too!
● A robust system must be remotely deployed
in “the cloud” or colocated
– Sub-optimal idea to use home desktop/laptop for
algo trading
●
Main issues:
– Hardware monitoring (CPU, RAM/swap, disk, I/O)
– High-availability/redundancy
– Backup AND restoration plan
– Log everything (Python has “logging” module)
– Continuous integration, unit testing, VCS
– Murphy's Law: “If it can fail it will fail.”
● Many vendors:
– Cloud: Amazon, Microsoft, Google, Rackspace
– VCS/Logging: Github, Bitbucket, Loggly, Splunk
“Murphy's Law.”
Final Thoughts
● No “quick fix” in quant trading – must work hard and learn a lot
● Don't concentrate too much on the best “strategy”
– It will eventually decay
– Continually research many new strategies
– Always have the “strategy pipeline” full
● Invest time in your infrastructure and it can improve your returns
● Write your own backtester to learn
– Either: Use it and continually improve it
– Or: Find a vendor and then ask lots of questions
● Always be reading, learning and improving
– Textbooks, arXiv, SSRN, quant blogs, academic journals, trade journals
Thanks to everyone for listening
and to Quantopian for hosting!
Questions?

More Related Content

What's hot

Backtesting And Live Trading With Interactive Brokers Using Python With Dr. H...
Backtesting And Live Trading With Interactive Brokers Using Python With Dr. H...Backtesting And Live Trading With Interactive Brokers Using Python With Dr. H...
Backtesting And Live Trading With Interactive Brokers Using Python With Dr. H...
QuantInsti
 
The QuantCon Keynote: "Counter Trend Trading – Threat or Complement to Trend ...
The QuantCon Keynote: "Counter Trend Trading – Threat or Complement to Trend ...The QuantCon Keynote: "Counter Trend Trading – Threat or Complement to Trend ...
The QuantCon Keynote: "Counter Trend Trading – Threat or Complement to Trend ...
Quantopian
 

What's hot (20)

"Quant Trading for a Living – Lessons from a Life in the Trenches" by Andreas...
"Quant Trading for a Living – Lessons from a Life in the Trenches" by Andreas..."Quant Trading for a Living – Lessons from a Life in the Trenches" by Andreas...
"Quant Trading for a Living – Lessons from a Life in the Trenches" by Andreas...
 
"From Trading Strategy to Becoming an Industry Professional – How to Break in...
"From Trading Strategy to Becoming an Industry Professional – How to Break in..."From Trading Strategy to Becoming an Industry Professional – How to Break in...
"From Trading Strategy to Becoming an Industry Professional – How to Break in...
 
Volatility Trading - Hedge Fund Strategies
Volatility Trading - Hedge Fund StrategiesVolatility Trading - Hedge Fund Strategies
Volatility Trading - Hedge Fund Strategies
 
Backtesting And Live Trading With Interactive Brokers Using Python With Dr. H...
Backtesting And Live Trading With Interactive Brokers Using Python With Dr. H...Backtesting And Live Trading With Interactive Brokers Using Python With Dr. H...
Backtesting And Live Trading With Interactive Brokers Using Python With Dr. H...
 
Classification of quantitative trading strategies webinar ppt
Classification of quantitative trading strategies webinar pptClassification of quantitative trading strategies webinar ppt
Classification of quantitative trading strategies webinar ppt
 
"A Framework for Developing Trading Models Based on Machine Learning" by Kris...
"A Framework for Developing Trading Models Based on Machine Learning" by Kris..."A Framework for Developing Trading Models Based on Machine Learning" by Kris...
"A Framework for Developing Trading Models Based on Machine Learning" by Kris...
 
"The 6 Stages of a Quant Equity Workflow" by Dr. Jessica Stauth, Vice Preside...
"The 6 Stages of a Quant Equity Workflow" by Dr. Jessica Stauth, Vice Preside..."The 6 Stages of a Quant Equity Workflow" by Dr. Jessica Stauth, Vice Preside...
"The 6 Stages of a Quant Equity Workflow" by Dr. Jessica Stauth, Vice Preside...
 
"Fundamental Forecasts: Methods and Timing" by Vinesh Jha, CEO of ExtractAlpha
"Fundamental Forecasts: Methods and Timing" by Vinesh Jha, CEO of ExtractAlpha"Fundamental Forecasts: Methods and Timing" by Vinesh Jha, CEO of ExtractAlpha
"Fundamental Forecasts: Methods and Timing" by Vinesh Jha, CEO of ExtractAlpha
 
"Portfolio Optimisation When You Don’t Know the Future (or the Past)" by Rob...
"Portfolio Optimisation When You Don’t Know the Future (or the Past)" by Rob..."Portfolio Optimisation When You Don’t Know the Future (or the Past)" by Rob...
"Portfolio Optimisation When You Don’t Know the Future (or the Past)" by Rob...
 
The QuantCon Keynote: "Counter Trend Trading – Threat or Complement to Trend ...
The QuantCon Keynote: "Counter Trend Trading – Threat or Complement to Trend ...The QuantCon Keynote: "Counter Trend Trading – Threat or Complement to Trend ...
The QuantCon Keynote: "Counter Trend Trading – Threat or Complement to Trend ...
 
Statistics - The Missing Link Between Technical Analysis and Algorithmic Trad...
Statistics - The Missing Link Between Technical Analysis and Algorithmic Trad...Statistics - The Missing Link Between Technical Analysis and Algorithmic Trad...
Statistics - The Missing Link Between Technical Analysis and Algorithmic Trad...
 
Algo Trading
Algo TradingAlgo Trading
Algo Trading
 
Algorithmic Trading: an Overview
Algorithmic Trading: an Overview Algorithmic Trading: an Overview
Algorithmic Trading: an Overview
 
Core Master Trading Strategies
Core Master Trading StrategiesCore Master Trading Strategies
Core Master Trading Strategies
 
Quantitative Trading
Quantitative TradingQuantitative Trading
Quantitative Trading
 
QuantConnect - Options Backtesting
QuantConnect - Options BacktestingQuantConnect - Options Backtesting
QuantConnect - Options Backtesting
 
Master trend-following
Master trend-followingMaster trend-following
Master trend-following
 
Algorithmic trading
Algorithmic tradingAlgorithmic trading
Algorithmic trading
 
What deep learning can bring to...
What deep learning can bring to...What deep learning can bring to...
What deep learning can bring to...
 
"How to Run a Quantitative Trading Business in China with Python" by Xiaoyou ...
"How to Run a Quantitative Trading Business in China with Python" by Xiaoyou ..."How to Run a Quantitative Trading Business in China with Python" by Xiaoyou ...
"How to Run a Quantitative Trading Business in China with Python" by Xiaoyou ...
 

Viewers also liked

Viewers also liked (20)

Trading Strategies Based on Market Impact of Macroeconomic Announcements by A...
Trading Strategies Based on Market Impact of Macroeconomic Announcementsby A...Trading Strategies Based on Market Impact of Macroeconomic Announcementsby A...
Trading Strategies Based on Market Impact of Macroeconomic Announcements by A...
 
Trade Like a Chimp: Unleash Your Inner Primate by Andreas Clenow at QuantCon ...
Trade Like a Chimp: Unleash Your Inner Primate by Andreas Clenow at QuantCon ...Trade Like a Chimp: Unleash Your Inner Primate by Andreas Clenow at QuantCon ...
Trade Like a Chimp: Unleash Your Inner Primate by Andreas Clenow at QuantCon ...
 
This Illegally Collected Data Set Produced More Alpha for Hedge Funds by Leig...
This Illegally Collected Data Set Produced More Alpha for Hedge Funds by Leig...This Illegally Collected Data Set Produced More Alpha for Hedge Funds by Leig...
This Illegally Collected Data Set Produced More Alpha for Hedge Funds by Leig...
 
The Sustainable Active Investing Framework: Simple, but Not Easy by Wesley Gr...
The Sustainable Active Investing Framework: Simple, but Not Easy by Wesley Gr...The Sustainable Active Investing Framework: Simple, but Not Easy by Wesley Gr...
The Sustainable Active Investing Framework: Simple, but Not Easy by Wesley Gr...
 
Market Timing, Big Data, and Machine Learning by Xiao Qiao at QuantCon 2016
Market Timing, Big Data, and Machine Learning by Xiao Qiao at QuantCon 2016Market Timing, Big Data, and Machine Learning by Xiao Qiao at QuantCon 2016
Market Timing, Big Data, and Machine Learning by Xiao Qiao at QuantCon 2016
 
Combining the Best Stock Selection Factors by Patrick O'Shaughnessy at QuantC...
Combining the Best Stock Selection Factors by Patrick O'Shaughnessy at QuantC...Combining the Best Stock Selection Factors by Patrick O'Shaughnessy at QuantC...
Combining the Best Stock Selection Factors by Patrick O'Shaughnessy at QuantC...
 
A Vision for Quantitative Investing in the Data Economy by Michael Beal at Qu...
A Vision for Quantitative Investing in the Data Economy by Michael Beal at Qu...A Vision for Quantitative Investing in the Data Economy by Michael Beal at Qu...
A Vision for Quantitative Investing in the Data Economy by Michael Beal at Qu...
 
Financial Engineering and Its Discontents by Emanuel Derman at QuantCon 2016
Financial Engineering and Its Discontents by Emanuel Derman at QuantCon 2016Financial Engineering and Its Discontents by Emanuel Derman at QuantCon 2016
Financial Engineering and Its Discontents by Emanuel Derman at QuantCon 2016
 
Honey, I Deep-shrunk the Sample Covariance Matrix! by Erk Subasi at QuantCon ...
Honey, I Deep-shrunk the Sample Covariance Matrix! by Erk Subasi at QuantCon ...Honey, I Deep-shrunk the Sample Covariance Matrix! by Erk Subasi at QuantCon ...
Honey, I Deep-shrunk the Sample Covariance Matrix! by Erk Subasi at QuantCon ...
 
A Guided Tour of Machine Learning for Traders by Tucker Balch at QuantCon 2016
A Guided Tour of Machine Learning for Traders by Tucker Balch at QuantCon 2016A Guided Tour of Machine Learning for Traders by Tucker Balch at QuantCon 2016
A Guided Tour of Machine Learning for Traders by Tucker Balch at QuantCon 2016
 
Needle in the Haystack by Anshul Vikram Pandey at QuantCon 2016
Needle in the Haystack by Anshul Vikram Pandey at QuantCon 2016Needle in the Haystack by Anshul Vikram Pandey at QuantCon 2016
Needle in the Haystack by Anshul Vikram Pandey at QuantCon 2016
 
Light up Your Dark Data by Lance Ransom at QuantCon 2016
Light up Your Dark Data by Lance Ransom at QuantCon 2016Light up Your Dark Data by Lance Ransom at QuantCon 2016
Light up Your Dark Data by Lance Ransom at QuantCon 2016
 
Latency in Automated Trading Systems by Andrei Kirilenko at QuantCon 2016
Latency in Automated Trading Systems by Andrei Kirilenko at QuantCon 2016Latency in Automated Trading Systems by Andrei Kirilenko at QuantCon 2016
Latency in Automated Trading Systems by Andrei Kirilenko at QuantCon 2016
 
The Evolution of Social Listening for Capital Markets by Chris Camillo at Qua...
The Evolution of Social Listening for Capital Markets by Chris Camillo at Qua...The Evolution of Social Listening for Capital Markets by Chris Camillo at Qua...
The Evolution of Social Listening for Capital Markets by Chris Camillo at Qua...
 
Dual Momentum Investing by Gary Antonacci QuantCon 2016
Dual Momentum Investing by Gary Antonacci QuantCon 2016Dual Momentum Investing by Gary Antonacci QuantCon 2016
Dual Momentum Investing by Gary Antonacci QuantCon 2016
 
Empowering Quants in the Data Economy by Napoleon Hernandez at QuantCon 2016
Empowering Quants in the Data Economy by Napoleon Hernandez at QuantCon 2016Empowering Quants in the Data Economy by Napoleon Hernandez at QuantCon 2016
Empowering Quants in the Data Economy by Napoleon Hernandez at QuantCon 2016
 
From Backtesting to Live Trading by Vesna Straser at QuantCon 2016
From Backtesting to Live Trading by Vesna Straser at QuantCon 2016From Backtesting to Live Trading by Vesna Straser at QuantCon 2016
From Backtesting to Live Trading by Vesna Straser at QuantCon 2016
 
Welcome to QuantCon 2016 John "fawce" Fawcett, Founder and CEO of Quantopian
Welcome to QuantCon 2016 John "fawce" Fawcett, Founder and CEO of QuantopianWelcome to QuantCon 2016 John "fawce" Fawcett, Founder and CEO of Quantopian
Welcome to QuantCon 2016 John "fawce" Fawcett, Founder and CEO of Quantopian
 
Meb Faber at QuantCon 2016
Meb Faber at QuantCon 2016Meb Faber at QuantCon 2016
Meb Faber at QuantCon 2016
 
Deep Value and the Aquirer's Multiple by Tobias Carlisle for QuantCon 2016
Deep Value and the Aquirer's Multiple by Tobias Carlisle for QuantCon 2016Deep Value and the Aquirer's Multiple by Tobias Carlisle for QuantCon 2016
Deep Value and the Aquirer's Multiple by Tobias Carlisle for QuantCon 2016
 

Similar to Should You Build Your Own Backtester? by Michael Halls-Moore at QuantCon 2016

Groovy On The Trading Desk
Groovy On The Trading DeskGroovy On The Trading Desk
Groovy On The Trading Desk
Jonathan Felch
 
Architecting large systems
Architecting large systemsArchitecting large systems
Architecting large systems
Simon Farrell
 
Doing Enterprise Business with Processes & Rules
Doing Enterprise Business with Processes & RulesDoing Enterprise Business with Processes & Rules
Doing Enterprise Business with Processes & Rules
Srinath Perera
 

Similar to Should You Build Your Own Backtester? by Michael Halls-Moore at QuantCon 2016 (20)

Groovy On The Trading Desk
Groovy On The Trading DeskGroovy On The Trading Desk
Groovy On The Trading Desk
 
Intro to Quantitative Investment (Lecture 2 of 6)
Intro to Quantitative Investment (Lecture 2 of 6)Intro to Quantitative Investment (Lecture 2 of 6)
Intro to Quantitative Investment (Lecture 2 of 6)
 
Architecting large systems
Architecting large systemsArchitecting large systems
Architecting large systems
 
Notes for Computational Finance lectures, Antoine Savine at Copenhagen Univer...
Notes for Computational Finance lectures, Antoine Savine at Copenhagen Univer...Notes for Computational Finance lectures, Antoine Savine at Copenhagen Univer...
Notes for Computational Finance lectures, Antoine Savine at Copenhagen Univer...
 
When to Code / Config / Config + Code in Salesforce - Nikunj Doshi
When to Code / Config / Config + Code in Salesforce - Nikunj DoshiWhen to Code / Config / Config + Code in Salesforce - Nikunj Doshi
When to Code / Config / Config + Code in Salesforce - Nikunj Doshi
 
How to Manage a Mixed Portfolio of Products by Salesforce PM
How to Manage a Mixed Portfolio of Products by Salesforce PMHow to Manage a Mixed Portfolio of Products by Salesforce PM
How to Manage a Mixed Portfolio of Products by Salesforce PM
 
Maximizing Big Data ROI via Best of Breed Technology Patterns and Practices -...
Maximizing Big Data ROI via Best of Breed Technology Patterns and Practices -...Maximizing Big Data ROI via Best of Breed Technology Patterns and Practices -...
Maximizing Big Data ROI via Best of Breed Technology Patterns and Practices -...
 
Strangle The Monolith: A Data Driven Approach
Strangle The Monolith: A Data Driven ApproachStrangle The Monolith: A Data Driven Approach
Strangle The Monolith: A Data Driven Approach
 
Doing Enterprise Business with Processes & Rules
Doing Enterprise Business with Processes & RulesDoing Enterprise Business with Processes & Rules
Doing Enterprise Business with Processes & Rules
 
"The Hunt For Alpha Among Alternative Data Sources" by Dr. Michael Halls-Moor...
"The Hunt For Alpha Among Alternative Data Sources" by Dr. Michael Halls-Moor..."The Hunt For Alpha Among Alternative Data Sources" by Dr. Michael Halls-Moor...
"The Hunt For Alpha Among Alternative Data Sources" by Dr. Michael Halls-Moor...
 
Including ecommerce in your business model landmann
Including ecommerce in your business model   landmannIncluding ecommerce in your business model   landmann
Including ecommerce in your business model landmann
 
L10 Architecture Considerations
L10 Architecture ConsiderationsL10 Architecture Considerations
L10 Architecture Considerations
 
2019-12-WWC-Toronto.pdf
2019-12-WWC-Toronto.pdf2019-12-WWC-Toronto.pdf
2019-12-WWC-Toronto.pdf
 
Piotr Karwatka - Managing IT project with no doubts. How to work with Agency,...
Piotr Karwatka - Managing IT project with no doubts. How to work with Agency,...Piotr Karwatka - Managing IT project with no doubts. How to work with Agency,...
Piotr Karwatka - Managing IT project with no doubts. How to work with Agency,...
 
Converged Systems Sales Playbook
Converged Systems Sales PlaybookConverged Systems Sales Playbook
Converged Systems Sales Playbook
 
7 things to consider when choosing your IaaS provider for ISV/SaaS
7 things to consider when choosing your IaaS provider for ISV/SaaS7 things to consider when choosing your IaaS provider for ISV/SaaS
7 things to consider when choosing your IaaS provider for ISV/SaaS
 
Financial Modeling
Financial ModelingFinancial Modeling
Financial Modeling
 
The First Kilometre: Building a Back-End That Sets You Up For Success
The First Kilometre: Building a Back-End That Sets You Up For Success The First Kilometre: Building a Back-End That Sets You Up For Success
The First Kilometre: Building a Back-End That Sets You Up For Success
 
Bitcoin Price Predictions and Machine Learning: Some New Ideas and Results
Bitcoin Price Predictions and Machine Learning: Some New Ideas and ResultsBitcoin Price Predictions and Machine Learning: Some New Ideas and Results
Bitcoin Price Predictions and Machine Learning: Some New Ideas and Results
 
Wall Street Derivative Risk Solutions Using Apache Geode
Wall Street Derivative Risk Solutions Using Apache GeodeWall Street Derivative Risk Solutions Using Apache Geode
Wall Street Derivative Risk Solutions Using Apache Geode
 

More from Quantopian

"From Insufficient Economic data to Economic Big Data – How Trade Data is red...
"From Insufficient Economic data to Economic Big Data – How Trade Data is red..."From Insufficient Economic data to Economic Big Data – How Trade Data is red...
"From Insufficient Economic data to Economic Big Data – How Trade Data is red...
Quantopian
 

More from Quantopian (20)

Being open (source) in the traditionally secretive field of quant finance.
Being open (source) in the traditionally secretive field of quant finance.Being open (source) in the traditionally secretive field of quant finance.
Being open (source) in the traditionally secretive field of quant finance.
 
Stauth common pitfalls_stock_market_modeling_pqtc_fall2018
Stauth common pitfalls_stock_market_modeling_pqtc_fall2018Stauth common pitfalls_stock_market_modeling_pqtc_fall2018
Stauth common pitfalls_stock_market_modeling_pqtc_fall2018
 
Tearsheet feedback webinar 10.10.18
Tearsheet feedback webinar 10.10.18Tearsheet feedback webinar 10.10.18
Tearsheet feedback webinar 10.10.18
 
"Three Dimensional Time: Working with Alternative Data" by Kathryn Glowinski,...
"Three Dimensional Time: Working with Alternative Data" by Kathryn Glowinski,..."Three Dimensional Time: Working with Alternative Data" by Kathryn Glowinski,...
"Three Dimensional Time: Working with Alternative Data" by Kathryn Glowinski,...
 
"Alpha from Alternative Data" by Emmett Kilduff, Founder and CEO of Eagle Alpha
"Alpha from Alternative Data" by Emmett Kilduff,  Founder and CEO of Eagle Alpha"Alpha from Alternative Data" by Emmett Kilduff,  Founder and CEO of Eagle Alpha
"Alpha from Alternative Data" by Emmett Kilduff, Founder and CEO of Eagle Alpha
 
"Supply Chain Earnings Diffusion" by Josh Holcroft, Head of Quantitative Rese...
"Supply Chain Earnings Diffusion" by Josh Holcroft, Head of Quantitative Rese..."Supply Chain Earnings Diffusion" by Josh Holcroft, Head of Quantitative Rese...
"Supply Chain Earnings Diffusion" by Josh Holcroft, Head of Quantitative Rese...
 
“Real Time Machine Learning Architecture and Sentiment Analysis Applied to Fi...
“Real Time Machine Learning Architecture and Sentiment Analysis Applied to Fi...“Real Time Machine Learning Architecture and Sentiment Analysis Applied to Fi...
“Real Time Machine Learning Architecture and Sentiment Analysis Applied to Fi...
 
“Market Insights Through the Lens of a Risk Model” by Olivier d'Assier, Head ...
“Market Insights Through the Lens of a Risk Model” by Olivier d'Assier, Head ...“Market Insights Through the Lens of a Risk Model” by Olivier d'Assier, Head ...
“Market Insights Through the Lens of a Risk Model” by Olivier d'Assier, Head ...
 
"Maximize Alpha with Systematic Factor Testing" by Cheng Peng, Software Engin...
"Maximize Alpha with Systematic Factor Testing" by Cheng Peng, Software Engin..."Maximize Alpha with Systematic Factor Testing" by Cheng Peng, Software Engin...
"Maximize Alpha with Systematic Factor Testing" by Cheng Peng, Software Engin...
 
"From Alpha Discovery to Portfolio Construction: Pitfalls and Solutions" by D...
"From Alpha Discovery to Portfolio Construction: Pitfalls and Solutions" by D..."From Alpha Discovery to Portfolio Construction: Pitfalls and Solutions" by D...
"From Alpha Discovery to Portfolio Construction: Pitfalls and Solutions" by D...
 
"Deep Reinforcement Learning for Optimal Order Placement in a Limit Order Boo...
"Deep Reinforcement Learning for Optimal Order Placement in a Limit Order Boo..."Deep Reinforcement Learning for Optimal Order Placement in a Limit Order Boo...
"Deep Reinforcement Learning for Optimal Order Placement in a Limit Order Boo...
 
"Making the Grade: A Look Inside the Algorithm Evaluation Process" by Dr. Jes...
"Making the Grade: A Look Inside the Algorithm Evaluation Process" by Dr. Jes..."Making the Grade: A Look Inside the Algorithm Evaluation Process" by Dr. Jes...
"Making the Grade: A Look Inside the Algorithm Evaluation Process" by Dr. Jes...
 
"Building Diversified Portfolios that Outperform Out-of-Sample" by Dr. Marcos...
"Building Diversified Portfolios that Outperform Out-of-Sample" by Dr. Marcos..."Building Diversified Portfolios that Outperform Out-of-Sample" by Dr. Marcos...
"Building Diversified Portfolios that Outperform Out-of-Sample" by Dr. Marcos...
 
"From Insufficient Economic data to Economic Big Data – How Trade Data is red...
"From Insufficient Economic data to Economic Big Data – How Trade Data is red..."From Insufficient Economic data to Economic Big Data – How Trade Data is red...
"From Insufficient Economic data to Economic Big Data – How Trade Data is red...
 
"Machine Learning Approaches to Regime-aware Portfolio Management" by Michael...
"Machine Learning Approaches to Regime-aware Portfolio Management" by Michael..."Machine Learning Approaches to Regime-aware Portfolio Management" by Michael...
"Machine Learning Approaches to Regime-aware Portfolio Management" by Michael...
 
"Don't Lose Your Shirt Trading Mean-Reversion" by Edith Mandel, Principal at ...
"Don't Lose Your Shirt Trading Mean-Reversion" by Edith Mandel, Principal at ..."Don't Lose Your Shirt Trading Mean-Reversion" by Edith Mandel, Principal at ...
"Don't Lose Your Shirt Trading Mean-Reversion" by Edith Mandel, Principal at ...
 
"Deep Q-Learning for Trading" by Dr. Tucker Balch, Professor of Interactive C...
"Deep Q-Learning for Trading" by Dr. Tucker Balch, Professor of Interactive C..."Deep Q-Learning for Trading" by Dr. Tucker Balch, Professor of Interactive C...
"Deep Q-Learning for Trading" by Dr. Tucker Balch, Professor of Interactive C...
 
"Quantum Hierarchical Risk Parity - A Quantum-Inspired Approach to Portfolio ...
"Quantum Hierarchical Risk Parity - A Quantum-Inspired Approach to Portfolio ..."Quantum Hierarchical Risk Parity - A Quantum-Inspired Approach to Portfolio ...
"Quantum Hierarchical Risk Parity - A Quantum-Inspired Approach to Portfolio ...
 
"Snake Oil, Swamp Land, and Factor-Based Investing" by Gary Antonacci, author...
"Snake Oil, Swamp Land, and Factor-Based Investing" by Gary Antonacci, author..."Snake Oil, Swamp Land, and Factor-Based Investing" by Gary Antonacci, author...
"Snake Oil, Swamp Land, and Factor-Based Investing" by Gary Antonacci, author...
 
"Bayesian Deep Learning: Dealing with Uncertainty and Non-Stationarity" by Dr...
"Bayesian Deep Learning: Dealing with Uncertainty and Non-Stationarity" by Dr..."Bayesian Deep Learning: Dealing with Uncertainty and Non-Stationarity" by Dr...
"Bayesian Deep Learning: Dealing with Uncertainty and Non-Stationarity" by Dr...
 

Recently uploaded

TriStar Gold- 05-13-2024 corporate presentation
TriStar Gold- 05-13-2024 corporate presentationTriStar Gold- 05-13-2024 corporate presentation
TriStar Gold- 05-13-2024 corporate presentation
Adnet Communications
 
Obat Penggugur Kandungan Aman Bagi Ibu Menyusui 087776558899
Obat Penggugur Kandungan Aman Bagi Ibu Menyusui  087776558899Obat Penggugur Kandungan Aman Bagi Ibu Menyusui  087776558899
Obat Penggugur Kandungan Aman Bagi Ibu Menyusui 087776558899
Cara Menggugurkan Kandungan 087776558899
 

Recently uploaded (20)

TriStar Gold- 05-13-2024 corporate presentation
TriStar Gold- 05-13-2024 corporate presentationTriStar Gold- 05-13-2024 corporate presentation
TriStar Gold- 05-13-2024 corporate presentation
 
Famous Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist i...
Famous Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist i...Famous Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist i...
Famous Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist i...
 
Famous Kala Jadu, Black magic expert in Oman Or Kala ilam expert in Kuwait
Famous Kala Jadu, Black magic expert in Oman Or Kala ilam expert in KuwaitFamous Kala Jadu, Black magic expert in Oman Or Kala ilam expert in Kuwait
Famous Kala Jadu, Black magic expert in Oman Or Kala ilam expert in Kuwait
 
20240514-Calibre-Q1-2024-Conference-Call-Presentation.pdf
20240514-Calibre-Q1-2024-Conference-Call-Presentation.pdf20240514-Calibre-Q1-2024-Conference-Call-Presentation.pdf
20240514-Calibre-Q1-2024-Conference-Call-Presentation.pdf
 
Premium Call Girls bhadrachalam 🧿 6378878445 🧿 High Class Call Girl Service A...
Premium Call Girls bhadrachalam 🧿 6378878445 🧿 High Class Call Girl Service A...Premium Call Girls bhadrachalam 🧿 6378878445 🧿 High Class Call Girl Service A...
Premium Call Girls bhadrachalam 🧿 6378878445 🧿 High Class Call Girl Service A...
 
asli amil baba bengali black magic kala jadu expert in uk usa canada france c...
asli amil baba bengali black magic kala jadu expert in uk usa canada france c...asli amil baba bengali black magic kala jadu expert in uk usa canada france c...
asli amil baba bengali black magic kala jadu expert in uk usa canada france c...
 
najoomi asli amil baba kala jadu expert rawalpindi bangladesh uk usa
najoomi asli amil baba kala jadu expert rawalpindi bangladesh uk usanajoomi asli amil baba kala jadu expert rawalpindi bangladesh uk usa
najoomi asli amil baba kala jadu expert rawalpindi bangladesh uk usa
 
Shrambal_Distributors_Newsletter_May-2024.pdf
Shrambal_Distributors_Newsletter_May-2024.pdfShrambal_Distributors_Newsletter_May-2024.pdf
Shrambal_Distributors_Newsletter_May-2024.pdf
 
Production and Cost of the firm with curves
Production and Cost of the firm with curvesProduction and Cost of the firm with curves
Production and Cost of the firm with curves
 
Certified Kala Jadu, Black magic specialist in Rawalpindi and Bangali Amil ba...
Certified Kala Jadu, Black magic specialist in Rawalpindi and Bangali Amil ba...Certified Kala Jadu, Black magic specialist in Rawalpindi and Bangali Amil ba...
Certified Kala Jadu, Black magic specialist in Rawalpindi and Bangali Amil ba...
 
Call Girl In Siliguri 💯Niamh 📲🔝6378878445🔝Call Girls No💰Advance Cash On Deliv...
Call Girl In Siliguri 💯Niamh 📲🔝6378878445🔝Call Girls No💰Advance Cash On Deliv...Call Girl In Siliguri 💯Niamh 📲🔝6378878445🔝Call Girls No💰Advance Cash On Deliv...
Call Girl In Siliguri 💯Niamh 📲🔝6378878445🔝Call Girls No💰Advance Cash On Deliv...
 
Black magic specialist in Canada (Kala ilam specialist in UK) Bangali Amil ba...
Black magic specialist in Canada (Kala ilam specialist in UK) Bangali Amil ba...Black magic specialist in Canada (Kala ilam specialist in UK) Bangali Amil ba...
Black magic specialist in Canada (Kala ilam specialist in UK) Bangali Amil ba...
 
Pitch-deck CopyFinancial and MemberForex.ppsx
Pitch-deck CopyFinancial and MemberForex.ppsxPitch-deck CopyFinancial and MemberForex.ppsx
Pitch-deck CopyFinancial and MemberForex.ppsx
 
DIGITAL COMMERCE SHAPE VIETNAMESE SHOPPING HABIT IN 4.0 INDUSTRY
DIGITAL COMMERCE SHAPE VIETNAMESE SHOPPING HABIT IN 4.0 INDUSTRYDIGITAL COMMERCE SHAPE VIETNAMESE SHOPPING HABIT IN 4.0 INDUSTRY
DIGITAL COMMERCE SHAPE VIETNAMESE SHOPPING HABIT IN 4.0 INDUSTRY
 
Abhay Bhutada: Driving Digital Transformation in NBFC Sector
Abhay Bhutada: Driving Digital Transformation in NBFC SectorAbhay Bhutada: Driving Digital Transformation in NBFC Sector
Abhay Bhutada: Driving Digital Transformation in NBFC Sector
 
Bank of Tomorrow White Paper For Reading
Bank of Tomorrow White Paper For ReadingBank of Tomorrow White Paper For Reading
Bank of Tomorrow White Paper For Reading
 
Obat Penggugur Kandungan Aman Bagi Ibu Menyusui 087776558899
Obat Penggugur Kandungan Aman Bagi Ibu Menyusui  087776558899Obat Penggugur Kandungan Aman Bagi Ibu Menyusui  087776558899
Obat Penggugur Kandungan Aman Bagi Ibu Menyusui 087776558899
 
No 1 Top Love marriage specialist baba ji amil baba kala ilam powerful vashik...
No 1 Top Love marriage specialist baba ji amil baba kala ilam powerful vashik...No 1 Top Love marriage specialist baba ji amil baba kala ilam powerful vashik...
No 1 Top Love marriage specialist baba ji amil baba kala ilam powerful vashik...
 
Famous Kala Jadu, Kala ilam specialist in USA and Bangali Amil baba in Saudi ...
Famous Kala Jadu, Kala ilam specialist in USA and Bangali Amil baba in Saudi ...Famous Kala Jadu, Kala ilam specialist in USA and Bangali Amil baba in Saudi ...
Famous Kala Jadu, Kala ilam specialist in USA and Bangali Amil baba in Saudi ...
 
劳伦森大学毕业证
劳伦森大学毕业证劳伦森大学毕业证
劳伦森大学毕业证
 

Should You Build Your Own Backtester? by Michael Halls-Moore at QuantCon 2016

  • 1. Should You Build Your Own Backtester? Michael Halls-Moore QuantCon 2016 NYC
  • 2. About The Talk ● Suitable for beginners to intermediate quants ● Discusses: – Backtesting pitfalls – Different types of backtesting methods – The software landscape – Whether you should build your own – Event-driven backtesting design 101
  • 3. About Me/QuantStart ● Me: – Based (near) London – Background in computational fluid dynamics research – Started as quant dev in London equity/futures fund – Key lesson: Vast chasm between backtests and live trading! – Very passionate about knowledge sharing and open- source ● QuantStart: – Started in late 2012 (lots has changed in QF since then) – Topics include trading, careers, data science, ML – Discusses details that are often ignored, but necessary – Trying to bring institutional thinking to individual quants – Provides end-to-end code that can be used immediately ● Great time to be a quant or data scientist – Everything is being automated/systematised – Still need to learn the math(s) and coding though!
  • 4. What Is A Backtest? ● Trading strategy rules applied to a historical dataset. ● “All [backtests] are wrong, but some are useful.” ● What purpose do they serve? – Ultimately help decide whether to live-trade a strategy – Gives us an idea of how a strategy performed in the past – Allow filtration of bad strategies before live trading ● Backtesting is not live trading ● Two main types: “For-Loop” or “Event-Driven” ● Backtester design: A trade-off between accuracy and implementation complexity
  • 5. Backtesting Pitfalls The Usual Suspects ● In-sample testing – Never, ever do this! ● Survivorship bias – Get better data ● Look-ahead bias – Very subtle ● Market regime change – Hard to detect ● Transaction costs: – Spread – Fees/commissions – Market impact – Slippage Hiding in plain sight.
  • 6. Backtesting Pitfalls Lesser-Spotted Issues Lurking in the deep, but there to catch the unwary. ● OHLC data – Feeds often a mix of multiple exchanges (could you really have achieved that price?) – H/L → Don't know it until close! ● Capacity constraints – Maximum capital allocation? – Average Daily Volume (ADV) ● Choice of benchmark – Does it really reflect your strategy? ● Robustness to initial condition ● Overfitting/Bias-Variance Tradeoff – Big, big problem – Q: “How to avoid it?”, A: “Extremely difficult!” ● Psychological tolerance for strategy – If 50% drawdown is expected from backtests, can you stomach that in live trading? ● See Tucker Balch, Ernie Chan and others for great discussions on these points
  • 8. For-Loop Backtests How do they work? ● For each trading bar (e.g. day/minute) – do_something_with_price() [e.g. Moving Average of close] – buy_or_sell_something() [Often the SAME close] – next_bar()
  • 9. For-Loop Backtests Pros and Cons ● Easy to program – Can use nearly any coding language ● Fast to execute – Can check many parameter combinations ● Unrealistic – Often no transaction costs – Minimal code re-use for live trading – Immediate market fill at midpoint ● Prone to look-ahead bias – Is it “i”, “i-1” or “i+1”? ● Should be used as a filtration mechanism – Eliminate the obviously bad – Remain skeptical of the good → Further research needed! Advantages Disadvantages
  • 11. Event-Driven Backtests How do they work? ● While data_still_exists(): [Loop until told otherwise] – event = get_latest_event() [Think of an “event” as a message] – If event.type == “tick”: [Market data update] ● calculate_trading_signals(event) – Else if event.type == “signal”: ● portfolio.handle_signal(event) – Else if event.type == “order”: ● execution.handle_order(event) – Else if event.type == “fill”: ● portfolio.handle_fill(event) – Sleep(10 minutes) [Check market every 10 mins]
  • 12. Event-Driven Backtests Pros and Cons ● Tricky to code – Possibly weeks/months of work – Healthy market for quant developers! ● Need an object-oriented language – Necessary for “modular” design ● Useful to know software engineering – Logging, unit testing, VCS, CI ● Slower to execute – Multiple parameter combinations can take a long time to calculate Advantages Disadvantages ● Mostly eliminates look-ahead bias – Event-driven design can't “look ahead” – Although possible indirect bias through model ● Code re-use – Only need to “switch out” data and execution modules for live trading – Less bugs to fix ● Multiple strategies and instruments ● “Proper” risk and position management – Kelly criterion/dynamic leverage – Sector exposures, ADV limits – Volatility estimates ● Remote deployment and monitoring – “The cloud” or colocation
  • 14. Software Landscape For-Loop Backtests ● Mainly open-source, some commercial ● Quant funds/IBs and individual quants use: – Python (Pandas) – R (quantmod) – MatLab ● Plenty of code snippets on quant blogs – Visit Quantocracy.com and start reading
  • 15. Software Landscape Event-Driven Backtests ● Desktop – Deltix – QuantHouse – Mainly for (some) quant funds, family offices, prop trading firms ● Cloud – Quantopian! ● Institutional quants? – They have regulatory constraints, investor relations, detailed reporting, auditability – “Nobody ever got fired for choosing IBM” – Although plenty build their own... ● Retail quants? – Cloud & data? → Go with Quantopian – Roll your own? → AWS & really good data source(s)! Commercial Free/Open Source ● Many to choose from... – Zipline (Quantopian) – PyAlgoTrade – PySystemTrade (Rob Carver) – QSTrader (Me) – C++ → Only if you need the speed... ● But...use good data – Else, it's “garbage in, garbage out”
  • 16. Programming Languages? ● Shouldn't be interested in “language wars” – only so many hours in the day! ● We just want to use what works ● Python – Standard library talks to everything – Great quant/data science/ML libraries – Could be better on classical stats and TSA – For-loop AND event-driven backtesting – Can perform end-to-end research, backtesting, deployment, live trading, reporting and monitoring – Could be faster... ● R – Great for time series, classical and Bayesian stats, ML, plotting – Great for for-loop backtesting, not good for event-driven or live trading ● C++ – Really, really fast – Painful (compared to Python) for loading/reading/formatting data – Used in higher frequency trading and legacy systems at funds, banks – C++11/C++14 brought in useful new features ● Others? – Java, Scala, C#, Julia, [functional...]
  • 17. Should You Write Your Own (Event-Driven) Backtester? ● Answer: Yes! → It is a great learning experience ● Forces you to consider all aspects of trading system – And the questions you should be asking of commercial/FOSS vendors... ● For example: How does your current live system differ from your backtest simulation in terms of: – Algorithmic execution and order routing? – Spread, fees, slippage and market impact? – Risk management and position sizing? ● Not easy or quick to write, but it will pay huge educational dividends later in your quant trading
  • 18. How Do You Write Your Own (Event-Driven) Backtester? ● Download zipline, QSTrader, PyAlgoTrade, PySystemTrade etc. – Try reading through the documentation and code! – Python is almost like reading pseudo-code ● Visit QuantStart and Investment Idiocy for detailed articles on event-driven backtesting ● You don't have to be an expert on day #1! – Take it slowly, module-by-module
  • 19. Event-Driven Backtest Design 101 It's not (quite) rocket science...
  • 20. Common Event-Driven Backtest Modules ● Securities Master Database ● Trading Strategies ● Portfolio & Order Management System ● Risk & Position Management ● Execution Handling ● Performance & Reporting ● System Deployment & Monitoring
  • 21. Securities Master Database ● Not just a CSV file from Yahoo Finance! ● Use a “First class” database/file system – PostgreSQL/MySQL/SQL Server – HDF5 ● Ideally want to obtain and store tick data – Bid/ask (for spreads) – Can then make your own OHLC bars, if desired ● Must be aware of: – Corporate actions (painful and time-consuming) – Survivorship bias (de-listing) – Timezones, various exchanges ● Individual quants can compete – Database technologies are free and mature – Data is becoming cheaper and “democratised” (e.g. Quandl) – Plenty of strategies that are “too small” for funds Quants need good data.
  • 22. Trading Strategies ● Generally runs a prediction or filtering mechanism on new data ● Receives a tick signal “on_tick()” – Produces a trading signal, e.g. “buy GOOG at market” – Notice no quantity – that's done elsewhere! ● 95% of quant blog discussion is about trading strategies – I think it should be more like 20% – Returns can often be improved significantly by spending more time on risk management, position sizing Just read the crop report!
  • 23. Portfolio & Order Management ● “Heart” of the event-driven backtester – Requires extensive dev time and testing ● Goal is to get from the current portfolio to desired portfolio – Minimise risk and costs while doing it ● Ties together strategy, risk, position and order execution ● Also carries out position handling calculations for backtesting ● Allows a variety of financial instruments in a single portfolio – Necessary for institutional-style portfolios with hedging – This is very tricky with a for-loop backtester I [(x^2 + y^2 -1)^3 – x^2 y^3 = 0] backtesting.
  • 24. Risk & Position Management ● Risk module can modify, add or veto orders – Add hedges to maintain market neutrality – Reduce order sizes (sector exposure or ADV limits) – Spread could be too wide (or fees too large), for a minor incremental change, so don't trade ● Position sizing for dynamic leverage – Kelly leverage (and other portfolio optimisation) – Volatility estimation ● Under-represented in quant blogosphere – Biggest difference between how institutional and some individual quants “think” about trading – Simplest way to try and get better returns? Implement risk management and position sizing The HAL9000 risk manager.
  • 25. Execution Handling AKA Transaction Cost Handling ● NOT guaranteed market fill at midpoint! ● Must consider capacity, spread, fees, slippage, market impact, algorithmic execution – Otherwise returns will be vastly overstated ● Should be able to switch BacktestExecutionHandler with LiveExecutionHandler and deploy ● Easily add multiple brokerages – Use OOP concept of “inheritance” ● Nobody enjoys writing code against poorly-documented brokerage APIs! – Have a policy of “trust but verify” when using third-party libraries – The devil is in the details... Optimal execution.
  • 26. Performance & Reporting ● Retail quants can borrow sophisticated reporting techniques from institutional quants – Live “dashboards” of portfolio and risk state – Current “backtest equity” vs “live equity” difference – Key metrics: Costs per trade, returns distribution, HWM, max DD, avg latency, alpha/beta, benchmark comparison ● Consistent incremental improvements to infrastructure – Can really enhance returns over the long term – Don't just consider the world's greatest strategy (WGS) ● WGS will eventually erode due to “alpha decay” – Robust trading infrastructure, and continual research into new strategies will always pay dividends ● Infrastructure more “boring” than strategies? – Less boring when returns are improved! Not the WGS.
  • 27. Deployment & Monitoring ● Crucial for “institutional-grade” systems – But individual quants can use these ideas too! ● A robust system must be remotely deployed in “the cloud” or colocated – Sub-optimal idea to use home desktop/laptop for algo trading ● Main issues: – Hardware monitoring (CPU, RAM/swap, disk, I/O) – High-availability/redundancy – Backup AND restoration plan – Log everything (Python has “logging” module) – Continuous integration, unit testing, VCS – Murphy's Law: “If it can fail it will fail.” ● Many vendors: – Cloud: Amazon, Microsoft, Google, Rackspace – VCS/Logging: Github, Bitbucket, Loggly, Splunk “Murphy's Law.”
  • 28. Final Thoughts ● No “quick fix” in quant trading – must work hard and learn a lot ● Don't concentrate too much on the best “strategy” – It will eventually decay – Continually research many new strategies – Always have the “strategy pipeline” full ● Invest time in your infrastructure and it can improve your returns ● Write your own backtester to learn – Either: Use it and continually improve it – Or: Find a vendor and then ask lots of questions ● Always be reading, learning and improving – Textbooks, arXiv, SSRN, quant blogs, academic journals, trade journals
  • 29. Thanks to everyone for listening and to Quantopian for hosting! Questions?