On Backtesting

How does one create a mechanical trading system? However one comes up with ideas for entry and exit signals, testing those ideas is essential. In trading, one generally tests ideas on historic data, and thus the term “Backtest” is often used to refer to this sort of test, a test that is performed looking back at what would have happened to ascertain what might happen in the future.

Here are some thoughts on backtesting, in no particular order.

Q&A on trading

Rusty, a good friend from my college days (and a bit beyond), has been asking some interesting questions in one of my posts below on trading. Here’s his latest comment:

Hi Jay –
The Vanguard funds have worked out well for me. Besides capturing the market return, they’ve had the other benefits of requiring absolutely none of my time, and I sleep a little better at night.
Regarding efficient markets, I think it depends on what you’re investing in. Are you looking at very small companies with a relatively small number of transactions? I might be convinced. If you’re trading GE and Microsoft, or more generally stocks in the S&P 500, I’m less inclined to agree. With millions of shares traded per day, that’s an efficient market. The people trading GE (as a whole) know a lot more about GE than I do.
If you actually generate the returns you’re expecting trading stocks in the S&P 500, that is an amazing feat.
Two other comments, if you will. I think it’s one thing to be able to say, “We’re in a tech bubble” or “These tulips cost way too much.” But it’s really hard to invest against a bubble. Greenspan was warning of irrational exuberance a couple of years before the bubble popped. Shorting too early would have cost quite a lot, not to mention passing up the rest of the ride up.
Besides that, I can’t think of how you’d try to exploit popularity in the 1-5 day time frame. That’s mindblowing to me, and I’d love to hear more about that. Are you researching these companies, or is your selection based on some kind of technical analysis or trend detection? I’m intensely curious.
Finally, the big question for me. Why aren’t others discovering this, and competing away the returns? Why isn’t some mutual fund company advertising a fund that returned 70% on average over the past 6 years?
Greatly enjoying this,

I started writing a response in the comments, but thought I’d put in a post so others can join in if so inclined.

Okay, one point of clarification. When I discuss my system, I am not referring to Tarzan. Tarzan was/is an experiment, but I do not trade it currently, though there are a couple very good ideas cooked into it (I think). If you read the original post on Tarzan, you will see a reference to my early attempts at Collective2 which performed great but were ill received. That system was the alpha of my current trading system, the one I talk about when referring to my own trading.

A point of agreement. I think it is of the utmost importance to sleep well at night and have that as one of the bedrock requirements of my system design. For me, that entails being fully in cash every night, even though that tends to degrade the performance a bit in the long run. I’m just very prone to frustration at being burned by the overnight news cycle, even though it helps overall. So I simply don’t mess with it, and have actually tried to make it an advantage.

Another clarification. It seems that some of my comments are being taken to refer to macroeconomic conditions. Another of my goals, however, is to build a system that is as uncorrelated to the broader market as possible. So, for instance, in the past few days, when the market was moving up, I was almost entirely short, and did okay… which is not to say that happens every time.

Which brings me back to that post I need to write on my basic approach. Suffice to say I find it MUCH easier to gain an exploitable edge in the 1 day time frame than any other time frame I’ve evaluated. And no, I don’t actually know the names of the companies I’m buying or shorting day by day.

The last question is pertinent (though once again, those results are against a system I don’t actually trade)… I’ll probably need to address it at some point as well. But I think the answer is roughly this: 1) fast-trading systems degrade with the amount of capital invested, so my technique would probably be terrible for a mutual fund; and 2) it took me a couple thousand hours to get here, so though others may be able to get there much more quickly, it is probably a reasonable barrier to entry for the average personal investor/trader.

Tarzan update 1

This is fun. My new system on Collective2 is off to a fast start.

As I said before, swing trade systems don’t come naturally to me, so this was very challenging. The system holds 7 positions at a time with an average hold time in the neighborhood of 7 trading days, so it roughly turns over one position a day… which, in my opinion, qualifies as a modestly paced swing trade pattern.

However, the current return rate will not be sustained. In fact, I am confident that it is way out in front of its sustainable return rate, so much so that I felt compelled to add a warning at the front of the system overview. Here’s how the description currently reads.

Tarzan v1.0

A little over a year ago, I began using Collective2 as one of the tools in my toolbox to develop a trading system. It took some time, but I gradually developed a solid track record and was ultimately listed with the top 20 or 30 systems available. This past February, however, I stopped supporting my system for two reasons: 1) I began trading it myself in earnest and started feeling more secretive; and 2) nobody was subscribing to it anyways.

At the time, I was flummoxed as to why nobody would subscribe to my system. The other top performing systems had many subscribers, with some of them pulling in over $10k a month in subscription fees. So what was wrong with mine? I now believe it is because the style of trading to which I am attracted looks stupid to others. I opened positions at market open and closed them at market close. I wasn’t twitchy enough for day traders and I broke every rule of the swing traders by closing out positions “prematurely” and had way too many trades. I got lots of questions like, “Where are the stop losses” and I’d answer that I didn’t use them because I couldn’t prove they added value… but that’s not what folks wanted to hear.

I’ve continued to work on my system and utilize it for myself. There’s been some ups and downs, but that’s not really what this post is about. I’ve missed Collective2, as it was one of the only public forums I had with my trading, and I found the interaction enjoyable. So I recently decided to give it another go by giving myself a very challenging (for me) goal. I didn’t focus on maximizing returns as I had with my previous system. Rather, I tried to design a system around a few key principles that I thought would make people happy.

Oddly enough, most traders (as far as I can tell… and numerous books agree with this observation) tend to focus on what makes them happy in the activity of trading rather than on making money. So I designed a system with the swing trader in mind:

1) All trades entered in the evening. Enter and exit positions on market open. Allows the system to be traded by those working full-time jobs.

2) Minimize the total number of trades while also minimizing the risk. I thought seven positions (both long and short) held at a time struck the right balance.

3) In general, let the profits run and cut the losses short.

4) Trades average 2 to 10 days. Here I was trying to meet the expectations of the trader looking for a bit of excitement without offending their sensibilities by dipping into the day-trader playbook.

Anyway, version 1 of Tarzan is now up and running. I still need to bring the max drawdown lower (it hits a 30% drawdown during 2002 in my backtesting), but I wanted to start developing a track record with it so I went ahead and put it on C2. As I alluded to above, classic swing systems are very difficult for me, so this was quite an achievement… or it will be, if it works. We shall see.

Tools of the trade(r): Amibroker

If you are designing a trading system, it is crucial that you adequately test your ideas. Now, backtesting trading systems is fraught with danger. Curve fitting, systems that can’t actually be traded in real life, ignoring frictional costs, you name it, I’ve done it. But that is another topic for another post. Even though there are problems to be avoided, you’ll still need to backtest.

Platforms to backtest come in many shapes and sizes, but most of them have a common characteristic: they are insanely expensive. In spite of the cost, most have huge gaps in their capabilities. In particular, many are deficient at the portfolio level and instead assume you are trading a few specific equities rather than screening the broader market day by day.

Amibroker overcomes all these issues for the technical trader (not so much for the fundamental trader). It is both feature rich and affordable. I have spent quite literally thousands of hours developing my trading style and specific system, and most of that time was logged on Amibroker. If you want to focus on individual charts, it is feature rich. If you want to do portfolio testing, it is feature rich. I have encountered very few goods or services in my life of any sort that were such a remarkable value.

Now, I will hasten to add that Amibroker does have some flaws. However, the rich scripting language (AFL) has allowed me to overcome pretty much all the problems I’ve encountered in the generic features. For instance, I’m not a fan of the default stops (loss, profit, time, etc.), but have implemented my own using AFL. You can even turn off the default backtester itself and programmatically control the individual buy/sell decisions. Thus, I was able to create a system that includes both shorts and longs with separate max open positions for each. So the flaws, though real, tend to be surmountable and do not detract from the value of Amibroker.

Tools of the trade(r): Stockfetcher

One of the many tools I rely on as a trader is Stockfetcher, which I’ve used on a daily basis for several years now. It is a wonderful stock screener, the likes of which I’ve not found elsewhere though there are many other screeners available (many of which are free).

I use Stockfetcher to: 1) execute my system on a daily basis; 2) explore the universe of stocks and chart patterns for new ideas; 3) provide initial testing on those new ideas.

The scripts used to screen for stocks are fairly easy to learn and are remarkably powerful. The only deficiency in the scripting logic is the lack of an OR statement (this is by design intent according to the site owners), and even this small drawback is easily overcome with a clever use of the COUNT command.

At $9 a month, I’m not aware of a better value for those wanting to implement a mechanical trading system that uses EOD data (End of Day… in other words, the day’s Open, High, Low, Close, and Volume).

And now a bit of explanation for those wondering what a stock screener (or scanner as they are sometimes called) is or does. Simply put, a stock screener evaluates data from the universe of stocks (around 8000 of them on the major markets) and spits out a list of stocks that meet specified criteria at that moment. Additionally, it might provide data about the list of stocks produced. In the case of Stockfetcher, that data can be user defined.

Thus, to run my system, I use Stockfetcher to run 8 different screens each night and return a list of stocks for each screen with an associated score that I use to sort the stocks picked from the different screens. I then take the top 6 that were picked by my 4 long screens and the top 9 that were picked by my 4 short screens. But the whole ranking and picking moves us to another tool for another entry.

Trade like Sgt. Schultz

The worst trade of my “career” came in the midst of solid success. I entered a trade and promptly watched it go nuts. It peaked up about 22%. On its way up, I realized it was showing all indications that it was going up with no end in sight. I had seen this happen before, and I knew what was going to happen next. So as it went up, I tripled my position. Might as well cash in on a winner, right?

The next morning, I closed out the position down almost 15%. I took a massive hit to my equity because I “knew” the stock was going to go up. I had been fooled by some modest success into thinking I could wing it. It was rather devastating, yet I remain thankful for the experience. It was the first trade in which I totally deviated from my system, and I got nailed. And when I say I deviated from my system, I mean I deviated massively. I threw out my money management rules and exposed far more money to a single trade than my system allowed, thus increasing my risk. And I expanded my position at a price point that was much higher than my system allowed.

In so doing, I learned (all the way down to my bones) an absolute, essential rule for system trading. I know nothing. Nothing at all about an individual trade. All my knowledge is at the system level. I have an edge, but it has nothing to do with any specific knowledge of any particular trade. Rather, I know that if I follow my system over enough time and enough trades, the odds tilt in my favor. (At least, that’s the hypothesis under test.)

Let’s say you are holding a bag with 100 marbles, 55 of them red and 45 of them blue. You reach in (without looking) and pull out a marble. It is red. You then return the marble to the bag and shake the bag up. You do this 5 times and each time you get a red marble. Your knowledge of what just happened (you got a red marble 5 times in a row) and your knowledge of the overall system odds in no way means you know the next marble will be red. Or blue, for that matter. Your knowledge remains strictly at the system level: that over enough trials you will tend toward an average of 55% of the marbles drawn being red.

Statistics 101, yet in the heat of a trade, it is surprisingly easy to forget. If you want to learn system (or mechanical) trading, I suggest you trade like Sgt. Schultz. When looking at an individual trade, always remind yourself, “I know nothing.”

The present tense(less)

I think this post wraps up my brief history of trading and moves us into the present tense. Thankfully, the present is less tense.

Picking up the story from where I left off, I began working on an entirely new system toward the end of the summer in 2006. There were numerous fits and starts along the way, and I ultimately changed to Interactive Brokers to put more emphasis on good, cheap execution and less emphasis on real-time data. I used Collective2 to do a lot of experimentation, which proved surprisingly helpful. By December I had all the elements of a new system in place and coming into the new year I’ve started fully trading it.

For now, you can see the results on my Collective2 system 1Day, which was used to try out a lot of ideas, but since the beginning of 2007 is simply tracking my actual trades (though to a different scale, as C2 forces you to start with $100k play money).


The great thing about my current approach is that it is easy. Well easy to execute on a daily basis… it was rather hard to develop. And that is the key lesson I believe I learned from my previous stressful success. Sustainable success isn’t going to come from a system that is massively difficult to actually trade. A good trading system should be like a good compressed codec, to use a techie metaphor. Take MP3s. The codec is designed to be front-loaded. All the time goes into the encoding. The decoding is quite easy and can easily be performed in real-time with minimal processing. The encoding will max out your CPU and takes quite a bit of time.

Likewise, developing a system is hard work, and as I believe I’ve amply demonstrated, takes a lot of time and involves a lot of failure (at least in my case it did). Actually trading the system, however, can be fairly straight-forward. I’ve got a spreadsheet that I use each night to download the hits on the six screens I use, and then ranks them and puts them in a format to be uploaded to my broker. It takes about 5 or 10 minutes a night to do my trades. Encode hard. Decode easy.

So my new system succeeds at lowering the stress level… time will tell if it remains profitable.

Stressful success can feel a lot like failure

I switched to Tradestation near the end of my second year of trading. After a couple months of learning the interface and trying out some ideas, my intuition kicked in. A vague idea was forming, but I couldn’t get a handle on it. Then, more on instinct than anything, I made a trade on September 1, 2005 that proved the catalyst to understanding. It went up 55% that day. I hopped out, and started systematizing that intuition.

It took some time, and there were some fits and starts, but I put together an approach that ultimately returned 140% profit in the following 8 months. Using no leverage, for what it’s worth. That’s the good. The bad was that it was killing me. The system was simply too stressful to trade while holding down a full-time job. Eventually, the stress led to mistakes, and what should have been a 10% drawdown turned into a 25% drop with the help of numerous mistakes on my part. Though I managed to sort my way through it and saw the beginnings of a nice recovery, I ultimately decided to set aside the system for that imaginary time in the future when I can trade full time.

So I had proven to myself that I could succeed, yet as I entered the summer of 2006 I felt I had to start from scratch, with far more emphasis on building a system that was relaxing, even if the returns were much lower. I had gained a new appreciation for the debilitating effects of stress. Stress doesn’t stay within neat boundaries, it spills over into all areas of your life. And I had also come to a better understanding of my strengths and weaknesses as a trader. I had developed a certain style, a personality, as a trader. Now I had to find out if I could invent an entirely new trading system that fit my style, gave good returns, and allowed me to relax.
Success -- sort of

optoma hd142x bulbcgix stock pricehow to turn on jaybird x2menon bearing share pricecerner stock price historyecovacs deebot m81pro reviewimac flashing folder with question markdelcath stocknvda cramerchartlinesefii stockapigee stockmhl kit walmartarlo base station lightse7240 specsdla piper ransomwarektnnfnyse rubihtc 626s specsdell xps 8900 specseabuildernsrpfcunb stockmagstocklamr stock pricesamsung 65ks9500emsmfdus stock pricenzbplanetadrny stockasm100 1580gartner hype curvespectra7 microsystemssamsung u28e590d reviewhomekit smoke alarmshuttle sh67h3un55mu7000mini jambox pairingapple me918ll atogetherville sign upnasdaq gntxxfinity pause wifiexpi stock priceinsy stock priceacer cb281hkdmtx stock priced7300 release dateprkr stock priceufmcdwsn stockbeoplay s3 reviewbose qc25 best buysterlite share pricesbbpevlvchromebox cxi2logitech c920 walmartsimplertradingsaregama share pricemnggoculus dreamdeckglpglinksys ple400vpor stockipvanish dd wrtlg 55uh7650 reviewmytmobile benefitswbmd stock pricexef8asus rog g752vy dh72gntx stock priceprataap snackshhs1 comdoubletwist airsyncgulfslope energyxco stock priceulteohedj stockptotf stockdbvt stock priceexsrsharepod reviewagnc stockukservers reviewskullcandy uproar wireless headphones reviewpzrxiphone 5s randomly shuts offwebroot secureanywhere removal toolnasdaq fuvbnb financialsaehr stocknyse aplenyse nrpdell t5500 specsisolfstdy stock pricenwbo stockwbmd stock pricesam's club chromebookscorpio dev kitnasdaq jcomnikon 24 megapixel dslr camera d3200 price in indiatbph stockagrx stockdiax stockunikrn stockturtle beach stealth 500p revieworthopediatrics corpquote jnugfibrogen stockvbio stock pricecbis stock chartnyse swnasus zenpad 10 z300m a2 grbtcs stock pricegthp stockcentric group kronosapptivo review65x850edeskstar 7k3000 3tbnikon d750 walmartchiclet mechanical keyboardnvee stock pricepsvue reviewalienware command center 4.0nvee stock pricedvd decrypter 64 bit windows 7 freewarenook simple touch screensaver changesiberian chervonetsdakpshimo vpnsony kdl 40w2000nvda cramerirobot roomba 652 robot vacuumitaserturtle beach px3 ps4creg stockpringles cantennamnkd tickergphofxunitytalk me xfinitynasdaq twouummy video downloader reviewhp m252dw reviewglbl stock pricerazer zgoldiview tablet resetfoxfcwb etfmacd explainedammj stock pricenyse lvlthotrwarotech corpaxcrypt reviewbmxizpinrilix scenarios downloadargos therapeutics stockdiffrient world chair reviewscty stock priceps december 2016astro a40 specsloncar cancer immunotherapy etfnasdaq manhis spyhunter legitptog stockinlxwww vevo com activate firetvaxs tv rokuapple iphone 5s 16gb gold price in india flipkarttvizhow to access synology diskstation remotelyabi index chartprqrstock acbffnxopfbicx stocknyse yrdmonacoin redditepson wf 2760 reviewcytx yahoomelodyvrpredator frostcoreoled tv lifespanopgn newskickapps pricingaxahy stockiview tablet resetcgra stocknasdaq oktaasus k501uq 15.6 laptop reviewbose soundtouch 520 reviewgarmin nuvi 57lm voicesaphb stock newsnyse usmlinksys re6500 reviewroyaletrickmsnbc streaming rokunasdaq ozrkfusiontraderh1z1 aiming tipsjailbroken firestick appsscla stock3i infotech share pricetransfer money from paypal to venmolucidpress reviewshesm stockdell e7270 reviewd7200 focus point selectionmanfrotto 055xbggp tickervtip stockadomani ipolmca stocknbrvcorsair vengeance k65 compact mechanical gaming keyboardnasdaq nbixmrib stockvpl gtz1cpss stockdvylhttps www setvnow comgrpn earningsarcx stock priceeglt stock pricemmmstockftrprnetgear wn3000sarseptfx stock priceibcp stock pricekymera magic wandasus vg248 monitortp link ac5400 reviewexopc slate windows 8samsung hw m550 zatnp stock priceiemg etfwsky stockzyne stock price todaysegwit2x countdownnetgear wnr1000 wireless n150 routerphilips hue light strips starter kiteabuilderplpm stockqc35skgji stockfbcmtomtom start 4ef00leica m246samsung un55ks8000ffcuufdillards stock price historyxbr65x930e pricegbilenzn stock pricecoyn stockgoogle ma0sftec holdingsnyse tlrdairadar asus rt n56ugigabyte p37x v6ncredible bluetooth earbudssumiko blackbird pricewabtec stock pricegarmin vivosmart hr walmartwii u gamepad not chargingvcit etfmymembersfirstneot stock pricevizio m70 e3 reviewpcrfy stock pricevgltpbf4game wizard retropieuvspmyzone heart monitorgarmin 935xt release dateasck stocklenovo y500 specssony xbr65x900csplif stockrift addon gadgetsasus eye care switcher software downloadpa4 bundlenyse rgsnorthwest biotherapeutics incamd fx 6350 wraith cooleretst stockwemo away modeesea stock priceshure se115mnyse ssnipaintshop pro x6 system requirementsacer aspire u5 620 all in one pc7.1 surround sound headset xbox onemoto gk40acpw stockcdif stockidxg stockark survival evolved mindwipemdr1000epzm stock priceapply for billfloat metropcsortofon bronze reviewgopro knockoff amazonmyndplayvizio sb3851 cohp envy 5540 setupntct stock pricevizio smartcast soundbarpennar industries share priceofg stock priceatusfsohu stock priceazsey stockhudl charging portgamestop nintendo switch restockwstl stock pricetenvis accountcesp6sqzzfujifilm xp80 digital camera reviewszte zmax sd card slotrgse reverse splitletscom fitness tracker appapmffccoi stockvoov stocka problem is preventing the troubleshooter from startingqcp stock pricemsi cx61 2pc reviewxrp worldcoinindexctrv stock newshainly abrams mass effectsyf tickersonoco stock priceishares core us aggregate bond etflpth stock pricembrxjotspotinsta video uploaderewbc stock pricenxtd newssarepta stock pricecoke ticker symbolipvanish lifetimeqrvo stock pricegdot stockuplmqnikon l340 manual mode