algorithmic trading by: avi thaker. table of contents hft vs non-hft terms data pandas limit...
TRANSCRIPT
![Page 1: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/1.jpg)
Algorithmic TradingBy: Avi Thaker
![Page 2: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/2.jpg)
Table of Contents
HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution
Kinds of Strategies Developing a Strategy
Backtesting Execution
Getting Started Appendix
![Page 3: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/3.jpg)
HFT vs Non HFT
HFT or High Frequency Trading, relies on quick algorithmic trading to capture small spreads or small alpha (less than 1 minute holds) Difficult for the retail investor to get into
Extremely competitive
Fastest usually takes all profits
Makes up 70%+ of all trading volume
Non HFT (trades of longer periods) Easier for the retail investor to get into
Not as competitive
Smarter people make profits
![Page 4: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/4.jpg)
Terms
Depth of Market (DOM, Limit Order Book, Level 2)
Best Bid – price to instantly sell Best Ask – price to instantly buy Bid Size Ask Size Alpha
![Page 5: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/5.jpg)
Data
Data, Data, Data Successful strategies are all about data and backtesting
Daily Bars Yahoo finance, Google finance
Downloadable into csv format
Python Pandas implementable with Yahoo Finance
Intraday Data Expensive for long history
Non cleaned data can be obtained from Yahoo/Google finance
![Page 6: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/6.jpg)
Pandas Developed for data manipulation and analysis by Wes
Mckinney at AQR Extremely fast because it is based in c, and is vector driven
Dataframes
Similar to R, but easier to use
Many built in algorithmic trading analysis
Slow for implementation Requires NumPy http://pandas.pydata.org/ http://
pandas.pydata.org/pandas-docs/stable/tutorials.html
![Page 7: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/7.jpg)
Limit Order Book
Best Bid
Best Ask
Volume By Price
Bid Size Ask Size
http://www.trade2win.com/articles/1750-understanding-liquidity-market-pullbacks
![Page 8: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/8.jpg)
Limit Order Execution
For an order to be executed, a trade must cross below your buy, or a trade happens at your price,when you have been filled in the queue
![Page 9: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/9.jpg)
Limit Order Execution – Place Order
Bids Price Asks
100.03 2,1
100.02 3,7,8
100.01 5,2,15
100 1,2,5
1,2 99.99
2,5,8 99.98
3,8,1,5,3 99.97
2,3 99.85
![Page 10: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/10.jpg)
Limit Order Execution – Book Movement
Bids Price Asks
100.03 2,1
100.02 3,7,8
100.01 5,2,15
100 1,2,5
1,2,5 99.99
2,5,8 99.98
3,8,1,5,3 99.97
2,3 99.85
Fill at 99.99, this becomes removed, and position advances. A trade happens
Another order is placed behind you
People cancel their orders
![Page 11: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/11.jpg)
Limit Order Execution – Order Fill
Bids Price Asks
100.03 2,1
100.02 3,7,8
100.01 5,2,15
100 1,2,5
2,5 99.99
2 99.98
3,8,1,5,3 99.97
2,3 99.85
After an order is filled you move up in the queue, until you either are filled or cancel the order
![Page 12: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/12.jpg)
Strategy: Alpha Taking Believes the market will
move in one direction Mean Reverting – price
reverts back to a “average” price
Trend following – price will move in one direction and not revert
http://marcoagd.usuarios.rdc.puc-rio.br/revers.html
Stockcharts.com
![Page 13: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/13.jpg)
Strategy: Market Making
Capture the Spread Increase Liquidity On both sides of the
market Risky during times of
volatility Must be fast and have
good queue position
Bids Price Asks
100.03 2,1
100.02 3,7,8
100.01 5,2,15
100 1,2,5
1,2 99.99
2,5,8 99.98
3,8,1,5,3 99.97
2,3 99.85
![Page 14: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/14.jpg)
Strategy: Pair Trading
Assumes two contracts move together
Revert moves when one moves against the other
Can be highly risky 2007 Crash?
Spreads blow up
http://www.investopedia.com/university/guide-pairs-trading/pairs-trade-example.asp
![Page 15: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/15.jpg)
Developing A Strategy
Identify a strategy Back-test the strategy Execute the strategy Manage Risk
![Page 16: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/16.jpg)
Backtesting a Strategy/Risk Provide evidence of profitability
Curve fitting/ optimization bias
In-sample vs out-of-sample
Forward looking bias
Risk tolerance
Key StatisticsAverage wins :: 0.637 USDAverage loss :: -0.438 USD# Wins :: 214# Losses :: 210# Neutrals :: 3Win Rate :: 0.501PPC :: 0.104USD# Traded :: 427.0Ann. Sharpe :: 2.335
![Page 17: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/17.jpg)
Executing a Strategy
Entry Long
Exit Long
![Page 18: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/18.jpg)
Getting Started
Open up an account with Interactive Brokers https://www.interactivebrokers.com/ind/en/main.php
Research and Develop Strategies https://www.quantopian.com/
http://www.quantstart.com/articles/Beginners-Guide-to-Quantitative-Trading
Execute Strategies Either use Quantopian or develop own system through IB
API
Use Python, C++, Java
![Page 19: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/19.jpg)
Appendix: Quantopian
Provides an excellent community which shares trading ideas
Good backtesting resource with fairly good minute bar data
Direct implementation from Python to IB API Live/Paper Trading
Slow execution and not good for higher frequency strategies
![Page 20: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/20.jpg)
Appendix: Candlestick/Bar Data
Open – price at start of bar High – highest price Low – lowest price Close – price at end of bar Volume – number traded
during bar Can be on any timescale:
seconds to dailyhttp://www.financial-spread-betting.com/course/candle-stick-charting.html
![Page 21: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/21.jpg)
Appendix: Sharpe Ratio
Developed by William F. Sharpe
Measures risk adjusted performance Risk vs. Reward
Higher is usually better
Usually annualized Adjust portfolio returns to a daily basis, average the returns and
multiply by
![Page 22: Algorithmic Trading By: Avi Thaker. Table of Contents HFT vs Non-HFT Terms Data Pandas Limit Order Book Limit Order Execution Kinds of Strategies](https://reader036.vdocument.in/reader036/viewer/2022062301/56649e555503460f94b4bc32/html5/thumbnails/22.jpg)
Appendix: Profit Per Contract (PPC)
A measure of profitability, measured in ticks
A highly liquid stock usually has a tick size of a penny
If your strategy has more than 2 ticks, it is considered profitable (can escape the bid/ask bounce), if testing on bar data without limit order execution on bar closes
You can submit market orders and still make money