Portfolio Performance for July 2010

One thing I’ve noticed in trading systems over the years is the observer effect. Typically, when a thoroughly backtested system fails…the trader will dismiss the system as being too optimized. You never hear about the observer effect with real-time trading of the system. That is probably the most difficult aspect of developing systems. Just the mere fact of participating in the price pattern you’ve discovered changes the price pattern. Despite how small a fish you may be in the market.

All we can hope for as system traders is finding an edge that is large enough to accommodate the increased order flow. So, when we jump in and reduce the edge…there is still enough leftover for us to be profitable. I guess, that is why I’ve always traded very long-term systems. And probably why I still lack confidence in this new short-term mean-reversion system.

Moving on…

July was an excellent month for the market. The portfolio was trounced. But, still finished the month with another positive number. This marks the second month trading the new system.

TaylorTree VAMI as of 07/2010

TaylorTree ROI as of 07/2010

TaylorTree Drawdown as of 07/2010

Adding a new chart to the reporting: Investment Levels. This reflects the amount of capital that TaylorTree is invested at the end of the month. As you can see, when the portfolio is less than 100% invested in the market and the market has a month like this one…it is extremely difficult to beat it. Cash drag kills you when the market turns around.
TaylorTree Investment Levels as of 07/2010

The picture above of the alligator is from our stay at The Retreat at Artesian Lakes located just outside Cleveland, TX. They had several cabins overlooking the lakes. Step out on your front porch and this 6ft alligator would come swimming up – day or night.

Later Trades,

MT

New Books

Received 2 books today:

I first heard about John Allspaw from his excellent slides, Ops Meta-Metrics. When I found out he had a book covering capacity planning…well, had to buy it.

Jeffrey MA was the the basis for the main character in the fun book, Bringing Down the House. I’m a stats junkie…so any book covering stats and business is a must-read for yours truly.

MT

Exponential Moving Average (EMA)

Now that we’ve tackled Running Simple Moving Averages (SMA)…let’s move on to Exponential Moving Averages (EMA). You may wonder why we’re not covering Running Exponential Moving Averages? The default formula for EMA is the running method – so we’re already covered.

Check out the posts below to understand the background on Exponential Moving Averages (EMA) and their calculation.

Be careful with using EMAs in your backtesting. Or any of these running type of indicators. Since all of them require a starting value. If that starting value changes – your signals change. Which can happen if you switch price quote providers that have different history requirements. Should not be a big deal but something to be aware of.

Let’s begin. We need to calculate our smoothing factor for the time series. Typical use in technical analysis is:
\alpha = 2.0 / (periods + 1.0)

We can use any value between 0 & 1 for the smoothing factor. Closer to one is less smooth and places greater weight on the more recent values. Use a value of 1 and you get the most recent value back. Closer to zero is more smooth and places greater weight on the older values.

Now, the formula for an EMA given our smoothing factor:
EMA_{today} = EMA_{yesterday} + \alpha(price_{today} - EMA_{yesterday})

Coding in Python we get:

def cumulative_sma(bar, value, prevma):
    '''Returns the simple moving average based on the prior average and a new
    value in a series.

    Keyword arguments:
    bar  --  index or location of the value in the series
    value  --  new value in the series
    prevma  --  previous average

    '''
    result = 0.0

    if bar <= 0:
        result = value

    else:
        result = prevma + ((value - prevma) / (bar + 1.0))

    return result

def ema(bar, series, period, prevma, smoothing=None):
    '''Returns the Exponential Moving Average of a series.

    Keyword arguments:
    bar  --  currrent index or location of the series
    series  --  series of values to be averaged
    period -- number of values in the series to average
    prevma  --  previous exponential moving average
    smoothing -- smoothing factor to use in the series.
        valid values: between 0 & 1.
        default: None - which then uses formula = 2.0 / (period + 1.0)
        closer to 1 to gives greater weight to recent values - less smooth
        closer to 0 gives greater weight to older values -- more smooth
    '''
    if period < 1:
        raise ValueError("period must be 1 or greater")

    if smoothing:
        if (smoothing < 0) or (smoothing > 1.0):
            raise ValueError("smoothing must be between 0 and 1")
        else:
            smoothfactor = smoothing

    else:
         smoothfactor = 2.0 / (period + 1.0)

    result = 0.0

    if bar <= 0:
        result = series[0]

    elif bar < period:
        result = cumulative_sma(bar, series[bar], prevma)

    else:
        result = prevma + smoothfactor * (series[bar] - prevma)

    return result

Example call and results using the typical smoothing factor of 2 / (period + 1):

prices = [32.47, 32.70, 32.77, 33.11, 33.25, 33.23, 33.23, 33.0, 33.04, 33.21]

prevsma = prevema = prices[0]   #1st day nothing to average
for bar, close in enumerate(prices):
    currentema = ema(bar, prices, 5, prevema, smoothing=None)
    currentsma = running_sma(bar, prices, 5, prevsma)

    print "Day %02d Value=%.2f 3-day SMA=%f and EMA=%f" % (bar + 1, close, currentsma, currentema)
    prevema = currentema
    prevsma = currentsma

----------------------------------------------------------
Results of call:
Day 01 Value=32.47 3-day SMA=32.470000 and EMA=32.470000
Day 02 Value=32.70 3-day SMA=32.585000 and EMA=32.585000
Day 03 Value=32.77 3-day SMA=32.646667 and EMA=32.646667
Day 04 Value=33.11 3-day SMA=32.762500 and EMA=32.762500
Day 05 Value=33.25 3-day SMA=32.860000 and EMA=32.860000
Day 06 Value=33.23 3-day SMA=33.012000 and EMA=32.983333
Day 07 Value=33.23 3-day SMA=33.118000 and EMA=33.065556
Day 08 Value=33.00 3-day SMA=33.164000 and EMA=33.043704
Day 09 Value=33.04 3-day SMA=33.150000 and EMA=33.042469
Day 10 Value=33.21 3-day SMA=33.142000 and EMA=33.098313

Portfolio Performance for June 2010

“Time flies like an arrow; fruit flies like a banana” — Groucho Marx

My how the months have zoomed by. As you can see from the site; I moved from blogger to wordpress. Haven’t had the time to do much with the old posts. Most likely I will leave them as is and start from a clean slate. The most important posts anyway are of the portfolio performance and this post will take care of what’s happening there.

TaylorTree VAMI as of 06/2010

Figure 1 - VAMI

You can see in the Figure 1 – VAMI; the portfolio is doing well…breaking free from the market. The main reason for this is a new trading system was added on June 1st. This trading system is a short-term mean-reversion system. It is doing as expected but taking some time to get used to. I’ve spent the better part of 10 years trading a long-term trend-following system. So, moving to a short-term mean-reversion system is going to take some adjustments on my part.

TaylorTree ROI as of 06/2010

Figure 2 - ROI

TaylorTree Drawdown as of 06/2010

Figure 3 - Drawdown

Again, all the charts show the portfolio breaking away from the market. June was a nasty month for the S&P 500…while the portfolio held its own. I feel I still have some work to do on the new system such as the proper risk allocation and determining a better weight for the systems in the portfolio. Also, the new system still has quite a bit of beta that I’d like to scale down. But, overall, a nice start.

On a personal note, I’m back from my yearly pilgrimage to Texas to see family & friends. Trip was good but volatile like the market.

We had to evacuate due to Hurricane Alex in the Gulf – almost lost our car.

San Luis Pass
Picture above is the day prior to the effects of Hurricane Alex.

And our transmission acted up on our stop at Broken Bow, OK – I’m guessing due to all the hill climbing.

Beavers Bend - Broken Bow, OK
I couldn’t get over how clear the water was and the beautiful pine-lined hills surrounding the lake.

We had to cut our losses short in both of the places we would have liked to spend more time. Managing risk vs reward…being a portfolio manager is a 24×7 job.

Later Trades,

MT

Running Simple Moving Average (SMA)

When building a platform to test trading ideas…one of the big issues to deal with is all the indicators that require a spin through the price series in order to calculate. For example, in order to calculate the 200 day simple moving average (SMA) of closing prices for Google today you would have to loop back 200 – 1 days ago and sum the closing prices and divide by 200.

When you are backtesting an idea you often need to start from day 1 of a stock’s trading history and loop forward to the most current day. In essence, pretending each day is the current day at that point in time. Thus, you are looping back 200 – 1 data points for each day in the series. This isn’t such a big deal with a stock such as Google whose trading history is rather limited (2004). But, take a stock like IBM with a more extensive trading history and your code is going to bog down with each call to the SMA indicator. Throw 20,000 securities into your backtest and the looping adds up.

Therefore, running calculations are the preferred method in order to spin just once through the data points. So, in order to calculate the running simple moving average for closing prices you apply the following formula:

SMA_{today} = SMA_{yesterday} + ((Price_{today} - Price_{200 days ago}) / 200)

Straight-forward and avoids the loop. Here’s the sample Python code for the Running SMA:

def cumulative_sma(bar, value, prevma):
    '''Returns the simple moving average based on the prior average and a new
    value in a series.

    Keyword arguments:
    bar  --  index or location of the value in the series
    value  --  new value in the series
    prevma  --  previous average
    '''
    result = 0.0

    if bar <= 0:
        result = value

    else:
        result = prevma + ((value - prevma) / (bar + 1.0))

    return result

def running_sma(bar, series, period, prevma):
    '''Returns the running simple moving average based on prior average
    and new value in a series.

    Keyword arguments:
    bar  --  index or location of the value in the series
    series  --  series to be averaged
    period -- number of values in the series to average
    prevma -- previous simple moving average

    '''
    if period < 1:
        raise ValueError("period must be 1 or greater")

    result = 0.0

    if bar <= 0:
        result = series[0]

    elif bar < period:
        result = cumulative_sma(bar, series[bar], prevma)

    else:
        result = prevma + ((series[bar] - series[bar - period]) / float(period))

    return result

And the example call and results:

prices = [10, 15, 25, 18, 13, 16]
prevsma = prices[0]   #1st day nothing to average so return itself.
for bar, close in enumerate(prices):
    currentsma = running_sma(bar, prices, 3, prevsma)
    print "Today's 3-day SMA=", currentsma
    prevsma = currentsma

------- Results ----------------
Today's 3-day SMA= 10
Today's 3-day SMA= 12.5
Today's 3-day SMA= 16.6666666667
Today's 3-day SMA= 19.3333333333
Today's 3-day SMA= 18.6666666667
Today's 3-day SMA= 15.6666666667