I wanted an extremely pessimistic backtester… in other words, one where I should reasonably expect to do better than it does in real life, even while following the systems to the letter. So, the rules are as follows:
- Make all trading decisions after hours, to be executed at the open on the next trading day
- All buys are filled 25% of the way between the open and the high of the day.
- All sells are filled 25% of the way between the open and the low of the day.
- Slippage of an additional 3 cents on all orders and $7 commissions (matches my broker).
In other words, it makes swing trades at bad prices, but if it is right about the stock direction for the next couple days, it will overcome its own horrible “timing” and make money.
The architecture of the tester is like this:
Each day, one or more strategies are run against the data (they can see the past, but not the future, obviously). The strategies vote with ‘bullish, ‘bearish, or ‘neutral, on any number of stocks. The simulator averages up (with equal weighting, at present) the sentiment on all the stocks that all the strategies chimed in on. It takes that information, along with the knowledge of whatever open positions there are, and enters trades for the following day.
So, for instance, if the strategies in play are predominantly neutral, and we have a position, the simulated trader will start scaling back on those and taking profits. If the strategies turn bearish and we have a long position, the simulated trader will close the position and go short. Etc, etc.
Strategies make use of studies, and I am slowly getting most of the ’standard’ ones implemented (SMAs, EMAs, Momentum, RSI, etc), so that strategies are faster to write.
There are hooks in place to attatch observers at various points, so I get log files of the strategy sentiment, the trades, and csv files of the decisions and equity curve that I can graph in excel.
So, what I haven’t had the energy to do to much, is the next step. That is, I run strategies, study the results, and identify where they are weak. Then, I have three main options:
- drop the strategy (it just doesn’t work well), and post to blog
- alter the strategy to try to overcome its weaknesses
- add additional strategies that will vote in ways that counteract the weaker votes (in other words, it will tend to be bearish at times when the weak strategy shouldn’t be so bullish. When the votes are averaged, they will cancel out).
I have implemented a Random strategy (and of course I hope every other strategy I implement outperforms it). I have a strategy that tries to follow a move when a stock continues to make higher highs and higher lows (or vice versa). This didn’t perform very well, actually. And I have a basic EMA-crossing strategy, which performs alright to a degree, but is obviously not enough alone.
The biggest obstacle with the freely available data is splits. I don’t want to use split-adjusted prices, because I believe a $100 stock acts differently than a $10 stock, and I want future strategies I code to be able to act differently based on the stock value, if that is wanted. But trading through a split blind gives me false huge overnight gains or losses. So, I’ve recorded the split dates for the stocks I use for data, and I use these rules:
- If tomorrow is a split, then close any open position at today’s close
- Do not trade in this stock for 30 calendar days
Sound ok? The reason for the trading moratorium is that most indicators will be whacky for a while after a split (think of a moving average on a stock that just lost 50% of its value). Without the 30 day break, most strategies made really bad choices right after splits, and I lost a ton of equity for no reason.
So, what’s next? Testing with strategies until I have a swing-trading type sysem I am happy with. Then, the plan is to put it into use, and I am thinking of trading on top of it, intra-day. As in, if the system is long on a stock, I may take partial profits on intraday peaks and try to get back in at intraday valleys.
May 12th, 2006 at 5:08 pm
Sounds like a really neat deal and pretty robust, but I think that sounds too pessimistic, it could skew your results and possibly make you throw out some good ideas. It’s much more likely to be something accurate if you had access to actual intraday data.
I’d recommend you buy some data if you can’t find the good stuff free. SCMagic covers some stocks, currencies and all e-mini futures, works well with SierraChart (which is like $10 / month.) I used that for intraday testing way back when. With all the time you’ve put into building this testing framework, and how much you have to gain if you can get some good systems, a little $ for data’s certainly worth it.
September 7th, 2006 at 6:14 pm
[...] So, to improve my confidence in my setups, I implemented a backtester, and also started keeping close track of my trading expectancy. It is soooo much easier to face a trade that’s going against you, when you have some reason to believe that you will make the money back (and more!) soon, trading the same way. Think about that… that’s powerful knowledge to have. I also did more thinking and reading about the chart patterns that are the basis for a lot of my trades. I tried to gain a deeper understanding of the market mechanics that make them work. I find it’s easier for me to trade against what I think market participants are doing, and harder for me to trade against what looks like a “head and shoulders” shape on a computer screen. [...]