Combining Trend Following with ES-Mean Reversion

Mean Reversion and Trend Following Produces Smooth Equity Curve

Expanding to a large portfolio is easy to do if you have a very large account.  Most retail trading accounts can’t cover the margin requirement nor the risk involved with trading many markets.  Take a look at this chart.

It trades a very small portfolio of five active and diverse markets.  The emini-ES market is traded from the long side only and uses a mean reversion algorithm.  The other markets are trading by our trend friendly Bollinger Band algorithm.  Notice how the equity curve has continued to rise over the past five years.

Portfolio Normalization

Much of this of course can be contributed to the stock market.  Notice how the other markets contribute almost the same amount of $s to the bottom line.  This strategy normalizes all of the markets on perceived market risk – at the beginning of the trading day each market’s average true range is calculated and the largest ATR of the portfolio is extracted from the five markets.  Once this value is obtained, then the rest of the markets’ ATRs are compared to the largest value and the position size is changed accordingly.  For example, let’s say the ATR in $s for the crude oil is $1,000 and $500 for the soybeans, so the position sizing would be 1 contract of crude and 2 contracts of beans.   This normalization process provides even exposure across all market/sectors.  In this example, profits are not re-invested, but that could be easily tested.

Normalization Code [TradingSimula18]

Pre-day portfolio calculations is one of the main cornerstones of TS-18.  Imagine being able to analyze all of the components of a portfolio before the trading day starts, and based on the analysis, make trading and/or position sizing decisions.   Another neat aspect of TS-18 is having the ability to apply a different algorithm to different markets in the portfolio.  Here is the code for the normalization process:

#---------------------------------------------------------------------------------------------------
# Preprocessing prior to the first market of the day is done here
#---------------------------------------------------------------------------------------------------
marketVal1[curMarket] = sAverage(myTrueRange,20,curBar,1)
marketVal2[curMarket] = myBPV
# marketVal1 stores the average range of each market
# marketVal2 stores the bigPointValue for each market
if firstMarketLoop == False and curMarket == 0:
maxATR = 0
for mkt in range(0,numMarkets):
maxATR = max(maxATR,marketVal1[mkt]*marketVal2[mkt])
# just extracted the largest ATR value and stored in maxATR
if firstMarketLoop == False:
if marketVal1[curMarket] > 0 :
posSize = maxATR/(marketVal1[curMarket]*myBPV)
posSize = int(posSize)
posSize = max(posSize,1)
else:
posSize = 1
# using maxATR - make each market the same risk
# Date,CL,EC,ES,S_,TY,
# 20000128,1,0,0,3,1,97191.0
# 20000131,1,1,1,3,1,98258.0
# 20000201,1,1,1,3,1,99163.0
# 20000202,1,1,1,3,1,97642.0
# Here 3 beans are being traded versus 1 for other markets
Normalize Position Size based on ATR

Market Specific Algorithm Code

#  Only enter this logic if the current market is ES
if myComName == "ES" and myClose[curBar-1] < myClose[curBar-2] and \
myClose[curBar] > trendAvg and myClose[curBar-1] < myClose[curBar-3] and mp != 1:
price = myOpen[curBar]
tradeName = "ES:B"
numShares = posSize
profit,curShares,trades = bookTrade(entry,buy,price,myDate[curBar],tradeName,numShares)
barsSinceEntry = 1
marketMonitorList[curMarket].setSysMarkTrackingInfo(tradeName,cumuProfit,mp,barsSinceEntry,curShares,trades)
Apply Different Rules to Different Markets

Let me know what you think.  The concept of portfolio normalization is very important and should be thoroughly tested.  Testing on a one contract basis is great for algorithm prototyping.  If a system makes money on a one contract basis, then you know you are heading in the right direction.

Tags: , , , ,

classic

yes

About This Site

This site is home to George’s Excellent Adventure into TradingSimula_18 and Python.  George grew tired of the old and expensive back testing software so he created his own and now is able to test and develop  Trend Following Systems utilizing EOD data and EOD intra-testing portfolio management.  This software, TradingSimula_18 can be found in his Trend Following Systems: A DIY Project – Batteries Included book – now in its 2nd edition.

December 2024
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031