Saturday, October 13, 2007

Not an exact science

You've got to know when to hold 'em; know when to fold'em; know when to walk away; and know when to run - Kenny Rogers.

Backtesting is not an exact science, and has its limitations. At times, it can be said that the best computer is the the one between the ears.

One limitation that I only discovered recently was regarding company M&A. I realised yesterday that 2 out the 10 companies that I purchased this week were under takeover offers. So I was wondering how TradeSim handles these situations, because, I want to stick to the plan which was backtested with the least degree of deviation as possible; so I have the most chance of realising similar results.

Well TradeSim is only as good as the data that you feed to it; and data is simply 5 values for each bar. It cannot in any way account for company decisions. So when a company is delisted i.e. stops trading for any reason (merger with another company, script takeover, cash takeover, change of stock code, bankcruptcy), then TradeSim will close the position on the last bar it traded, the trade will be found in the TradeSim trade database as an open trade, and the price will be at the price it last traded (regardless of how long ago that was).

It will be marked as an open trade to differentiate from those trades that were closed out because they hit the protective stop or triggered a normal exit.

So it is upto me how to deal with these company M&A situations. I think at least for now, I will just leave the positions as they are, but will reassess the situation periodically.

I will not be updating the portfolio this week because all exits (as are entries) are delayed by one bar, I will have to check at the close of the next bar, which is next week, to see if any stops or exits were triggered. And I won't be running a scan (exploration) for any new candidates because all my capital is already in open trades anyway.

I notice there's some media articles regarding next week being the 20th anniversary of the 1987 crash. Some commentators say that this may well be a cause of market "jitters" next week. I guess that sort of news sells newpapers.

Thursday, October 11, 2007

Exits

Two of the cardinal sins of trading - giving losses too much rope and taking profits prematurely - are both attempts to make current positions more likely to succeed, to the severe detriment of long-term performance - William Eckhardt.

I can relate somewhat to what Eckhardt is saying in the above quote because I tried profit targets for my system sometime ago. They didn't work very well. What was initially supposed to increase win % in fact did not, but instead, reduced the size of average winners substantially. I was effectively cutting winners short.

My whole thinking behind it was because I don't like seeing winners becoming losses, as this (sometimes) happens in long-term trend following systems, that by definition give back alot of open profits. But clearly, the flip side of the coin of cutting winners short made the trade-off rather unfavourable.

Thinking about it now, the idea did not make sense at all, as I'm cutting (potentially) big winners in an attempt stop small losses. Losses are always small because of the my stop loss. Big winners, however, can often be the difference between a great system and an average one. If I were to remove the best 10 trades from the trade database, returns fall by almost 10%p.a.

What could work is a profit exit based on rate of change (ROC), designed for stocks that rise very rapidly. If a stock rises X% in a N number of bars, then the exit is taken. But more work had to be done here before I can make any conclusions.

Howard Bandy discusses exits in a section of his book. He mentions there are 5 types;

1. By the action of an indicator or recognition of a pattern, similar to what caused the entry.

a. The parameters can be the same as those that caused the entry, but in the other direction.

b. The parameters can be different for exit than for entry.

c. Some other indicator can be used.

2. By the price reaching a profit target.

3. By the time in the trade reaching a maximum holding period.

4. By the price falling back to the level of a trailing stop.

5. By the price falling back to the level of a maximum-loss stop.

He goes onto mention that the fifth type is the worst i.e. the maximum stop loss level. Those that have designed and traded mechanical systems would agree with this. During testing, we try and aim for the highest percent possible of trades exited in profit. Exits taken with a loss, and these are mostly those that hit the protective stop, should ideally be no more than 10-15% of the total exits.

Initial stops don't always help the system. For example, for my system, that I've just began trading live on this blog, I tried several but couldn't find an initial stop that improved the bottom line (doesn't mean there isn't one). I wanted an initial stop to calculate position sizing so ultimately I decided to place the initial stop at the trailing exit.

Maximum holding periods I must admit I haven't put enough research into this area to have an informed opinion but it just doesn't make sense to me. I believe the time in a stock should be determined by its trend. You want to spend the most time in the winners because profit increases as time in trade increases. At the same time, you want to spend as little time as you can in the losers, so you can take the loss and use the money for another trade (an opportunity cost issue). The problem is that you never know beforehand whether the trade will be a win or a loss, so it would be difficult (impossible?) to deduce the optimal holding time which would outperform other types of exits.

Wednesday, October 10, 2007

Randomly skipping some trades part 2

I had to learn discipline and money management. I decided that I was going to become very disciplined and businesslike about my trading - Paul Tudor Jones.

I didn't really explain the chart in my previous post as well as I should have.

The test was conducted over 9.5 years. In that time, there were about 2900 trades in the trade database. Those are all the possible trades picked by the system over that time.

Due to capital restraints and position sizing, I only traded between 400-500. I say and position sizing, because this is what keeps the number of trades down. Even if I started with 500k, if my fixed percent risk was 1.5%, I would still be taking about the same number of trades.

As you can see, I'm only taking about 15% of all the trades that are triggered anyway. So it doesn't matter how I pick them or even if ignore a vast majority of the trades, the results aren't affected significantly, as monte carlo runs have shown.

Randomly skipping some trades


Trading provides one of the last great frontiers of opportunity in our economy. It is one of the very few ways in which an individual can start with a relatively small bankroll and actually become a multimillionaire - Jack D. Schwager.


I was having a discussion with tech/a over at ASF the other day. He uses discretion (eyeballing the chart) to choose which candidates to buy from the stocks that have triggered. I thought that's fine -- until I found out that sometimes he doesn't trade at all because the candidates don't pass his filter.

Initially I was thinking that this was playing with fire because such a strategy cannot be backtested with TradeSim. I mean, having 10 candidates and picking any 4 because you have capital to take 4 trades is fine. Discretion can be applied here and shouldn't matter which 4 we pick as this is what monte analysis takes into account -- the different portfolio combinations and permutations.

It has been brought to me attention that TradeSim actually can test for this. This post was inspired by some good work by Stevo. You can actually program a code as part of the EntryTrigger and tell TradeSim to randomly only take X% of the trades that trigger.

So I did just that, to see if my system held up even if I missed some trades. And it does quite nicely. That said, I don't plan to ever do this in practice. You never know which trade will be the big winner.

For the above test, market orders were used to account for slippage and 200 monte carlo simulations were run each time, with the average return tabulated and shown in the above chart.

Tuesday, October 9, 2007

Every great journey begins with the first step




I realized that this chipping away approach was what I should be doing, not putting myself at big risk, trying to collect a ton of dough - Tony Saliba.

(Disclaimer: Just to re-iterate that I am NOT giving recommendations to buy or sell any of the securities mentioned in this blog.)

The first purchases were made this morning. We need to remind ourselves that this system is not supposed to work overnight. It's a long term weekly system, designed to make consistent money, over the long term. In fact, even in backtesting, the first year is often not profitable. So I would expect a single digit gain or loss on closed equity in the first year. That said, we should expect some nice open profits at this stage (after 12 months). Professional traders don't consider open profits as their own.

Start up is hard for long term systems because the trades that are closed out first are often the losers, and we need to give winners time to run. From testing, the average holding time for a winner was about 200 days, compared to 60 days for a loss. And the really big winners (which are the trends we are trying to catch) often run for much longer than a year.

The Total Trading Capital column in the spreadsheet is the money allocated to existing trades minus brokerage fees plus money in the bank. This is what TradeSim uses to calculate position sizing so I will do the same. MIN I paid double in brokerage because I made a mistake with the position sizing and bought less than I should have the first time around.

Monday, October 8, 2007

Waiting for opportunity

Although the cheetah is the fastest animal in the world and can catch any animal on the plains, it will wait until it is absolutely sure it can catch its prey. It may hide in the bush for a week waiting for just the right moment. It will wait for a baby antelope, and not just any baby antelope, but preferably one that is also sick or lame. Only then, when there is no chance it can lose its prey, does it attack. That, to me, is the epitome of professional trading - Mark Weinstein.

This post will have nothing to do with the title but I really liked that quote and has to fit it in somewhere!

There was another tweak I made to the system over the weekend that added a few percent to the results, that I haven't yet mentioned here.

All this time, I had the box in the TradeSim Preferences window "Accept partial trades if inadequate capital", unchecked. This only came to mind when I was thinking about this week's buy orders. After buying 9 stocks, each with a parcel size of about $4,500-4,700 (worked out from fixed percent risk), I would not actually take the 10th trade because i would fall sort of the required parcel size by a few hundred dollars. Then I thought why not take the trade anyway. But that hasn't been backtested. So I ran the tests again, to quantify the benefit (if any).

As suspected, the profit results were greater, by 3-4%p.a. over the various timeframes. Drawdowns were not affected significantly, about 1% higher. I'm happy with that. Number of trades increased by about 20%, naturally, so instead of 149 trades in the 6 year test, there were 179 trades. And instead of 84 trades in the 3.5 year test, there were 101 trades.

So now, the method will allow me to clean up the account if I don't have enough cash to take the full sized trade. This means that my money is in the market more often, which is a more efficient use of trading capital. And 3-4%p.a. is nothing to scoff at. Over a number of years, due to the effect of compounding, the increase in profit is quite substantial.

Maximising performance part 3

I have found that the greatest traders are the ones who are most afraid of the markets - Mark Weinstein.

I found a flaw in my testing method when ranking trades due to price, well, not a flaw as such, but the study design could've been structured better. Because I was ranking by lower priced stocks, this should mean, in theory, that there is only one possible route of trades to take. So everytime I ran a single portfolio simulation (with original ordering), all else being equal, the results should be exactly the same.

But they weren't, and I soon realised this was due to slippage. The variability would come from the randomness generated by the market orders which would buy a price anywhere between the low and the high of the entry bar and exit through any price between the low and the high of the exit bar.

As this wasn't a sound method of testing, I started again. For the purposes of this test, I ran monte carlo simulations (20,000) this time using default order slippage. Then I ran a single simulation through with the ranking giving preference to lower priced securities, also using default order slippage. So there's only 1 possible outcome. Then I compared this to the average portfolio result generated from monte carlo. The results are as follows.

01-01-1998 to 31-12-2003
Monte carlo average: 37.4%p.a.
With trade ranking: 38.9%p.a.

01-07-2001 to 01-03-2003 (The worst - XAO loses 18%, peak to trough of the bearmarket)
Monte carlo average: 1.5% (non-annualised)
With trade ranking: 13.56% (non-annualised)

01-01-2004 to 30-06-2007
Monte carlo average: 31.1%p.a.
With trade ranking: 44.6%p.a.

I don't think its coincidence that the more recent we go, the more wider the gulf becomes. I suspect it's due to not many stocks back in the 90s getting past my liquidity filter, though this hypothesis has not been tested. You can see this from the trade database. For the 6 year test between 1998 and 2003, there were 1234 possible trades, and for the 3.5 year test between 2004 and 2007, there were 1647 possible trades.