Algorithms for trading the equity curve

Discussions about Money Management and Risk Control.
Vince
Roundtable Fellow
Roundtable Fellow
Posts: 61
Joined: Wed Jun 11, 2003 12:40 pm

Algorithms for trading the equity curve

Post by Vince »

Forum Mgmnt,

Could you start a forum dedicated to algorithms for trading the equity curve?

Cheers :lol:
edward kim
Roundtable Knight
Roundtable Knight
Posts: 344
Joined: Sun Apr 20, 2003 2:42 pm
Location: Silicon Valley / San Jose, CA USA
Contact:

Post by edward kim »

Hi Vince,

Can you specify what you mean by "trading the equity curve"? In the literal sense, we trade instruments and the EC is a result of that trading.

Obviously, there is something that I'm not catching ..

Thanks,

Edward
Vince
Roundtable Fellow
Roundtable Fellow
Posts: 61
Joined: Wed Jun 11, 2003 12:40 pm

Post by Vince »

The EC is the most important "instrument" you will ever trade.
Last edited by Vince on Thu Jun 12, 2003 8:11 am, edited 1 time in total.
blueberrycake
Roundtable Knight
Roundtable Knight
Posts: 125
Joined: Mon Apr 21, 2003 11:04 pm
Location: California

Post by blueberrycake »

Vince wrote:The EC is the most important "instrument" you will ever trade. It is the curve of the profit. By "trading the equity curve" I mean that when my profit is increasing, in the direction of the trend - e.g. Long signals are winning - then, when the direction of the market changes and Long signals start to lose, I want to "stop" (not literally because I need to keep a track of notional results, so that my probabilities etc are updated correctly, for when I start trading Long again) trading during these dd periods. I have tried to use different MA`s over the curve but with unsuitable results, so I was wondering whether there were some algorithms dedicated to this aspect of trading.

Hmmmmm maybe I've just worked out a good way of doing it......but would like discussion on it. I think I read something about R Squared somewhere........
If your equity curve is "tradeable", then your trades have a serial correlation. So test your trades for any such correlation, and if it exists, incorporate it into your primary system. I don't see how trading your equity curve will improve results beyond that.

-bbc
Vince
Roundtable Fellow
Roundtable Fellow
Posts: 61
Joined: Wed Jun 11, 2003 12:40 pm

Post by Vince »

Sussed! Its all in the Water my dear Watson. Trading the EC is absolutely fundamental to traders, because their sole function, is to extract as much profit from the market, as the nature of the market will allow.

EndEx
TradingCoach
Roundtable Knight
Roundtable Knight
Posts: 176
Joined: Thu Apr 17, 2003 9:52 am
Location: Sacramento, CA
Contact:

variations on risk

Post by TradingCoach »

Vince wrote:Sussed! Its all in the Water my dear Watson. Trading the EC is absolutely fundamental to traders, because their sole function, is to extract as much profit from the market, as the nature of the market will allow.

EndEx
Variations of risk/unit exposure can be part of “equity curve” trading…..(1/2% or) 1 % risk on negative slope and 2-3% on positive slope is a proper variation.
...IMHO...
Cheers
Andras
Kiwi
Roundtable Knight
Roundtable Knight
Posts: 513
Joined: Wed Apr 16, 2003 1:18 am
Location: Nowhere near

Post by Kiwi »

Until this weekend I believed that trading ones equity curve was evidence that one was missing something in ones system. Over the weekend I spent time on the wealthlab site and tested a lot of their public systems. I have to say that my overall comment is that for real trading most of them are not nearly as good as I'd need .. but I did learn some new things because many of the systems take advantage of statistical outliers to gain their edge.

I hadn't really got to grips with this approach previously so it was interesting. One particular system uses a different characteristic and takes breakouts in the direction of the trend defined by a shortish moving average. It then limits out with the target set by the close and whether it is above or below the trend still. The usual holding time is 1-2 days and the profit is greater than buy and hold (but PF is weak).

The strangest thing is that the market goes through quite long periods when the system is wrong (30-100 days which can include both shorts and longs). Then periods when its right (30-60 days). So, because it gets a signal virtually every day a short term moving average like an T3 on the equity curve could provide a simple way of deciding when to take the signals and when to stop.

On the other hand there may be a better way if you measured market behaviour directly ... but another bit of arrogance disappears in the face of the markets :)

John
blueberrycake
Roundtable Knight
Roundtable Knight
Posts: 125
Joined: Mon Apr 21, 2003 11:04 pm
Location: California

Post by blueberrycake »

Kiwi wrote: The strangest thing is that the market goes through quite long periods when the system is wrong (30-100 days which can include both shorts and longs). Then periods when its right (30-60 days). So, because it gets a signal virtually every day a short term moving average like an T3 on the equity curve could provide a simple way of deciding when to take the signals and when to stop.
I would strongly recommend a serial correlation test (3 mins in Excel) to be sure, since we all know that randomness will often appear non-random.

-bbc
Kiwi
Roundtable Knight
Roundtable Knight
Posts: 513
Joined: Wed Apr 16, 2003 1:18 am
Location: Nowhere near

Emarsi Tests

Post by Kiwi »

I didnt run the test sorry bbc.

Instead, before I saw your response, I created a relatively simple channel on the equity curve. On some instruments short channels were quite successful, on others poor. Longer channels resulted in too high a reduction in the profitable periods to compensate for any reduction in drawdowns.

It started to feel a lot like the traditional filter problems.

On examination the biggest problem is that about 50% the losing trades that break the channel penetrate it strongly.

Hmmm .... onto the backburner for now.
TradingCoach
Roundtable Knight
Roundtable Knight
Posts: 176
Joined: Thu Apr 17, 2003 9:52 am
Location: Sacramento, CA
Contact:

Post by TradingCoach »

blueberrycake wrote: I would strongly recommend a serial correlation test (3 mins in Excel) to be sure, since we all know that randomness will often appear non-random.

-bbc
How do you do that?
blueberrycake
Roundtable Knight
Roundtable Knight
Posts: 125
Joined: Mon Apr 21, 2003 11:04 pm
Location: California

Post by blueberrycake »

TradingCoach wrote: How do you do that?
Take all your trades and put them into a column in Excel. Then put the same trades in the adjacent column, but offset the second column by one row. The use the Excel correlation function (dont remember exact name) to compute the correlation between the two columns. If one exists, then the trades are serially correlated. There are all kinds of additional tests you could run, but this is a good starting point.

-bbc
redbullpeter
Roundtable Fellow
Roundtable Fellow
Posts: 82
Joined: Mon Apr 28, 2003 9:12 am
Location: London, UK

Post by redbullpeter »

Apologies in advance for my ignorance.

What does serial correlation tell you?

Is it a good or bad thing? How good is good and how bad is bad?
Take all your trades and put them into a column in Excel.
For my understanding, would this mean I would have two columns of just the trade prices?

Thanks

red
blueberrycake
Roundtable Knight
Roundtable Knight
Posts: 125
Joined: Mon Apr 21, 2003 11:04 pm
Location: California

Post by blueberrycake »

redbullpeter wrote:Apologies in advance for my ignorance.

What does serial correlation tell you?

Is it a good or bad thing? How good is good and how bad is bad?
Take all your trades and put them into a column in Excel.
For my understanding, would this mean I would have two columns of just the trade prices?

Thanks

red

Hi Red,

All serial correlation tells you is if the outcome of a particular trade has any effect on the following trade(s). In other words, it's a simple test to see if winning/losing streaks are random or not. If it happens that they are not random, then you can improve returns by skipping trades or varying your "bet size" by looking at whether the previous trade(s) were winners or losers.

When entering this into Excel, make a list of all the trade outcomes, in whatever unit of measurement you size them in (ie percent gain/loss for each trade) and put that into the two offsetting columns. That what in each row you have the outcome of one trade in the first column, and the outcome of the following trade in the adjacent column. Hope this makes sense.

-bbc
Kiwi
Roundtable Knight
Roundtable Knight
Posts: 513
Joined: Wed Apr 16, 2003 1:18 am
Location: Nowhere near

Serial Correlation

Post by Kiwi »

Attached as a zip is the TS2000i code for the EMARSI Public Wealthlab Script originally created by Raghuram Bala plus the TS2000i strategy report on QQQ. EMARSI takes short trades in the direction of the trend and seems to make money when trends have conviction and lose it when they are confused (the language is chosen deliberately :) ).

QQQ is chosen because it is profitable (as are most of the contributing stocks) and widely available for testing. 58% winners. 1.35 profit factor. Zero slippage allowed for simplicity.

I tested it for serial correlation using the Xcel method on 1, 5 and 22 day intervals. The results were 0.094, 0.094 and 0.024. Given that testing the string against itself gave a correlation of 1.000 this suggests to me that the serial correlation is very low. Perhaps Bbc or Christian could comment on that?

I included the TS2k report as QQQEmarsi.xls and the serial correlation results as SerCorrel.xls.

John
Attachments
Serial Correlation.zip
(76.65 KiB) Downloaded 1403 times
TradingCoach
Roundtable Knight
Roundtable Knight
Posts: 176
Joined: Thu Apr 17, 2003 9:52 am
Location: Sacramento, CA
Contact:

Q

Post by TradingCoach »

Just out of curiousity why is there a blank file in the zip? :shock:
Kiwi
Roundtable Knight
Roundtable Knight
Posts: 513
Joined: Wed Apr 16, 2003 1:18 am
Location: Nowhere near

What was in the blank text file

Post by Kiwi »

:shock:

Should have had the TS code below. Note that the original Emarsi has C+Z but I removed it because it was asymetric wrt shorts and longs and I suspect it was a mistake rather than intentional. Just remove the {} if you want it back in.

Code: Select all

Var: Z(0);

Z = AvgTrueRange(6)/4;

If MarketPosition <> 0 then begin
 
      if (C{+z}) < Xaverage(C,28 ) or (RSI(C,12)>=70) then       
      begin
           if MarketPosition=1 then
               begin
                  ExitLong("SellL") next bar At C-Z Limit;
               end
             else
               begin
                 ExitShort("CoverL") next bar at C-Z Limit;
               end;
       end;

      if (C{+z}) > Xaverage(C,28 ) or (RSI(C,12)<=30) then  {Error XXXX}
      begin
           if MarketPosition=1 then
               begin
                 ExitLong("SellH") next bar At C+Z Limit; 
               end
             else
               begin
                 ExitShort("CoverH") next bar at C+Z Limit;
               end;
       end; 
end else Begin
     if C>Xaverage(C,28 ) then
       Buy at C + Z/2 Stop
     else
       Sell at C - Z/2 Stop;
End;
Luke
Contributing Member
Contributing Member
Posts: 5
Joined: Wed Jun 11, 2003 9:12 pm
Location: Australia

Post by Luke »

For short term systems, my research has shown that trading them only when they are making money (eg average of last 20 trades > 0) improves average return per trade.

I don't know if it is such a good idea for long term systems where you are relying on outlier trades so much.
Mark Johnson
Roundtable Knight
Roundtable Knight
Posts: 122
Joined: Thu Apr 17, 2003 9:49 am

Trading the equity curve of I-Master, some test results

Post by Mark Johnson »

To stimulate your thinking and to encourage you to perform some research on your own, I'm attaching a graph of a little research experiment. I ran the vendor-sold system I-Master with and without "trading the equity curve".

The first run (purple line) is I-Master trading a constant 2 contracts on every signal without fail. Two hundred dollars per contract is used to simulate commissions and slippage.

Then code was added to reduce positionsize when the theoretical equity of taking every single trade that I-Master signalled, was below its N-day moving average. I ran this variation three times, for N=10, 20, and 40 day moving averages. A little snippet of EasyLanguage:

Code: Select all

avg_theor = @Average(theoretical, Ndays);
If(theoretical > avg_theor) then ncars=2 else ncars=1;
...
If (IMaster buy conditions) then Buy("BullBuy") ncars contracts at (...price...) ;
... repeated for all the other buy and sell statements in I-Master... 
I wouldn't say that I-Master's performance has been improved by this modification; however, that's just my opinion and you may feel otherwise.
Attachments
.png format
.png format
imeq.png (18.18 KiB) Viewed 23552 times
Luke
Contributing Member
Contributing Member
Posts: 5
Joined: Wed Jun 11, 2003 9:12 pm
Location: Australia

Post by Luke »

G'day Mark,
I get similar results to the one you show above on my systems. They all have quite smooth equity curves, and filtering trades does reduce net profits. But it might be misleading because we are only looking at systems that have worked well in the past.

How would filtering go on systems that fall apart after a period of time? As perhaps a better indication of effectiveness I looked at the results of a simple short term system that has a small edge, and ranges from being terrible to trade on some markets to excellent on others.

Tested on 20 markets, the system generated 46528 trades with a mean return per trade of 0.119, which is the average gain in points divided by recent volatility, so the results can be normalised across all markets.

In the table below, x is the threshold of which the last 20 trades average has to be greater than to allow the next trade to be taken


x mean no. trades
0 0.135 31054
0.1 .15 23269
0.25 0.18 12773
0.50 0.225 3197

There is definitely a positive correlation between recent trade performance and the next trade.

The problem with this method is that it can lead to significant whipsaws if the system goes into a consolidation period.

To overcome this, the second method I have tested is as follows:
- only take the next trade if there has been an all time equity high within the last 20 trades.

On the same dataset, I ended up with a mean return of 0.162 with 23562 trades. This is almost a 50% improvement in average profit per trade.

I think this one works better because the all time equity high keeps us out of markets that just don't make money at all, and reduces the whipsaw problem when the system flatlines for a period.

The second filtering method is the one I use in my actual trading. Of course I don't know for sure if it will work better than taking every trade in the future, but I do know I have an "insurance policy", whereby I won't continue to trade a system that falls apart completely with a huge drawdown.

This filter works quite well for my systems as they hit new equity highs regularly so I rarely have to stop taking signals. I would be interested to see how this one works on your i-master equity curve if you have time.
Mark Johnson
Roundtable Knight
Roundtable Knight
Posts: 122
Joined: Thu Apr 17, 2003 9:49 am

Post by Mark Johnson »

Luke, thanks for sharing the results of your research! I hope and trust it will inspire many other Roundtable members to limber up their research muscles and put some "trading the equity curve" ideas to the test.

Mark Johnson
Post Reply