Show HN: Optimized trading algorithms using IPython parallel and ec2
twiecki.github.com
twiecki.github.com
If you actually want to trade moving average strategies, your best best is just to diversify and run several different strategies across a variety of parameter sets and across various sectors/asset classes, without trying to overly optimize a single strategy
As for market-paradigm shifts, I totally agree. One way to deal with that is to constantly re-optimize the parameters based on recent data. This is also known as walk-forward optimization on which there is a slide at the very end (see http://blog.quantopian.com/parameter-optimization/ for a more information).
Finally, as to running multiple strategies with different parameter settings. The OLMAR paper that describes the algorithm (http://arxiv.org/abs/1206.4626) has a variation of this where they use a range of different-length moving averages, rather than just one.
To anyone newly thinking about this topic, it is certainly the most challenging project you can take on. There are no laws of the market like there are laws of physics. You can get your code to work perfectly, but all that means is that your results will be the same as your model's going forward. As for a model, it's likely to need to change fairly frequently, even becoming the opposite of a previously great model for example, and you can never truly account for the effect of politics on markets. One tip is that a sudden catastrophic crash is far more likely than a gigantic surprise to the upside so if you're playing with real money, you need to use options to insure against such an event. Luckily (or not luckily in the case of trading itself) markets are highly correlated, so index options will probably fill this need.
You have to deal with intraday prices now. Got those? Well they are not split or dividend adjusted. Good luck.
My point about intraday data with corporate actions wasn't really about the difficulty with corporate actions, but rather the leaky abstraction of trading present in the slides. To give you credit, I don't know what issues Quantopian addresses. On the other hand, has any one tried running Zipline-backtested strategies in real life? Does any one know what issues aren't addressed by Quantopian? Corp actions was one part, T-cost model was hinted at in the slides, but was any though given to borrow costs and availability? There leaks everywhere. It is not that you don't seem like smart guys who made this cool thing freely generously available to everyone, but that you seem like you spent too little time downtown NYC.
PS. Fully adjusted bars are nice, but they have an epoch to be adjusted to. Unfortunately having an epoch that is not today() means you can't add today's data to it. If you can't add today's data to it, you can use this system to generate real trades to trade. Now you need two sets of data and two sets of code to work with. Good luck.
Quantopian does not have data for stock borrowing costs or availability, and Zipline's slippage/cost model does not account for them either. We'll find a way to get that data and plug the hole. The challenge has been finding a clean way to get it from the brokers, or finding an aggregator with a reasonable price (any advice?). In the meantime, we've been open about this limitation, and the zipline code is opensource, so I think/hope anyone who cares to know does probably know.
Quantopian is building our live trading environment now, so we don't yet have comparisons between the backtest results and real trading.
Regarding your point about the epoch, I'm not sure I entirely follow you. Part of the point of zipline's design is to allow easy swapping of datasources, mainly to allow the transition from backtesting to paper trading and then to real trading to be seamless. One algo code can run either historically or live. Adjustments from splits and mergers are back-projected, so that current day prices need no adjustment. Dividends are dealt with as announce, ex, and pay events, meaning we do not smooth out the over-night drops, instead we increment/decrement cash.
I'm in NYC regularly to host the NYC Algorithmic Trading meetup - it would be awesome to talk to you about these issues in person, please consider coming: http://www.meetup.com/NYC-Algorithmic-Trading/
We have the same strategy on Quantopian though (https://www.quantopian.com/posts/olmar-implementation-fixed-...) where we have 10 years of minutely data, adjusted for splits and dividends. It seems to do quite well.
That course also uses Python as programming language in the examples. Short description from that URL: "Find out how modern electronic markets work, why stock prices change in the ways they do, and how computation can help our understanding of them. Build algorithms and visualizations to inform investing practice."
Finally, live trading is something which we are working on to enable on Quantopian (which uses zipline for backtesting your algorithms). The syntax is very similar so you could just convert your zipline strategy to Quantopian (which is free to use).
Full disclosure - I used to run their developer platform.
Data: https://developer.etrade.com/ctnt/dev-portal/getDetail?conte...
There's also a call for data on option chains.
A downside is that they are between you and the exchanges at least when you use their SMART routing, so I get the impression your fills will be optimized for their benefit (via their Timber Hill subsidiary), not yours. Years ago, you could get filled substantially better than your limit order especially at the open for example, but no more.
You can, however, view the full IPython NB here: http://nbviewer.ipython.org/urls/raw.github.com/twiecki/zipl...
As an aside, I think an enterprise-quality zipline solution could be a worth a pretty fat chunk of $$ especially considering that the budget for KX and its support is generally > 1M per year per firm. (Yes, there's complex logistics and legal issues)
I believe seeing on github some requests for h5 support -- this + support could potentially be a big inroad...
[ Running: Chromium Version 26.0.1386.0 Ubuntu 12.10 (177362) ]