Pairs Trading from NYC Algorithmic Trading Meetup November '13

27,337 views

Published on

Gary Chan presented at the NYC Algorithmic Trading Meetup. More on the presentation, including a sample Excel file, on our blog http://blog.quantopian.com/gary-chan-on-pairs-trading-presentation-from-nyc-algorithmic-trading-meetup/ You can sign up for future meetups here: www.meetup.com/NYC-Algorithmic-Trading/

Published in: Economy & Finance, Business
  • Be the first to comment

Pairs Trading from NYC Algorithmic Trading Meetup November '13

  1. 1. How To Build Your Own Pairs Trading Algorithm Trading System Quantopian Meetup Gary Chan
  2. 2. Introduction • Started programming at a young age • Played poker as main source of income for a few years • Money is just a way to keep score • Became interested in stock market • Read ~70 textbooks, mostly corporate finance, CFA curriculum • Currently running an algorithmic trading system out of my apartment
  3. 3. Expectations • I’m not here to divulge secrets • Teach a man to fish, not give him a fish • You will see how easy the pairs trading model is to understand and build • Deployable by retail investors • Seeing is believing • You will not be able to build your own tomorrow… but one day… if you want it badly enough • It’s a small world, so share ideas
  4. 4. Why you can beat the professionals • Definition of professionals • Algorithmic does not mean high frequency • HFT is not for retail investors • Strategy capacity • Find a niche
  5. 5. Disclaimers • A lot of learning, before this came to fruition • Content here will not be complete due to time constraints • Survivorship bias, Look ahead bias • Model risk, implementation risk, execution risk, over parameterization • Random models can have profitable backtests • I’m not responsible if you lose money
  6. 6. Algorithmic Trading is Easy • • • • • • What does easy / hard mean? Info, books, tools, cheaply or freely available Yahoo, Google, Morningstar, Edgar, Quantopian Visual Studio Express, MySQL, R Many textbooks written on the subject Low capital requirements (30K minimum) compared to other ventures • Backtest before you use real money!! • Higher quality data will cost more money
  7. 7. My Current System • • • • • Low frequency Single computer, 3 years old Runs on Wifi from my apartment Started coding Oct 2012 Started forward testing play money in March 2013 • Started forward testing real money June 2013 • Current performance consistent with backtests • Just started using cloud computing
  8. 8. My Cloud
  9. 9. My Cloud Part 2
  10. 10. Backtesting • Profitable backtests does not mean good • You need a valid model • Live trading WILL underperform backtests
  11. 11. How A Good Backtest Looks • Consistent, high R Squared • Similar parameters have similar equity curves
  12. 12. Key Info From Backtests • • • • Portfolio of 39 pairs Average of 12 to 18 pairs with opened positions, $5400 max drawdown $10k sized legs in backtests, $395 average profit per trade 81.3% winning trades, 4540 trades, 26 day average holding period
  13. 13. Pairs Trading Books • Contains Code • Complete manual to putting together your own system
  14. 14. Types of Investment Strategies • Mean Reversion – Buy low, sell high / Sell high, buy low – Fundamental Analysis – Statistical Arbitrage • Momentum – Sell low, buy lower / Buy high, sell higher – News • Technical analysis does not work
  15. 15. Necessary Math • • • • • • • Basic statistics Linear algebra Standard deviations, regressions Types of distributions (normal, logarithmic) Random walks Stationary (mean reverting) series Cointegration
  16. 16. Mean Reversion Example #1 • • • • • Keep an opened mind Everything can be measured in money If you don’t believe me, put it on EBay Fear can be measured in dollars Unwarranted fear -> Sell volatility to profit
  17. 17. Mean Reversion Example #2 • • • • • Stocks move in random walks Some stocks move together Spread between the stocks are mean reverting Buy low, sell high on the spread Statistical arbitrage means you win most of the time, not all the time • Buyouts and bankruptcies result in large losses • Diversification is a must • Learn some corporate finance / fundamentals
  18. 18. Case Study, GLD and IAU • Two gold ETF’s • Pull end of day prices from Yahoo Finance into csv files • Do a linear regression • Calculate the spread • Graph of spread is mean reverting • Find #Stdevs to enter / exit trade • Optimize parameters
  19. 19. Next Steps • Try higher quality data • You could trade this by hand + excel, but better to automate the process • Many systems are built in excel • Optimize the code • Backtest until you find a profitable strategy • Use a brokerage with an API, sample code • Forward test with play money
  20. 20. Next Steps Part 2 • • • • • • • Execution, order, position management Test with small amounts of real money Tweak your system Ramp up trading size if still profitable Exhaust universe for the strategy Find new strategies Never stop learning
  21. 21. The End • Ernest P Chan - Quantitative Trading: How to Build Your Own Algorithmic Trading Business (Wiley Trading) • Ganapathy Vidyamurthy - Pairs Trading: Quantitative Methods and Analysis (Wiley Finance) • R - http://www.r-project.org/ (like Matlab) Yahoo, Google, Morningstar, Edgar, Quantopian • Visual Studio Express, MySQL, R • garychan7@gmail.com • https://twitter.com/RITrading - I tweet my trades here

×