I’ve put together a small framework for testing out technical-based trading strategies. You can create indicators, generate trading signals, calculate P&L, and chart the results. I know there are a bunch of mature packages out there that do this, but it’s a fun thought experiment. The code is public in case it’s of interest. I may throw a few random studies up here showing the futility of technical analysis, which is the consistent result of my experience with it.
As an example, consider this strategy:
- Buy when the price > VWAP * 1.005
- Sell when the price < VWAP * .995 (and there’s an open position)
- Long only, starting cash of $10000, run from 1/1/2012 through 1/3/2013, trading just SPY, no transaction costs
Strategy P&L = $871 vs Buy & Hold = $2028
In addition to showing the price movement and signals, this chart demos some other random indicators.
If you reverse the strategy and go contrarian (buy with a price dip instead of buying on the trend movement), the strategy beats the Buy & Hold performance, earning $2129 (that’s above and beyond the initial $10k outlay). The contrarian strategy, if run from 1/1/2005 actually earns a profit of $17K compared to $4.6K for just buying and holding! Anyway, this framework makes it easy to backtest strategies, test a universe of securities, and look at how different indicators perform. It’d also be easy to extend the backtester to note additional interesting stats, such as max drawdown.
Happy to help test out any strategies – feel free to drop them in the comments.
3 comments
Thanks Craig, nice article and great work in code. Can you please mention those “bunch of mature packages” as well?
Thank you Gautam. I think the most well known mature package is zipline (https://github.com/quantopian/zipline) which is used by the site Quantopian, definitely check that out if you have any interest in putting these sorts of algorithms together.
I like using MarketXLS for this. It’s great for me.
Comments are closed.