You are on page 1of 180

QuantStrat TradeR

Trading, QuantStrat, R, and more.

Category Archives: Dr. John Ehlers


Ehlerss Autocorrelation Periodogram
Posted on February 15, 2017 Posted in Dr. John Ehlers, R, Trading 7 Comments

This post will introduce John Ehlerss Autocorrelation Periodogram mechanisma mechanism designed to
dynamically find a lookback period. That is, the most common parameter optimized in backtests is the
lookback period.

Before beginning this post, I must give credit where its due, to one Mr. Fabrizio Maccallini, the head of
structured derivatives at Nordea Markets in London. You can find the rest of the repository he did for Dr.
John Ehlerss Cycle Analytics for Traders on his github. I am grateful and honored that such intelligent and
experienced individuals are helping to bring some of Dr. Ehlerss methods into R.

The point of the Ehlers Autocorrelation Periodogram is to dynamically set a period between a minimum and
a maximum period length. While I leave the exact explanation of the mechanic to Dr. Ehlerss book, for all
practical intents and purposes, in my opinion, the punchline of this method is to attempt to remove a massive
source of overfitting from trading system creationnamely specifying a lookback period.

SMA of 50 days? 100 days? 200 days? Well, this algorithm takes that possibility of overfitting out of your
hands. Simply, specify an upper and lower bound for your lookback, and it does the rest. How well it does it
is a topic of discussion for those well-versed in the methodologies of electrical engineering (Im not), so feel
free to leave comments that discuss how well the algorithm does its job, and feel free to blog about it as
well.

In any case, heres the original algorithm code, courtesy of Mr. Maccallini:

1 AGC <- function(loCutoff = 10, hiCutoff = 48, slope = 1.5) { accSlope = -slope #
acceptableSlope = 1.5 dB ratio = 10 ^ (accSlope / 20) if ((hiCutoff - loCutoff) >
2
0)
3 factor <- ratio ^ (2 / (hiCutoff - loCutoff));
4 return (factor)
5 }
6
7 autocorrPeriodogram <- function(x, period1 = 10, period2 = 48, avgLength = 3) {
# high pass filter
8 alpha1 <- (cos(sqrt(2) * pi / period2) + sin(sqrt(2) * pi / period2) - 1) /
9 cos(sqrt(2) * pi / period2)
1 hp <- (1 - alpha1 / 2) ^ 2 * (x - 2 * lag(x) + lag(x, 2))
0 hp <- hp[-c(1, 2)]
11 hp <- filter(hp, (1 - alpha1), method = "recursive")
hp <- c(NA, NA, hp)
1 hp <- xts(hp, order.by = index(x))
2 # super smoother
1 a1 <- exp(-sqrt(2) * pi / period1)
3 b1 <- 2 * a1 * cos(sqrt(2) * pi / period1)
c2 <- b1
1 c3 <- -a1 * a1
4 c1 <- 1 - c2 - c3
1 filt <- c1 * (hp + lag(hp)) / 2
5 leadNAs <- sum(is.na(filt))
filt <- filt[-c(1: leadNAs)]
1
filt <- filter(filt, c(c2, c3), method = "recursive")
6 filt <- c(rep(NA, leadNAs), filt)
1 filt <- xts(filt, order.by = index(x))
7 # Pearson correlation for each value of lag
1 autocorr <- matrix(0, period2, length(filt))
for (lag in 2: period2) {
8 # Set the average length as M
1 if (avgLength == 0) M <- lag
9 else M <- avgLength
2 autocorr[lag, ] <- runCor(filt, lag(filt, lag), M)
0 }
autocorr[is.na(autocorr)] <- 0
2 # Discrete Fourier transform
1 # Correlate autocorrelation values with the cosine and sine of each period of
2 interest
2 # The sum of the squares of each value represents relative power at each period
cosinePart <- sinePart <- sqSum <- R <- Pwr <- matrix(0, period2, length(filt))
2 for (period in period1: period2) {
3 for (N in 2: period2) {
2 cosinePart[period, ] = cosinePart[period, ] + autocorr[N, ] * cos(2 * N * pi /
4 period)
2 sinePart[period, ] = sinePart[period, ] + autocorr[N, ] * sin(2 * N * pi /
period)
5 }
2 sqSum[period, ] = cosinePart[period, ] ^ 2 + sinePart[period, ] ^ 2
6 R[period, ] <- EMA(sqSum[period, ] ^ 2, ratio = 0.2)
2 }
7 R[is.na(R)] <- 0
# Normalising Power
2 K <- AGC(period1, period2, 1.5)
8 maxPwr <- rep(0, length(filt)) for(period in period1: period2) { for (i in 1:
2 length(filt)) { if (R[period, i] >= maxPwr[i]) maxPwr[i] <- R[period, i]
9 else maxPwr[i] <- K * maxPwr[i]
}
3 }
0 for(period in 2: period2) {
3 Pwr[period, ] <- R[period, ] / maxPwr
1 }
3 # Compute the dominant cycle using the Center of Gravity of the spectrum
Spx <- Sp <- rep(0, length(filter))
2 for(period in period1: period2) {
3 Spx <- Spx + period * Pwr[period, ] * (Pwr[period, ] >= 0.5)
3 Sp <- Sp + Pwr[period, ] * (Pwr[period, ] >= 0.5)
3 }
dominantCycle <- Spx / Sp
4
dominantCycle[is.nan(dominantCycle)] <- 0
3 dominantCycle <- xts(dominantCycle, order.by=index(x))
5 dominantCycle <- dominantCycle[dominantCycle > 0]
3 return(dominantCycle)
6 #heatmap(Pwr, Rowv = NA, Colv = NA, na.rm = TRUE, labCol = "", add.expr =
lines(dominantCycle, col = 'blue'))
3 }
7
3
8
3
9
4
0
4
1
4
2
4
3
4
4
4
5
4
6
4
7
4
8
4
9
5
0
5
1
5
2
5
3
5
4
5
5
5
6
5
7
5
8
5
9
6
0
6
1
6
2
6
3
6
4
6
5
6
6
6
7
6
8
6
9
One thing I do notice is that this code uses a loop that says for(i in 1:length(filt)), which is an O(data points)
loop, which I view as the plague in R. While Ive used Rcpp before, its been for only the most basic of
loops, so this is definitely a place where the algorithm can stand to be improved with Rcpp due to Rs
inherent poor looping.

Those interested in the exact logic of the algorithm will, once again, find it in John Ehlerss Cycle Analytics
For Traders book (see link earlier in the post).

Of course, the first thing to do is to test how well the algorithm does what it purports to do, which is to
dictate the lookback period of an algorithm.

Lets run it on some data.

1 getSymbols('SPY', from = '1990-01-01')


2
3 t1 <- Sys.time()
4 out <- autocorrPeriodogram(Ad(SPY), period1 = 120, period2 = 252, avgLength = 3)
5 t2 <- Sys.time() print(t2-t1)

And the result:

1>avgLength
t1 <- Sys.time() > out <- autocorrPeriodogram(Ad(SPY), period1 = 120, period2 = 252,
= 3) > t2 <- Sys.time() > print(t2-t1)
2Time difference of 33.25429 secs

Now, what does the algorithm-set lookback period look like?

1 plot(out)

Lets zoom in on 2001 through 2003, when the markets went through some upheaval.

1 plot(out['2001::2003']
In this zoomed-in image, we can see that the algorithms estimates seem fairly jumpy.

Heres some code to feed the algorithms estimates of n into an indicator to compute an indicator with a
dynamic lookback period as set by Ehlerss autocorrelation periodogram.

1
2 acpIndicator <- function(x, minPeriod, maxPeriod, indicatorFun = EMA, ...) {
acpOut <- autocorrPeriodogram(x = x, period1 = minPeriod, period2 = maxPeriod)
3 roundedAcpNs <- round(acpOut, 0) # round to the nearest integer
4 uniqueVals <- unique(roundedAcpNs) # unique integer values
5 out <- xts(rep(NA, length(roundedAcpNs)), order.by=index(roundedAcpNs))
6
7 for(i in 1:length(uniqueVals)) { # loop through unique values, compute indicator
8 tmp <- indicatorFun(x, n = uniqueVals[i], ...)
out[roundedAcpNs==uniqueVals[i]] <- tmp[roundedAcpNs==uniqueVals[i]]
9 }
10 return(out)
11 }
12

And here is the function applied with an SMA, to tune between 120 and 252 days.

1 ehlersSMA <- acpIndicator(Ad(SPY), 120, 252, indicatorFun = SMA)


2
3 plot(Ad(SPY)['2008::2010'])
4 lines(ehlersSMA['2008::2010'], col = 'red')

And the result:


As seen, this algorithm is less consistent than I would like, at least when it comes to using a simple moving
average.

For now, Im going to leave this code here, and let people experiment with it. I hope that someone will find
that this indicator is helpful to them.

Thanks for reading.

NOTES: I am always interested in networking/meet-ups in the northeast (Philadelphia/NYC). Furthermore,


if you believe your firm will benefit from my skills, please do not hesitate to reach out to me. My linkedin
profile can be found here.

Lastly, I am volunteering to curate the R section for books on quantocracy. If you have a book about R that
can apply to finance, be sure to let me know about it, so that I can review it and possibly recommend it.
Thakn you.

A John Ehlers oscillator Cycle RSI(2)


Posted on August 11, 2014 Posted in Dr. John Ehlers, ETFs, QuantStrat, R, Trading Tagged R 9
Comments
Since Ive hit a rut in trend following (how do you quantify rising/falling/flat? What even defines those three
terms in precise, machine definition? How do you avoid buying tops while not getting chopped by
whipsaws?), I decided to look the other way, with oscillators. Certainly, Im not ready to give up on Dr.
Ehlers just yet. So, in this post, Ill introduce a recent innovation of the RSI by Dr. John Ehlers.

The indicator is Dr. Ehlerss modified RSI from Chapter 7 of Cycle Analytics for Traders.

For starters, heres how the Ehlers RSI is different than the usual ones: it gets filtered with a high-pass filter
and then smoothed with a supersmoother filter. While Michael Kapler also touched on this topic a while
back, I suppose it cant hurt if I attempted to touch on it myself.

Here is the high pass filter and the super smoother, from the utility.R file in DSTrading. Theyre not
exported since as of the moment, theyre simply components of other indicators.

1
2
3 highPassFilter <- function(x) {
alpha1 <- (cos(.707*2*pi/48)+sin(.707*2*pi/48)-1)/cos(.707*2*pi/48)
4 HP <- (1-alpha1/2)*(1-alpha1/2)*(x-2*lag(x)+lag(x,2))
5 HP <- HP[-c(1,2)]
6 HP <- filter(HP, c(2*(1-alpha1), -1*(1-alpha1)*(1-alpha1)), method="recursive")
7 HP <- c(NA, NA, HP)
8 HP <- xts(HP, order.by=index(x))
return(HP)
9 }
10
11 superSmoother <- function(x) {
12 a1 <- exp(-1.414*pi/10)
13 b1 <- 2*a1*cos(1.414*pi/10)
14 c2 <- b1
c3 <- -a1*a1
15 c1 <- 1-c2-c3
16 filt <- c1*(x+lag(x))/2
17 leadNAs <- sum(is.na(filt))
18 filt <- filt[-c(1:leadNAs)]
filt <- filter(filt, c(c2, c3), method="recursive")
19 filt <- c(rep(NA,leadNAs), filt)
20 filt <- xts(filt, order.by=index(x))
21 }
22
23

In a nutshell, both of these functions serve to do an exponential smoothing on the data using some statically
computed trigonometric quantities, the rationale of which I will simply defer to Dr. Ehlerss book (link
here).

Heres the modified ehlers RSI, which I call CycleRSI, from the book in which its defined:

1 "CycleRSI" <- function(x, n=20) {


filt <- superSmoother(highPassFilter(x))
2
diffFilt <- diff(filt)
3 posDiff <- negDiff <- diffFilt
4 posDiff[posDiff < 0] <- 0
5 negDiff[negDiff > 0] <- 0
6 negDiff <- negDiff*-1
posSum <- runSum(posDiff, n)
7 negSum <- runSum(negDiff, n)
8 denom <- posSum+negSum
9 rsi <- posSum/denom
10 rsi <- superSmoother(rsi)*100
11 colnames(rsi) <- "CycleRSI"
return(rsi)
12
13 }
14
15

Heres a picture comparing four separate RSIs.

The first is the RSI featured in this post (cycle RSI) in blue. The next is the basic RSI(2) in red. The one
after that is Larry Connorss Connors RSI , which may be touched on in the future, and the last one, in
purple, is the generalized Laguerre RSI, which is yet another Dr. Ehlers creation (which Ill have to test
sometime in the future).

To start things off with the Cycle RSI, I decided to throw a simple strategy around it:

Buy when the CycleRSI(2) crosses under 10 when the close is above the SMA200, which is in the vein of a
Larry Connors trading strategy from Short Term ETF Trading Strategies That Work (whether they work or
not remains debatable), and sell when the CycleRSI(2) crosses above 70, or when the close falls below the
SMA200 so that the strategy doesnt get caught in a runaway downtrend.

Since the strategy comes from an ETF Trading book, I decided to use my old ETF data set, from 2003
through 2010.

Heres the strategy code, as usual:

1 require(DSTrading)
require(IKTrading)
2 require(quantstrat)
3 require(PerformanceAnalytics)
4
5 initDate="1990-01-01"
from="2003-01-01"
6
to="2010-12-31"
7 options(width=70)
8 verbose=TRUE
9
10 source("demoData.R")
11
12 #trade sizing and initial equity settings
tradeSize <- 100000
13 initEq <- tradeSize*length(symbols)
14
15 strategy.st <- portfolio.st <- account.st <- "Cycle_RSI_I"
16 rm.strat(portfolio.st)
17 rm.strat(strategy.st)
18 initPortf(portfolio.st, symbols=symbols, initDate=initDate, currency='USD')
initAcct(account.st, portfolios=portfolio.st, initDate=initDate,
19 currency='USD',initEq=initEq)
20 initOrders(portfolio.st, initDate=initDate)
21 strategy(strategy.st, store=TRUE)
22
23 #parameters
nRSI=2
24 RSIentry=10
25 RSIexit=70
26
27 nSMA=200
28
29 period=10
30 pctATR=.04
31
#indicators
32 add.indicator(strategy.st, name="lagATR",
33 arguments=list(HLC=quote(HLC(mktdata)), n=period),
34 label="atrX")
35 add.indicator(strategy.st, name="SMA",
36 arguments=list(x=quote(Cl(mktdata)), n=nSMA),
label="SMA")
37 add.indicator(strategy.st, name="CycleRSI",
38 arguments=list(x=quote(Cl(mktdata)), n=nRSI),
39 label="RSI")
40
41 #signals
add.signal(strategy.st, name="sigComparison",
42 arguments=list(columns=c("Close", "SMA"), relationship="gt"),
43 label="ClGtSMA")
44
45 add.signal(strategy.st, name="sigThreshold",
46 arguments=list(column="CycleRSI.RSI", threshold=RSIentry,
47 relationship="lt", cross=FALSE),
label="RSIltEntryThresh")
48
49 add.signal(strategy.st, name="sigAND",
50 arguments=list(columns=c("ClGtSMA", "RSIltEntryThresh"),
51 cross=TRUE),
52 label="longEntry")
53
add.signal(strategy.st, name="sigCrossover",
54
arguments=list(columns=c("Close", "SMA"), relationship="lt"),
55 label="exitSMA")
56
57 add.signal(strategy.st, name="sigThreshold",
58 arguments=list(column="CycleRSI.RSI", threshold=RSIexit,
59 relationship="gt", cross=TRUE),
label="longExit")
60
61
62
63
64
65
66
67
68
69
70
71
72 #rules
73 #rules
74 add.rule(strategy.st, name="ruleSignal",
arguments=list(sigcol="longEntry", sigval=TRUE,
75 ordertype="market",
76 orderside="long", replace=FALSE,
77 prefer="Open", osFUN=osDollarATR,
78 tradeSize=tradeSize, pctATR=pctATR,
79 atrMod="X"),
type="enter", path.dep=TRUE)
80
81 add.rule(strategy.st, name="ruleSignal",
82 arguments=list(sigcol="longExit", sigval=TRUE,
83 orderqty="all", ordertype="market",
84 orderside="long", replace=FALSE,
85 prefer="Open"),
type="exit", path.dep=TRUE)
86
87 add.rule(strategy.st, name="ruleSignal",
88 arguments=list(sigcol="exitSMA", sigval=TRUE,
89 orderqty="all", ordertype="market",
90 orderside="long", replace=FALSE,
prefer="Open"),
91 type="exit", path.dep=TRUE)
92
93 #apply strategy
94 t1 <- Sys.time()
95 out <- applyStrategy(strategy=strategy.st,portfolios=portfolio.st)
96 t2 <- Sys.time()
print(t2-t1)
97
98 #set up analytics
99 updatePortf(portfolio.st)
10 dateRange <- time(getPortfolio(portfolio.st)$summary)[-1]
0 updateAcct(portfolio.st,dateRange)
updateEndEq(account.st)
10
1
10
2
10
3
10
4
10
5
10
6
And here are the results:

1 > (aggPF <- sum(tStats$Gross.Profits)/-sum(tStats$Gross.Losses))


2 [1] 1.846124
> (aggCorrect <- mean(tStats$Percent.Positive))
3 [1] 65.071
4 > (numTrades <- sum(tStats$Num.Trades))
5 [1] 2048
6 > (meanAvgWLR <- mean(tStats$Avg.WinLoss.Ratio[tStats$Avg.WinLoss.Ratio < Inf],
na.rm=TRUE))
7 [1] 1.028333
8
9 > print(t(durStats))
1 [,1]
0 Min 1
11 Q1 6
Med 9
1 Mean 11
2 Q3 14
1 Max 43
3 WMin 1
WQ1 7
1 WMed 9
4 WMean 11
1 WQ3 13
5 WMax 40
1 LMin 1
LQ1 6
6 LMed 11
1 LMean 12
7 LQ3 15
1 LMax 43
8
1 > print(mean(as.numeric(as.character(mktExposure$MktExposure))))
[1] 0.2806
9
2 > mean(corMeans)
0 [1] 0.2763
2
1 > SharpeRatio.annualized(portfRets)
2 [,1]
Annualized Sharpe Ratio (Rf=0%) 1.215391
2 > Return.annualized(portfRets)
2 [,1]
3 Annualized Return 0.1634448
2 > maxDrawdown(portfRets)
4 [1] 0.1694307
2
5
2
6
2
7
2
8
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
4
0
4
1
4
2
4
3
4
4

Overall, the statistics dont look bad. However, the 1:1 annualized returns to max drawdown isnt
particularly pleasing, as it means that this strategy cant be leveraged effectively to continue getting outsized
returns in this state. Quite irritating. Heres the equity curve.

In short, as with other mean reverters, when drawdowns happen, they happen relatively quickly and brutally.
Heres an individual instrument position chart.

By the looks of things, the strategy does best in a market that grinds upwards, rather than a completely
choppy sideways market.

Finally, heres some code for charting all of the different trades.

1 agg.chart.ME <- function(Portfolio, Symbols, type=c("MAE", "MFE"), scale=c("cash",


2 "percent", "tick")) {
type=type[1]
3 scale=scale[1]
4 trades <- list()
5 length(trades) <- length(Symbols)
6 for(Symbol in Symbols) {
trades[[Symbol]] <- pts <- perTradeStats(Portfolio=Portfolio, Symbol=Symbol,
7 includeOpenTrade=FALSE)
8 }
9 trades <- do.call(rbind, trades)
1 trades$Pct.Net.Trading.PL <- 100 * trades$Pct.Net.Trading.PL
0 trades$Pct.MAE <- 100 * trades$Pct.MAE
trades$Pct.MFE <- 100 * trades$Pct.MFE
11 profitable <- (trades$Net.Trading.PL > 0)
1 switch(scale, cash = {
2 .ylab <- "Profit/Loss (cash)"
1 if (type == "MAE") {
.cols <- c("MAE", "Net.Trading.PL")
3 .xlab <- "Drawdown (cash)"
1 .main <- "Maximum Adverse Excursion (MAE)"
4 } else {
1 .cols <- c("MFE", "Net.Trading.PL")
5 .xlab <- "Run Up (cash)"
.main <- "Maximum Favourable Excursion (MFE)"
1 }
6 }, percent = {
1 .ylab <- "Profit/Loss (%)"
if (type == "MAE") {
7
.cols <- c("Pct.MAE", "Pct.Net.Trading.PL")
1 .xlab <- "Drawdown (%)"
8 .main <- "Maximum Adverse Excursion (MAE)"
1 } else {
9 .cols <- c("Pct.MFE", "Pct.Net.Trading.PL")
.xlab <- "Run Up (%)"
2 .main <- "Maximum Favourable Excursion (MFE)"
0 }
2 }, tick = {
1 .ylab <- "Profit/Loss (ticks)"
2 if (type == "MAE") {
.cols <- c("tick.MAE", "tick.Net.Trading.PL")
2 .xlab <- "Drawdown (ticks)"
2 .main <- "Maximum Adverse Excursion (MAE)"
3 } else {
2 .cols <- c("tick.MFE", "tick.Net.Trading.PL")
.xlab <- "Run Up (ticks)"
4 .main <- "Maximum Favourable Excursion (MFE)"
2 }
5 })
2 .main <- paste("All trades", .main)
6 plot(abs(trades[, .cols]), type = "n", xlab = .xlab, ylab = .ylab,
main = .main)
2 grid()
7 points(abs(trades[profitable, .cols]), pch = 24, col = "green",
2 bg = "green", cex = 0.6)
8 points(abs(trades[!profitable, .cols]), pch = 25, col = "red",
2 bg = "red", cex = 0.6)
abline(a = 0, b = 1, lty = "dashed", col = "darkgrey")
9 legend(x = "bottomright", inset = 0.1, legend = c("Profitable Trade",
3 "Losing Trade"), pch = c(24, 25),
0 col = c("green", "red"),
3 pt.bg = c("green", "red"))
}
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
4
0
4
1
4
2
4
3
4
4
4
5
4
6
4
7
4
8
4
9
5
0
5
1
5
2
5
3
5
4
5
5
5
6
5
7
5
8
5
9
6
0

And the resulting plot:


One last thing to notethat $50,000 trade in the upper left hand corner? That was a yahoo data issue and is
a false print. Beyond that, once again, this seems like standard fare for a mean reverterwhen trades go bad,
theyre *really* bad, but the puzzle of where to put a stop is a completely separate issue, as it usually means
locking in plenty of losses that decrease in magnitude, along with possibly turning winners into losers. On
the flip side, heres the maximum favorable excursion plot.
In short, there are definitely trades that could have been stopped for a profit that turned into losers.

In conclusion, while the initial trading system seems to be a good start, its far from complete.

Thanks for reading.

Another Failed Volatility Histeresis: Ehlerss


Own Idea
Posted on August 4, 2014 Posted in Dr. John Ehlers, QuantStrat, R, Trading Tagged R 1 Comment

This week, I attempted to use Ehlerss own idea from this presentation.

Essentially, the idea is that when an indicator is flat, line crossings can produce whipsaws, so add a fraction
of the daily range to the lagged indicator, and see if the non-lagged indicator crosses the threshold. In this
case, its an exponentially smoothed daily range thats used to compute the bands. I ran this from 2012
through the present day at the time of this writing (July 14, 2014), as the original link goes through most of
the 2000s. (Also, be sure youre using my most up-to-date IKTrading package, as I updated the quandClean
function to deal with some intraday messy data issues that had gone unnoticed before.)

The settings I used were John Ehlerss original settings that is, a 20 day analysis period, a 10 day
exponential band smoothing (that is, the band is computed as .1*(high-low)+.9*band), entered upon the
percent B (that is, the current FRAMA minus the low band over the difference of the bands), and the fraction
is 1/10th of the daily range.

Heres the indicator used:


1
2 FRAMAbands <- function(HLC, n=126, FC=1, SC=300, nBands=n/2, bandFrac=10, ...) {
3 frama <- FRAMA(HLC, n=n, FC=FC, SC=SC, ...)
band <- Hi(HLC) - Lo(HLC)
4 band <- xts(filter(1/nBands*band, 1-1/nBands, method="recursive"),
5 order.by=index(frama))
6 bandUp <- frama$trigger + band/bandFrac
7 bandDn <- frama$trigger - band/bandFrac
pctB <- (frama$FRAMA-bandDn)/(bandUp-bandDn)
8
out <- cbind(frama, pctB)
9 colnames(out) <- c("FRAMA", "trigger", "pctB")
1 return(out)
0 }
11

And heres the strategy code:

1 source("futuresData.R")
2
3 #trade sizing and initial equity settings
tradeSize <- 100000
4 initEq <- tradeSize*length(symbols)
5
6 strategy.st <- portfolio.st <- account.st <- "FRAMA_BANDS_I"
7 rm.strat(portfolio.st)
8 rm.strat(strategy.st)
initPortf(portfolio.st, symbols=symbols, initDate=initDate, currency='USD')
9 initAcct(account.st, portfolios=portfolio.st, initDate=initDate,
1 currency='USD',initEq=initEq)
0 initOrders(portfolio.st, initDate=initDate)
11strategy(strategy.st, store=TRUE)
1
2 #parameters
FC = 1
1 SC = 300
3 n = 20
1 triggerLag = 1
4 nBands = 10
1 bandFrac=10
entryThreshPctB=1
5 exitThreshPctB=.5
1
6 period=10
1 pctATR=.06
7
1 #indicators
add.indicator(strategy.st, name="FRAMAbands",
8 arguments=list(HLC=quote(HLC(mktdata)), FC=FC, SC=SC,
1 n=n, triggerLag=triggerLag, nBands=nBands,
9 bandFrac=bandFrac),
2 label="Fbands")
0
2 add.indicator(strategy.st, name="lagATR",
arguments=list(HLC=quote(HLC(mktdata)), n=period),
1 label="atrX")
2
2 #signals
2 add.signal(strategy.st, name="sigThreshold",
3 arguments=list(column="pctB.Fbands",
threshold=entryThreshPctB,
2 relationship="gt", cross=TRUE),
4 label="longEntry")
2
5 add.signal(strategy.st, name="sigThreshold",
2 arguments=list(column="pctB.Fbands",
threshold=exitThreshPctB,
6
relationship="lt", cross=TRUE),
2 label="longExit")
7
2 #rules
8 add.rule(strategy.st, name="ruleSignal",
2 arguments=list(sigcol="longEntry", sigval=TRUE, ordertype="market",
orderside="long", replace=FALSE, prefer="Open",
9 osFUN=osDollarATR,
3 tradeSize=tradeSize, pctATR=pctATR, atrMod="X"),
0 type="enter", path.dep=TRUE)
3
1 add.rule(strategy.st, name="ruleSignal",
3 arguments=list(sigcol="longExit", sigval=TRUE, orderqty="all",
ordertype="market",
2 orderside="long", replace=FALSE, prefer="Open"),
3 type="exit", path.dep=TRUE)
3
3 #apply strategy
4 t1 <- Sys.time()
out <- applyStrategy(strategy=strategy.st,portfolios=portfolio.st)
3 t2 <- Sys.time()
5 print(t2-t1)
3
6 #set up analytics
3 updatePortf(portfolio.st)
7 dateRange <- time(getPortfolio(portfolio.st)$summary)[-1]
updateAcct(portfolio.st,dateRange)
3 updateEndEq(account.st)
8
3
9
4
0
4
1
4
2
4
3
4
4
4
5
4
6
4
7
4
8
4
9
5
0
5
1
5
2
5
3
5
4
5
5
5
6
5
7
5
8
5
9
6
0
6
1
6
2
6
3
6
4
6
5
6
6
6
7
6
8
6
9
7
0
7
1
7
2
7
3
7
4

Here are the results:

1 > (aggPF <- sum(tStats$Gross.Profits)/-sum(tStats$Gross.Losses))


[1] 0.956477
2
> (aggCorrect <- mean(tStats$Percent.Positive))
3 [1] 36.39737
4 > (numTrades <- sum(tStats$Num.Trades))
5 [1] 1778
6 > (meanAvgWLR <- mean(tStats$Avg.WinLoss.Ratio[tStats$Avg.WinLoss.Ratio < Inf],
na.rm=TRUE))
7 [1] 1.678421
8
9 > print(t(durStats))
1 [,1]
Min 1
0
Q1 2
11Med 6
1 Mean 9
2 Q3 14
1 Max 65
WMin 1
3 WQ1 3
1 WMed 13
4 WMean 13
1 WQ3 19
5 WMax 65
LMin 1
1 LQ1 2
6 LMed 4
1 LMean 6
7 LQ3 8
LMax 57
1
8 mean(corMeans)
1 [1] 0.08232023
9
2 > SharpeRatio.annualized(portfRets)
0 [,1]
2 Annualized Sharpe Ratio (Rf=0%) -0.2476826
> Return.annualized(portfRets)
1 [,1]
2 Annualized Return -0.03485231
2 > maxDrawdown(portfRets)
2 [1] 0.2632001
3
2
4
2
5
2
6
2
7
2
8
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
4
0
4
1

In short, its a loser over the past three years. Heres the equity curve:

Now while it may have worked in the past (or something similar to it, using Ehlerss filter indicator), it
doesnt seem to do so going forward.

Ill leave this here for now as a demonstration of how to do Ehlers bands.

Thanks for reading.

Volatility Histeresis: A First Attempt


Posted on July 29, 2014 Posted in Dr. John Ehlers, QuantStrat, R, Trading Tagged R 2 Comments
So the last time that a FRAMA strategy was tried with price crossovers, the problem was that due to counter-
trending failures, the filter that was added missed a lot of good trades, and wound up losing a lot of money
during flat markets that passed the arbitrary filter.

This trading system tries to rectify those issues by trading a rising FRAMA filtered on a 5-day standard
deviation ratio.

The hypothesis is this: the FRAMA rises in legitimately trending markets, and stays flat in choppy markets.
Therefore, the ratio of standard deviations (that is, a running standard deviation of the FRAMA over the
standard deviation of the market close) should be higher during trending markets, and lower during choppy
markets. Additionally, as this ratio bottoms out at zero and usually tops out at 1 (rarely gets higher), it can be
used as an indicator across instruments of vastly different properties.

The data that will be used will be the quandl futures data file (without federal funds, coffee, or sugar,
because of data issues).

Heres the data file:

1 require(IKTrading)
2
3
4 currency('USD')
Sys.setenv(TZ="UTC")
5
6
7 t1 <- Sys.time()
8 if(!"CME_CL" %in% ls()) {
9 #Energies
1 CME_CL <- quandClean("CHRIS/CME_CL", start_date=from, end_date=to, verbose=verbose)
#Crude
0 CME_NG <- quandClean("CHRIS/CME_NG", start_date=from, end_date=to, verbose=verbose)
11#NatGas
1 CME_HO <- quandClean("CHRIS/CME_HO", start_date=from, end_date=to, verbose=verbose)
2 #HeatingOil
1 CME_RB <- quandClean("CHRIS/CME_RB", start_date=from, end_date=to, verbose=verbose)
#Gasoline
3 ICE_B <- quandClean("CHRIS/ICE_B", start_date=from, end_date=to, verbose=verbose)
1 #Brent
4 ICE_G <- quandClean("CHRIS/ICE_G", start_date=from, end_date=to, verbose=verbose)
1 #Gasoil
5
#Grains
1
CME_C <- quandClean("CHRIS/CME_C", start_date=from, end_date=to, verbose=verbose)
6 #Chicago Corn
1 CME_S <- quandClean("CHRIS/CME_S", start_date=from, end_date=to, verbose=verbose)
7 #Chicago Soybeans
1 CME_W <- quandClean("CHRIS/CME_W", start_date=from, end_date=to, verbose=verbose)
#Chicago Wheat
8 CME_SM <- quandClean("CHRIS/CME_SM", start_date=from, end_date=to, verbose=verbose)
1 #Chicago Soybean Meal
9 CME_KW <- quandClean("CHRIS/CME_KW", start_date=from, end_date=to, verbose=verbose)
2 #Kansas City Wheat
0 CME_BO <- quandClean("CHRIS/CME_BO", start_date=from, end_date=to, verbose=verbose)
#Chicago Soybean Oil
2
1 #Softs
2 #ICE_SB <- quandClean("CHRIS/ICE_SB", start_date=from, end_date=to,
2 verbose=verbose) #Sugar
2 #Sugar 2007-03-26 is wrong
#ICE_KC <- quandClean("CHRIS/ICE_KC", start_date=from, end_date=to,
3
verbose=verbose) #Coffee
2 #Coffee January of 08 is FUBAR'd
4 ICE_CC <- quandClean("CHRIS/ICE_CC", start_date=from, end_date=to, verbose=verbose)
#Cocoa
2
ICE_CT <- quandClean("CHRIS/ICE_CT", start_date=from, end_date=to, verbose=verbose)
5 #Cotton
2
6 #Other Ags
2 CME_LC <- quandClean("CHRIS/CME_LC", start_date=from, end_date=to, verbose=verbose)
7 #Live Cattle
CME_LN <- quandClean("CHRIS/CME_LN", start_date=from, end_date=to, verbose=verbose)
2 #Lean Hogs
8
2 #Precious Metals
9 CME_GC <- quandClean("CHRIS/CME_GC", start_date=from, end_date=to, verbose=verbose)
3 #Gold
0 CME_SI <- quandClean("CHRIS/CME_SI", start_date=from, end_date=to, verbose=verbose)
#Silver
3 CME_PL <- quandClean("CHRIS/CME_PL", start_date=from, end_date=to, verbose=verbose)
1 #Platinum
3 CME_PA <- quandClean("CHRIS/CME_PA", start_date=from, end_date=to, verbose=verbose)
2 #Palladium
3
3 #Base
CME_HG <- quandClean("CHRIS/CME_HG", start_date=from, end_date=to, verbose=verbose)
3 #Copper
4
3 #Currencies
5 CME_AD <- quandClean("CHRIS/CME_AD", start_date=from, end_date=to, verbose=verbose)
3 #Ozzie
6 CME_CD <- quandClean("CHRIS/CME_CD", start_date=from, end_date=to, verbose=verbose)
#Loonie
3 CME_SF <- quandClean("CHRIS/CME_SF", start_date=from, end_date=to, verbose=verbose)
7 #Franc
3 CME_EC <- quandClean("CHRIS/CME_EC", start_date=from, end_date=to, verbose=verbose)
8 #Euro
CME_BP <- quandClean("CHRIS/CME_BP", start_date=from, end_date=to, verbose=verbose)
3 #Cable
9 CME_JY <- quandClean("CHRIS/CME_JY", start_date=from, end_date=to, verbose=verbose)
4 #Yen
0 CME_NE <- quandClean("CHRIS/CME_NE", start_date=from, end_date=to, verbose=verbose)
4 #Kiwi
1
#Equities
4 CME_ES <- quandClean("CHRIS/CME_ES", start_date=from, end_date=to, verbose=verbose)
2 #Emini
4 CME_MD <- quandClean("CHRIS/CME_MD", start_date=from, end_date=to, verbose=verbose)
3 #Midcap 400
4 CME_NQ <- quandClean("CHRIS/CME_NQ", start_date=from, end_date=to, verbose=verbose)
#Nasdaq 100
4 CME_TF <- quandClean("CHRIS/CME_TF", start_date=from, end_date=to, verbose=verbose)
4 #Russell Smallcap
5 CME_NK <- quandClean("CHRIS/CME_NK", start_date=from, end_date=to, verbose=verbose)
4 #Nikkei
6
#Dollar Index and Bonds/Rates
4
ICE_DX <- quandClean("CHRIS/CME_DX", start_date=from, end_date=to,
7 verbose=verbose) #Dixie
4 #CME_FF <- quandClean("CHRIS/CME_FF", start_date=from, end_date=to,
8 verbose=verbose) #30-day fed funds
4 CME_ED <- quandClean("CHRIS/CME_ED", start_date=from, end_date=to,
verbose=verbose) #3 Mo. Eurodollar/TED Spread
9 CME_FV <- quandClean("CHRIS/CME_FV", start_date=from, end_date=to,
5 verbose=verbose) #Five Year TNote
0 CME_TY <- quandClean("CHRIS/CME_TY", start_date=from, end_date=to,
5 verbose=verbose) #Ten Year Note
1 CME_US <- quandClean("CHRIS/CME_US", start_date=from, end_date=to,
verbose=verbose) #30 year bond
5 }
2
CMEinsts <- c("CL", "NG", "HO", "RB", "C", "S", "W", "SM", "KW", "BO", "LC", "LN",
5
"GC", "SI", "PL",
3 "PA", "HG", "AD", "CD", "SF", "EC", "BP", "JY", "NE", "ES", "MD", "NQ",
5 "TF", "NK", #"FF",
4 "ED", "FV", "TY", "US")
5
5 ICEinsts <- c("B", "G", #"SB", #"KC",
"CC", "CT", "DX")
5 CME <- paste("CME", CMEinsts, sep="_")
6 ICE <- paste("ICE", ICEinsts, sep="_")
5 symbols <- c(CME, ICE)
7 stock(symbols, currency="USD", multiplier=1)
5 t2 <- Sys.time()
print(t2-t1)
8
5
9
6
0
6
1
6
2
6
3
6
4
6
5
6
6
6
7
6
8
6
9
7
0
7
1
7
2
7
3
7
4
7
5
7
6
7
7
7
8
7
9
8
0
8
1
8
2
8
3

Heres the strategy:

1 require(DSTrading)
require(IKTrading)
2
require(quantstrat)
3 require(PerformanceAnalytics)
4
5 initDate="1990-01-01"
6 from="2000-03-01"
7 to="2011-12-31"
options(width=70)
8 verose=TRUE
9
10 FRAMAsdr <- function(HLC, n, FC, SC, nSD, ...) {
11 frama <- FRAMA(HLC, n=n, FC=FC, SC=SC, ...)
12 sdr <- runSD(frama$FRAMA, n=nSD)/runSD(Cl(HLC), n=nSD)
13 sdr[sdr > 2] <- 2
out <- cbind(FRAMA=frama$FRAMA, trigger=frama$trigger, sdr=sdr)
14 out
15 }
16
17 source("futuresData.R")
18
19 #trade sizing and initial equity settings
tradeSize <- 100000
20 initEq <- tradeSize*length(symbols)
21
22 strategy.st <- portfolio.st <- account.st <- "FRAMA_SDR_I"
23 rm.strat(portfolio.st)
24 rm.strat(strategy.st)
25 initPortf(portfolio.st, symbols=symbols, initDate=initDate, currency='USD')
initAcct(account.st, portfolios=portfolio.st, initDate=initDate,
26 currency='USD',initEq=initEq)
27 initOrders(portfolio.st, initDate=initDate)
28 strategy(strategy.st, store=TRUE)
29
30 #parameters
31 FC = 1
SC = 300
32 n = 126
33 triggerLag = 1
34 nSD = 5
35 sdThresh <- .3
36
period=10
37 pctATR=.02
38
39 #indicators
40 add.indicator(strategy.st, name="FRAMAsdr",
41 arguments=list(HLC=quote(HLC(mktdata)), FC=FC, SC=SC,
42 n=n, triggerLag=triggerLag, nSD=nSD),
label="SDR")
43
44 add.indicator(strategy.st, name="lagATR",
arguments=list(HLC=quote(HLC(mktdata)), n=period),
45
label="atrX")
46
47 #signals
48 add.signal(strategy.st, name="sigComparison",
49 arguments=list(columns=c("FRAMA.SDR", "trigger.SDR"), relationship="gt"),
50 label="FRAMAup")
51
add.signal(strategy.st, name="sigThreshold",
52 arguments=list(column="sdr.SDR", threshold=sdThresh,
53 relationship="gt",cross=FALSE),
54 label="SDRgtThresh")
55
56 add.signal(strategy.st, name="sigAND",
57 arguments=list(columns=c("FRAMAup", "SDRgtThresh"), cross=TRUE),
label="longEntry")
58
59 add.signal(strategy.st, name="sigCrossover",
60 arguments=list(columns=c("FRAMA.SDR", "trigger.SDR"), relationship="lt"),
61 label="FRAMAdnExit")
62
63 #add.signal(strategy.st, name="sigThreshold",
# arguments=list(column="sdr.SDR", threshold=sdThresh, relationship="lt",
64 cross=TRUE),
65 # label="SDRexit")
66
67 #rules
68 add.rule(strategy.st, name="ruleSignal",
69 arguments=list(sigcol="longEntry", sigval=TRUE, ordertype="market",
orderside="long", replace=FALSE, prefer="Open",
70 osFUN=osDollarATR,
71 tradeSize=tradeSize, pctATR=pctATR, atrMod="X"),
72 type="enter", path.dep=TRUE)
73
74 add.rule(strategy.st, name="ruleSignal",
75 arguments=list(sigcol="FRAMAdnExit", sigval=TRUE, orderqty="all",
ordertype="market",
76 orderside="long", replace=FALSE, prefer="Open"),
77 type="exit", path.dep=TRUE)
78
79 #add.rule(strategy.st, name="ruleSignal",
80 # arguments=list(sigcol="SDRexit", sigval=TRUE, orderqty="all",
ordertype="market",
81 # orderside="long", replace=FALSE, prefer="Open"),
82 # type="exit", path.dep=TRUE)
83
84 #apply strategy
85 t1 <- Sys.time()
86 out <- applyStrategy(strategy=strategy.st,portfolios=portfolio.st)
t2 <- Sys.time()
87 print(t2-t1)
88
89 #set up analytics
90 updatePortf(portfolio.st)
91 dateRange <- time(getPortfolio(portfolio.st)$summary)[-1]
updateAcct(portfolio.st,dateRange)
92
updateEndEq(account.st)
93
94
95
96
97
98
99
10
0
10
1
10
2
10
3
10
4

Notice that the exit due to the volatility filter had to have been commented out (as it caused the strategy to
lose all its edge). In any case, the FRAMA is the usual 126 day FRAMA, and the running standard deviation
is 5 days, in order to try and reduce lag. The standard deviation ratio threshold will be .2 or higher. Here are
the results:

1> (aggPF <- sum(tStats$Gross.Profits)/-sum(tStats$Gross.Losses))


2[1] 1.297276
3> (aggCorrect <- mean(tStats$Percent.Positive))
[1] 39.08526
4> (numTrades <- sum(tStats$Num.Trades))
5[1] 5186
6> (meanAvgWLR <- mean(tStats$Avg.WinLoss.Ratio[tStats$Avg.WinLoss.Ratio < Inf],
7na.rm=TRUE))
8[1] 2.065526

In other words, typical trend follower results. 40/60 wrong to right, with a 2:1 win to loss ratio. Far from
spectacular.

Duration statistics:

1
2
print(t(durStats))
3 [,1]
4 Min 1
5 Q1 2
6 Med 5
7 Mean 11
Q3 11
8 Max 158
9 WMin 1
10 WQ1 5
11 WMed 10
WMean 18
12
WQ3 21
13 WMax 158
14 LMin 1
15 LQ1 1
16 LMed 3
LMean 6
17 LQ3 6
18 LMax 93
19
20

In short, winners last longer than losers, which makes sense given that there are a lot of whipsaws, and that
this is a trend-following strategy.
Market exposure:

1 > print(mean(as.numeric(as.character(mktExposure$MktExposure))))
2 [1] 0.3820789

38%. So how did it perform?

Like this. Not particularly great, considering its a 60% gain over 11 years. Here are the particular statistics:

1
> SharpeRatio.annualized(portfRets)
2 [,1]
3 Annualized Sharpe Ratio (Rf=0%) 0.8124137
4 > Return.annualized(portfRets)
5 [,1]
Annualized Return 0.04229355
6 > maxDrawdown(portfRets)
7 [1] 0.07784351
8

In other words, about 10 basis points of returns per percent of market exposure, or a 10% annualized return.
The problem being? The drawdown is much higher than the annualized return, meaning that leverage will
only make things worse. Basically, for the low return on exposure and high drawdown to annualized return,
this strategy is a failure. While the steadily ascending equity curve is good, it is meaningless when the worst
losses take more than a year to recover from.

In any case, heres a look at some individual instruments.

Heres the equity curve for the E-minis.


So first off, we can see one little feature of this strategydue to the entry and exit not being symmetric (that
is, it takes two conditions to entera rising FRAMA and a standard deviation ratio above .2and only exits
on one of them (falling FRAMA), price action that exhibits a steady grind upwards, due to the rapid change
in ATR (its a 10-day figure) can actually slightly pyramid from time to time. This is a good feature in my
opinion, since it can add onto a winning position. However, in times of extreme volatility, when even an
adaptive indicator can get bounced around chasing mini-trends, we can see losses pile on.

Next, lets look at a much worse situation. Heres the equity curve for the Eurodollar/TED spread.
In this case, its clearly visible that the strategy has countertrend issues, as well as the fact that the 5-day
standard deviation ratio can be relatively myopic when it comes to instruments that have protracted periods
of complete inactivitythat is, the market is not even choppy so much as just still.

Ill leave this here, and move onto other attempts at getting around this sort of roadblock next.

Thanks for reading.

FRAMA Part V: Wrap-Up on Confirmatory


Indicator/Test Sample
Posted on July 16, 2014 Posted in Dr. John Ehlers, ETFs, QuantStrat, R, Trading Tagged R 1 Comment

So, it is possible to create a trading system that can correctly isolate severe and protracted downturns,
without taking (too many) false signals.

Here are the rules:

126 day FRAMA, FC=4, SC=300 (were still modifying the original ETFHQ strategy).
A running median (somewhere between 150 days and 252 daysseemingly, all these configurations work).

Both the FRAMA and the confirmatory median must be moving in the same direction (up for a long trade,
down for a short tradethe median rising is the new rule here), and the price must cross the FRAMA in that
direction to enter into a trade, while exiting when the price crosses below the FRAMA. Presented as a set of
quantstrat rules, it gets rather lengthy, since a rule needs to specify the three setup conditions, a rule to bind
them together, and an exit rule (5 rules each side).
The strategy works on both long and short ends, though the short version seems more of an insurance
strategy than anything else. Heres the equity curve for a 150 day median:

Basically, it makes money in terrible periods, but gives some of it back during just about any other time. Its
there just to put it out there as something that can finally try and isolate the truly despicable conditions and
give you a pop in those times. Other than that? Using it would depend on how often someone believes those
sorts of drawdown conditions would occurthat is, a descending adaptive indicator, a descending 7-12
month median.

Here are the trade and portfolio statistics:

1 > (aggPF <- sum(tStats$Gross.Profits)/-sum(tStats$Gross.Losses))


2 [1] 1.169916
> (aggCorrect <- mean(tStats$Percent.Positive))
3 [1] 33.475
4 > (numTrades <- sum(tStats$Num.Trades))
5 [1] 667
6 > (meanAvgWLR <- mean(tStats$Avg.WinLoss.Ratio[tStats$Avg.WinLoss.Ratio < Inf],
na.rm=TRUE))
7 [1] 2.631724
8
9 [,1]
1 Annualized Sharpe Ratio (Rf=0%) 0.07606299
0 > Return.annualized(portfRets)
11 [,1]
Annualized Return 0.004247807
1 > maxDrawdown(portfRets)
2 [1] 0.09845553
1
3
1
4
1
5
1
6

In other words, its absolutely not a standalone strategy, but more of a little something to give a long-only
strategy a boost during bad times. Its certainly not as spectacular as it gets. For instance, heres the equity
curve for XLK in late 2008-2009. Mainly, the problem with the ETFHQ strategy (Im still on that, yes) is
that it does not at all take into account the magnitude of the direction of the indicator. This means that in a
reverting market, this strategy has a potential to lose a great deal of money unnecessarily.

Basically, this strategy is highly conservative, meaning that it has a tendency to miss good trades, take
unnecessary ones, and is generally flawed because it has no way of really estimating the slope of the
FRAMA.

As the possible solution to this involves a strategy by John Ehlers, I think Ill leave this strategy here for
now.

So, to send off this original ETFHQ price cross strategy off, Ill test it out of sample using a 200-day
median, using both long and short sides (from 2010-03-01 to get the 200 day median burned in, to the
current date as of the time of this writing, 2014-06-20).

Here are the trade stats and portfolio stats:

1 > (aggPF <- sum(tStats$Gross.Profits)/-sum(tStats$Gross.Losses))


[1] 1.195693
2
> (aggCorrect <- mean(tStats$Percent.Positive))
3 [1] 36.20733
4
5
6
7
8
> (numTrades <- sum(tStats$Num.Trades))
9 [1] 1407
1 > (meanAvgWLR <- mean(tStats$Avg.WinLoss.Ratio[tStats$Avg.WinLoss.Ratio < Inf],
0 na.rm=TRUE))
11[1] 2.263333
1
> SharpeRatio.annualized(portfRets)
2 [,1]
1 Annualized Sharpe Ratio (Rf=0%) 0.3290298
3 > Return.annualized(portfRets)
1 [,1]
4 Annualized Return 0.02467234
> maxDrawdown(portfRets)
1 [1] 0.1354166
5
1
6
1
7

With the corresponding equity curve:

In short, definitely not good. Why?

Heres a good symptom as to why:


This is the out-of-sample equity curve of SHYthat is, the ETF of short term bonds. The trend had ended,
but the trading system didnt pick up on that.

In this case, you can see that the magnitude of the trend makes no difference to the strategywhich is a major
problem. Although the counter-trend trading was eliminated, forcing action was not, and trying to remain
loyal to the price crossing the indicator strategy while sticking to more conventional methods (a confirming
indicator) turns out to be flawed. Here is another side symptom of a flawed system:
In this instance, using such a conservative confirmatory indicator for the short trade and simply using that
same indicator for the long side indicates that there may very well have been overfitting on the system. On a
more general note, however, this picture makes one wonder whether a confirmatory indicator was even
necessary. For instance, there were certainly protracted periods during which there was a long trend that
were cut off due to the running median being slightly negative. There were both long and short opportunities
missed.

In my opinion, I think this puts the kibosh on something as ham-handed as a long-running confirmatory
indicator. Why? Because I think that it over-corrects for a flawed order logic system that doesnt take into
account the magnitude of the slope of the indicator. Obviously, trading in a countertrend (descending
indicator) is a terrible idea. But what about a slight change of directional sign as part of a greater counter-
trend? Suddenly, a robust, deliberately lagging confirmatory indicator no longer seems like such a bad idea.
However, as you can see, the downside of a lagging indicator is that it may very well lag your primary
indicator in a good portion of cases. And it does nothing to eliminate sideways trading.

Surely, a more elegant solution exists that attempts to quantify the fact that sometimes, the smooth-yet-
adaptive FRAMA can trend rapidly (and such trades should be taken posthaste), and can also go flat.
Ultimately, I think that while the indicator settings from ETFHQ have some merit, the simplistic order logic
on its own can certainly hurtand coupled with an order-sizing function that downsizes orders in times of
trending while magnifying them in times of calm (a side-effect of ATR, which was created to equalize risk
across instruments, but with the unintended consequence of very much not equalizing risk across market
conditions) can cause problems.

The next strategy will attempt to rectify these issues.

Thanks for reading.


FRAMA Part IV: Continuing the Long/Short
Filter Search
Posted on July 9, 2014 Posted in Dr. John Ehlers, ETFs, QuantStrat, R, Trading Tagged R 14 Comments

This post examines an n-day median filter for two desirable properties: robustness to outliers and an inherent
trend-confirming lag. While this is an incomplete filter (or maybe even inferior), it offers some key insights
into improving the trading system.

The strategy will be thus:

First and foremost, this will be a short-only strategy, due to the long bias within the sample period, so the
stress-test of the system will be to attempt to capture the non-dominant trend (and only when appropriate).

Heres the strategy: we will continue to use the same 126 day FRAMA with the fast constant set at 4, and a
slow constant at 300 (that is, it can oscillate anywhere between an EMA4 and EMA300). We will only enter
into a short position when this indicator is descending, below the 126-day median of the price action, and
when the price action is lower than this indicator (usually this means a cross, not in all cases though). We
will exit when the price action rises back above the indicator.

Heres the strategy in R code:

1 require(DSTrading)
require(IKTrading)
2
require(quantstrat)
3 require(PerformanceAnalytics)
4
5 initDate="1990-01-01"
6 from="2003-01-01"
7 to="2010-12-31"
options(width=70)
8
9 #to rerun the strategy, rerun everything below this line
10 source("demoData.R") #contains all of the data-related boilerplate.
11
12 #trade sizing and initial equity settings
13 tradeSize <- 10000
14 initEq <- tradeSize*length(symbols)
15
strategy.st <- portfolio.st <- account.st <- "FRAMA_III"
16 rm.strat(portfolio.st)
17 rm.strat(strategy.st)
18 initPortf(portfolio.st, symbols=symbols, initDate=initDate, currency='USD')
19 initAcct(account.st, portfolios=portfolio.st, initDate=initDate,
currency='USD',initEq=initEq)
20 initOrders(portfolio.st, initDate=initDate)
21 strategy(strategy.st, store=TRUE)
22
23 #parameters
24
25 FC=4
26 SC=300
n=126
27 triggerLag=1
28
29 period=10
30 pctATR=.02
31
32 #indicators
33
add.indicator(strategy.st, name="FRAMA",
34
arguments=list(HLC=quote(HLC(mktdata)), n=n,
35 SC=SC, FC=FC, triggerLag=triggerLag),
36 label="primary")
37
38 add.indicator(strategy.st, name="runMedian",
39 arguments=list(x=quote(Cl(mktdata)), n=n),
label="confirmatory")
40
41 add.indicator(strategy.st, name="lagATR",
42 arguments=list(HLC=quote(HLC(mktdata)), n=period),
43 label="atrX")
44
45 # #long signals
46 #
# add.signal(strategy.st, name="sigComparison",
47 # arguments=list(columns=c("FRAMA.primary", "X1.confirmatory"),
48 # relationship="gte"),
49 # label="FRAMAgteMedian")
50 #
# add.signal(strategy.st, name="sigComparison",
51 # arguments=list(columns=c("FRAMA.primary", "trigger.primary"),
52 # relationship="gte"),
53 # label="FRAMArising")
54 #
55 # add.signal(strategy.st, name="sigComparison",
# arguments=list(columns=c("Close", "FRAMA.primary"),
56 # relationship="gte"),
57 # label="ClGtFRAMA")
58 #
59 # add.signal(strategy.st, name="sigAND",
60 # arguments=list(columns=c("FRAMAgteMedian",
# "FRAMArising", "ClGtFRAMA"),
61 # cross=TRUE),
62 # label="longEntry")
63 #
64 # add.signal(strategy.st, name="sigCrossover",
# arguments=list(columns=c("Close", "FRAMA.primary"),
65 # relationship="lt"),
66 # label="longExit")
67 #
68 # #long rules
69 #
# add.rule(strategy.st, name="ruleSignal",
70 # arguments=list(sigcol="longEntry", sigval=TRUE, ordertype="market",
71 # orderside="long", replace=FALSE, prefer="Open",
72 osFUN=osDollarATR,
73 # tradeSize=tradeSize, pctATR=pctATR, atrMod="X"),
# type="enter", path.dep=TRUE)
74
#
75 # add.rule(strategy.st, name="ruleSignal",
76 # arguments=list(sigcol="longExit", sigval=TRUE, orderqty="all",
77 ordertype="market",
78 # orderside="long", replace=FALSE, prefer="Open"),
# type="exit", path.dep=TRUE)
79
80 #short signals
81
82 add.signal(strategy.st, name="sigComparison",
83 arguments=list(columns=c("FRAMA.primary", "X1.confirmatory"),
84 relationship="lt"),
85 label="FRAMAltMedian")
86
add.signal(strategy.st, name="sigComparison",
87 arguments=list(columns=c("FRAMA.primary", "trigger.primary"),
relationship="lt"),
88
label="FRAMAfalling")
89
90 add.signal(strategy.st, name="sigComparison",
91 arguments=list(columns=c("Close", "FRAMA.primary"),
92 relationship="lt"),
93 label="ClLtFRAMA")
94
add.signal(strategy.st, name="sigAND",
95 arguments=list(columns=c("FRAMAltMedian",
96 "FRAMAfalling", "ClLtFRAMA"),
97 cross=TRUE),
98 label="shortEntry")
99
10 add.signal(strategy.st, name="sigCrossover",
arguments=list(columns=c("Close", "FRAMA.primary"),
0 relationship="gt"),
10 label="shortExit")
1
10 #short rules
2
10 add.rule(strategy.st, name="ruleSignal",
arguments=list(sigcol="shortEntry", sigval=TRUE, ordertype="market",
3 orderside="short", replace=FALSE, prefer="Open",
10 osFUN=osDollarATR,
4 tradeSize=-tradeSize, pctATR=pctATR, atrMod="X"),
10 type="enter", path.dep=TRUE)
5
10 add.rule(strategy.st, name="ruleSignal",
arguments=list(sigcol="shortExit", sigval=TRUE, orderqty="all",
6 ordertype="market",
10 orderside="short", replace=FALSE, prefer="Open"),
7 type="exit", path.dep=TRUE)
10
8
10
9 #apply strategy
110t1 <- Sys.time()
out <- applyStrategy(strategy=strategy.st,portfolios=portfolio.st)
111 t2 <- Sys.time()
112print(t2-t1)
113
114
115#set up analytics
116updatePortf(portfolio.st)
117dateRange <- time(getPortfolio(portfolio.st)$summary)[-1]
updateAcct(portfolio.st,dateRange)
118updateEndEq(account.st)
119
12
0
12
1
12
2
12
3
12
4
12
5
12
6
12
7
12
8
12
9
13
0
13
1
13
2
13
3
13
4
13
5
13
6
13
7
13
8
13
9
14
0
14
1
14
2
14
3
14
4
14
5
14
6

The results arent pretty, meaning that the filter is still incomplete. Here are the trade stats:

1 EFA EPP EWA EWC EWG


Num.Txns 90.00 68.00 85.00 66.00 90.00
2
Num.Trades 44.00 34.00 41.00 33.00 45.00
3 Net.Trading.PL -2030.68 -25.54 -1485.82 -2283.03 -356.83
4 Avg.Trade.PL -46.15 -0.75 -36.24 -69.18 -7.93
5 Med.Trade.PL -103.99 -44.95 -77.27 -100.40 -69.91
6 Largest.Winner 1238.56 1656.56 1106.59 2195.51 3197.29
Largest.Loser -661.04 -786.27 -548.06 -823.55 -783.65
7 Gross.Profits 4336.92 4455.45 3246.48 3566.35 5948.76
8 Gross.Losses -6367.61 -4480.99 -4732.30 -5849.38 -6305.59
9 Std.Dev.Trade.PL 364.75 419.42 288.36 487.05 557.98
10 Percent.Positive 29.55 32.35 43.90 24.24 37.78
Percent.Negative 70.45 67.65 56.10 75.76 62.22
11 Profit.Factor 0.68 0.99 0.69 0.61 0.94
Avg.Win.Trade 333.61 405.04 180.36 445.79 349.93
12
Med.Win.Trade 57.09 238.60 66.34 124.31 101.88
13 Avg.Losing.Trade -205.41 -194.83 -205.75 -233.98 -225.20
14 Med.Losing.Trade -156.80 -122.45 -170.49 -166.84 -184.70
15 Avg.Daily.PL -46.15 -0.75 -36.24 -69.18 -7.93
16 Med.Daily.PL -103.99 -44.95 -77.27 -100.40 -69.91
Std.Dev.Daily.PL 364.75 419.42 288.36 487.05 557.98
17 Ann.Sharpe -2.01 -0.03 -2.00 -2.25 -0.23
18 Max.Drawdown -5089.55 -3095.58 -3609.64 -4915.76 -4222.60
19 Profit.To.Max.Draw -0.40 -0.01 -0.41 -0.46 -0.08
20 Avg.WinLoss.Ratio 1.62 2.08 0.88 1.91 1.55
21 Med.WinLoss.Ratio 0.36 1.95 0.39 0.75 0.55
Max.Equity 146.74 1473.19 834.54 78.43 1467.12
22 Min.Equity -4942.81 -2562.72 -2775.10 -4837.32 -3960.49
23 End.Equity -2030.68 -25.54 -1485.82 -2283.03 -356.83
24
25 EWH EWJ EWS EWT EWU
26 Num.Txns 74.00 102.00 72.00 66.00 72.00
Num.Trades 36.00 51.00 35.00 33.00 36.00
27 Net.Trading.PL 596.16 -1493.76 982.93 1354.40 439.00
28 Avg.Trade.PL 16.56 -29.29 28.08 41.04 12.19
29 Med.Trade.PL -54.45 -89.63 -52.85 -40.22 -56.50
30 Largest.Winner 3436.43 1076.25 1165.10 1980.68 1680.33
31 Largest.Loser -544.78 -781.15 -429.64 -441.47 -468.28
Gross.Profits 4519.53 5681.81 4763.28 4317.26 5105.73
32 Gross.Losses -3923.37 -7175.57 -3780.35 -2962.87 -4666.73
33 Std.Dev.Trade.PL 610.29 368.61 353.59 408.77 415.23
34 Percent.Positive 38.89 37.25 37.14 42.42 33.33
35 Percent.Negative 61.11 62.75 62.86 57.58 66.67
36 Profit.Factor 1.15 0.79 1.26 1.46 1.09
Avg.Win.Trade 322.82 299.04 366.41 308.38 425.48
37 Med.Win.Trade 79.88 99.19 267.75 115.47 399.34
38 Avg.Losing.Trade -178.33 -224.24 -171.83 -155.94 -194.45
39 Med.Losing.Trade -137.71 -175.69 -141.06 -95.88 -180.13
40 Avg.Daily.PL 16.56 -29.29 28.08 41.04 12.19
Med.Daily.PL -54.45 -89.63 -52.85 -40.22 -56.50
41 Std.Dev.Daily.PL 610.29 368.61 353.59 408.77 415.23
42 Ann.Sharpe 0.43 -1.26 1.26 1.59 0.47
43 Max.Drawdown -2390.89 -2994.16 -1689.63 -2113.93 -3192.52
44 Profit.To.Max.Draw 0.25 -0.50 0.58 0.64 0.14
45 Avg.WinLoss.Ratio 1.81 1.33 2.13 1.98 2.19
Med.WinLoss.Ratio 0.58 0.56 1.90 1.20 2.22
46 Max.Equity 2534.61 1380.90 1938.04 2065.70 1845.45
47 Min.Equity -2131.17 -2540.03 -1265.23 -1501.15 -3192.52
48 End.Equity 596.16 -1493.76 982.93 1354.40 439.00
49
50 EWY EWZ EZU IEF IGE
Num.Txns 68.00 80.00 96.00 63.00 56.00
51
Num.Trades 34.00 40.00 48.00 32.00 28.00
52 Net.Trading.PL 1359.59 -2763.77 -178.24 -5286.17 -588.44
53 Avg.Trade.PL 39.99 -69.09 -3.71 -165.19 -21.02
54 Med.Trade.PL 19.52 -103.71 -73.53 -253.57 -87.68
55 Largest.Winner 1799.34 2495.03 1423.73 908.54 2146.42
Largest.Loser -467.07 -496.73 -847.67 -758.78 -466.57
56 Gross.Profits 4729.27 2790.33 5960.68 2309.18 2757.36
57 Gross.Losses -3369.68 -5554.10 -6138.92 -7595.36 -3345.80
58 Std.Dev.Trade.PL 414.55 440.16 402.00 349.52 456.89
59 Percent.Positive 55.88 15.00 33.33 25.00 25.00
60 Percent.Negative 44.12 85.00 66.67 75.00 75.00
Profit.Factor 1.40 0.50 0.97 0.30 0.82
61 Avg.Win.Trade 248.91 465.05 372.54 288.65 393.91
62 Med.Win.Trade 58.75 43.02 67.59 156.68 43.03
63 Avg.Losing.Trade -224.65 -163.36 -191.84 -316.47 -159.32
64 Med.Losing.Trade -217.23 -110.98 -139.29 -284.87 -115.98
Avg.Daily.PL 39.99 -69.09 -3.71 -192.64 -21.02
65 Med.Daily.PL 19.52 -103.71 -73.53 -260.53 -87.68
66 Std.Dev.Daily.PL 414.55 440.16 402.00 318.33 456.89
Ann.Sharpe 1.53 -2.49 -0.15 -9.61 -0.73
67
Max.Drawdown -2237.74 -3903.71 -3510.08 -6682.82 -2836.80
68 Profit.To.Max.Draw 0.61 -0.71 -0.05 -0.79 -0.21
69 Avg.WinLoss.Ratio 1.11 2.85 1.94 0.91 2.47
70 Med.WinLoss.Ratio 0.27 0.39 0.49 0.55 0.37
71 Max.Equity 3532.28 836.88 1270.40 669.24 709.44
Min.Equity -790.83 -3066.84 -3222.22 -6013.57 -2127.36
72 End.Equity 1359.59 -2763.77 -178.24 -5286.17 -588.44
73
74 IYR IYZ LQD RWR SHY
75 Num.Txns 96.00 108.00 63.00 98.00 51.00
76 Num.Trades 48.00 54.00 31.00 49.00 25.00
77 Net.Trading.PL -3444.89 -2032.70 1532.27 -3740.29 -4049.16
Avg.Trade.PL -71.77 -37.64 49.43 -76.33 -161.97
78 Med.Trade.PL -129.99 -83.00 -84.44 -114.84 -141.20
79 Largest.Winner 1714.13 2673.04 2693.04 1455.78 86.02
80 Largest.Loser -745.50 -463.08 -480.73 -578.29 -644.17
81 Gross.Profits 4652.33 4978.26 5114.62 3534.95 365.46
Gross.Losses -8097.22 -7010.97 -3582.35 -7275.24 -4414.63
82 Std.Dev.Trade.PL 405.93 479.46 604.30 341.37 195.72
83 Percent.Positive 22.92 22.22 35.48 16.33 28.00
84 Percent.Negative 77.08 77.78 64.52 83.67 72.00
85 Profit.Factor 0.57 0.71 1.43 0.49 0.08
86 Avg.Win.Trade 422.94 414.86 464.97 441.87 52.21
Med.Win.Trade 110.81 29.28 139.76 188.82 44.33
87 Avg.Losing.Trade -218.84 -166.93 -179.12 -177.44 -245.26
88 Med.Losing.Trade -182.73 -134.02 -129.79 -138.78 -232.61
89 Avg.Daily.PL -71.77 -37.64 45.47 -76.33 -162.83
90 Med.Daily.PL -129.99 -83.00 -86.18 -114.84 -144.12
91 Std.Dev.Daily.PL 405.93 479.46 614.22 341.37 199.88
Ann.Sharpe -2.81 -1.25 1.18 -3.55 -12.93
92 Max.Drawdown -3857.85 -5575.45 -2876.51 -4695.60 -4049.16
93 Profit.To.Max.Draw -0.89 -0.36 0.53 -0.80 -1.00
94 Avg.WinLoss.Ratio 1.93 2.49 2.60 2.49 0.21
95 Med.WinLoss.Ratio 0.61 0.22 1.08 1.36 0.19
Max.Equity 260.07 118.92 3375.06 302.96 0.00
96 Min.Equity -3597.77 -5456.52 -2138.62 -4392.65 -4049.16
97 End.Equity -3444.89 -2032.70 1532.27 -3740.29 -4049.16
98
99 TLT XLB XLE XLF XLI
100 Num.Txns 85.00 104.00 50.00 120.00 92.00
101 Num.Trades 43.00 51.00 25.00 60.00 46.00
Net.Trading.PL -4037.97 -5591.16 -308.15 -3036.79 -2136.85
102 Avg.Trade.PL -93.91 -109.63 -12.33 -50.61 -46.45
103 Med.Trade.PL -133.03 -138.47 -96.47 -79.48 -108.98
104 Largest.Winner 1425.91 1831.45 1828.51 1058.03 1218.87
105 Largest.Loser -543.28 -707.20 -430.13 -711.69 -632.77
Gross.Profits 3355.40 3130.31 2472.08 5282.27 4597.82
106
Gross.Losses -7393.37 -8721.48 -2780.24 -8319.05 -6734.68
107 Std.Dev.Trade.PL 338.88 345.20 420.71 309.84 342.80
108 Percent.Positive 25.58 25.49 20.00 30.00 23.91
109 Percent.Negative 74.42 74.51 80.00 70.00 76.09
110 Profit.Factor 0.45 0.36 0.89 0.63 0.68
Avg.Win.Trade 305.04 240.79 494.42 293.46 417.98
111 Med.Win.Trade 168.50 83.98 33.87 135.46 294.74
112 Avg.Losing.Trade -231.04 -229.51 -139.01 -198.07 -192.42
113 Med.Losing.Trade -197.38 -207.82 -120.99 -171.67 -149.06
114 Avg.Daily.PL -101.44 -109.63 -12.33 -50.61 -46.45
115 Med.Daily.PL -140.48 -138.47 -96.47 -79.48 -108.98
Std.Dev.Daily.PL 339.33 345.20 420.71 309.84 342.80
116 Ann.Sharpe -4.75 -5.04 -0.47 -2.59 -2.15
117 Max.Drawdown -4926.34 -6711.79 -1938.05 -3451.10 -4068.90
118 Profit.To.Max.Draw -0.82 -0.83 -0.16 -0.88 -0.53
119 Avg.WinLoss.Ratio 1.32 1.05 3.56 1.48 2.17
Med.WinLoss.Ratio 0.85 0.40 0.28 0.79 1.98
120 Max.Equity 459.78 0.00 1298.51 414.31 0.00
121 Min.Equity -4466.56 -6711.79 -1329.01 -3036.79 -4068.90
End.Equity -4037.97 -5591.16 -308.15 -3036.79 -2136.85
122
123
XLK XLP XLU XLV XLY
124 Num.Txns 86.00 92.00 82.00 94.00 82.00
125 Num.Trades 43.00 45.00 40.00 47.00 40.00
126 Net.Trading.PL -1205.62 -4427.34 -3490.76 -4291.56 -230.80
127 Avg.Trade.PL -28.04 -98.39 -87.27 -91.31 -5.77
Med.Trade.PL -101.30 -153.01 -93.87 -98.69 -140.01
128 Largest.Winner 2403.16 1008.09 1805.03 842.35 2090.68
129 Largest.Loser -806.29 -460.10 -462.68 -554.57 -698.45
130 Gross.Profits 4984.72 2839.42 2493.63 2959.31 6253.33
131 Gross.Losses -6190.34 -7266.76 -5984.39 -7250.87 -6484.14
132 Std.Dev.Trade.PL 464.22 294.41 350.37 280.87 495.21
Percent.Positive 30.23 15.56 20.00 19.15 30.00
133 Percent.Negative 69.77 84.44 80.00 80.85 70.00
134 Profit.Factor 0.81 0.39 0.42 0.41 0.96
135 Avg.Win.Trade 383.44 405.63 311.70 328.81 521.11
136 Med.Win.Trade 191.31 116.12 61.87 266.16 307.13
Avg.Losing.Trade -206.34 -191.23 -187.01 -190.81 -231.58
137 Med.Losing.Trade -188.49 -191.04 -156.33 -161.51 -171.21
138 Avg.Daily.PL -28.04 -98.39 -87.27 -91.31 -5.77
139 Med.Daily.PL -101.30 -153.01 -93.87 -98.69 -140.01
140 Std.Dev.Daily.PL 464.22 294.41 350.37 280.87 495.21
141 Ann.Sharpe -0.96 -5.30 -3.95 -5.16 -0.18
Max.Drawdown -3448.99 -5384.93 -3540.13 -5186.60 -3964.07
142 Profit.To.Max.Draw -0.35 -0.82 -0.99 -0.83 -0.06
143 Avg.WinLoss.Ratio 1.86 2.12 1.67 1.72 2.25
144 Med.WinLoss.Ratio 1.01 0.61 0.40 1.65 1.79
145 Max.Equity 646.11 651.59 0.00 895.04 2960.96
146 Min.Equity -3003.57 -4733.34 -3540.13 -4291.56 -1003.11
End.Equity -1205.62 -4427.34 -3490.76 -4291.56 -230.80
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

At this point, for the sake of brevity, Ill leave off the equity curves and portfolio statistics (theyll obviously
be bad). However, lets look at some images of what exactly is going on with individual trades.

Here is the full-backtest equity curve and corresponding indicators for XLP. The FRAMA is in purple, with
the 126-day median in orange, along with the 10-day ATR (lagged by a day) on the bottom.

And here we can immediately see certain properties:

1) ATR order-sizing is not a be-all, end-all type of order. It was created for one purpose, which is to equalize
risk across instruments (the original idea of which, I defer to Andreas Clenows article). However, that is
only a base from which to begin, using other scaled order-sizing procedures which can attempt to quantify
the confidence in any particular trade. As it currently stands, for short strategies in equities, the best
opportunities happen in the depths of rapid falling price action, during which ATR will rise. One may
consider augmenting the ATR order sizing function in order to accomplish this task (or merely apply
leverage at the proper time, through modifying the pctATR parameter).

2) While the running median certainly has value as a filter to keep out obviously brainless trades (E.G. in the
middle of an uptrend), once the FRAMA crosses the median, anything can happen, as the only logic is that
the current FRAMA is just slightly lower than the previous days. This may mean that the running median
itself is still rising, or that the FRAMA is effectively flat, and what is being traded on is purely noise. And
furthermore, with ATR order sizing amplifying the consequences of that noise, this edge case can have
disastrous consequences on an equity curve.

Heres a zoom in on 2005, where we see a pretty severe drawdown (chart time series recolored for clarity).
As can be seen, even though the FRAMA seems to be slightly rising, a price crossing when the FRAMA is
lower than the previous day by even an invisibly small amount (compare the purplethe FRAMA, to the
redthe same quantity lagged a day) is enough to trigger a trade that will buy a sizable number of shares,
even when the volatility is too small to justify such a trade. Essentially, most of the losses in this trading
system arise as a result of trading during these flat periods during which the system attempts to force action.

This pattern repeats itself. Here is the equity curve for XLB.
Again, aside from maybe a bad trade in the end thanks to any trade being taken once all three conditions line
up (decreasing FRAMA, FRAMA lower than median, price lower than FRAMA) too late due to a flat
FRAMA/median relationship, most of the losers seem to be trades made during very flat and calm market
action, even when the running median may be going in the opposite direction of the FRAMA, during which
the ATR order-sizing function tried to force action. A second filter that serves to catch these edge-case
situations (or maybe a filter that replaces the running median entirely) will be investigated in the future.

So, to recap this post:

The running median filter is an intrinsically lagging but robust indicator, chosen deliberately for these two
properties. It is able to filter out trades that obviously go against the trend. However, due to some edge cases,
there were still a great deal of losses that were incurred, which drown out the one good shorting opportunity
over this sample period. This is an issue that needs addressing.

Thanks for reading.

FRAMA Part III: Avoiding Countertrend Trading


A First Attempt
Posted on July 2, 2014 Posted in Dr. John Ehlers, ETFs, QuantStrat, R, Trading Tagged R 1 Comment

This post will begin to experiment with long-term directional detection using relationships between two
FRAMA indicators. By observing the relationship between two differently parametrized FRAMAs and the
relationship by virtue of the ATR, it will be possible to avoid counter-trend trading on both sides. We will
see this example later:
As with TVI, when the signals and rules were swapped for the short end, the equity curve was an
unmitigated disaster. Unlike the flat-during-bull-runs-and-permanently-popping-up equity curve of ETFHQ,
this equity curve was a disaster. For those that read the final TVI post, the equity curve looked almost
identical to thatjust a monotonous drawdown until the crisis, at which point the gains arent made up, and
then the losses continue. In short, theres no need to go into depth of those statistics.

As the link to ETFHQ suggests, we will use a longer-term FRAMA (the n=252, FC=40, SC=252 version).
The market will be in an uptrend when the fast FRAMA (the FRAMA from the previous post) is above this
slower FRAMA, and vice versa. Furthermore, in order to avoid some whipsaws, the fast FRAMA will have
to be ascending (or descending, during a downtrend), and the entry signal will be when the price crosses
over (under) the faster FRAMA, with the exit being the reverse.

In the interest of brevity, since the sample period was an uptrend, then a great deal of strategies will look
good on the upside. The question is whether or not the strategy does well on the short side, as the litmus test
in testing a confirming indicator is whether or not it can create a positive expectation in a strategy that is
counter-trend to the dominant trend in the sample data. As this is a replication of an implied idea by ETFHQ
(rather than my own particular idea), lets look at the code for the strategy. In this instance, both the long and
short end of this symmetric strategy are included, and in RStudio, commenting or uncommenting one half or
the other is as simple as highlight+ctrl+shift+C.

Heres the code.

1 require(DSTrading)
require(IKTrading)
2 require(quantstrat)
3 require(PerformanceAnalytics)
4
5 initDate="1990-01-01"
6 from="2003-01-01"
to="2010-12-31"
7
options(width=70)
8
9 #to rerun the strategy, rerun everything below this line
10 source("demoData.R") #contains all of the data-related boilerplate.
11
12 #trade sizing and initial equity settings
13 tradeSize <- 10000
initEq <- tradeSize*length(symbols)
14
15 strategy.st <- portfolio.st <- account.st <- "FRAMA_II"
16 rm.strat(portfolio.st)
17 rm.strat(strategy.st)
18 initPortf(portfolio.st, symbols=symbols, initDate=initDate, currency='USD')
19 initAcct(account.st, portfolios=portfolio.st, initDate=initDate,
currency='USD',initEq=initEq)
20 initOrders(portfolio.st, initDate=initDate)
21 strategy(strategy.st, store=TRUE)
22
23 #parameters
24
25 FCfast=4
SCfast=300
26 nFast=126
27 fastTriggerLag=1
28
29 FCslow=40
30 SCslow=252
31 nSlow=252
slowTriggerLag=1
32
33 period=10
34 pctATR=.02
35
36 #indicators
37 #Have to add in this function first, since the word 'slow' gets picked up
38 #by the HLC function as "low", which causes issues.
add.indicator(strategy.st, name="lagATR",
39 arguments=list(HLC=quote(HLC(mktdata)), n=period),
40 label="atrX")
41
42
43 add.indicator(strategy.st, name="FRAMA",
44 arguments=list(HLC=quote(HLC(mktdata)), n=nFast, FC=FCfast,
SC=SCfast, triggerLag=fastTriggerLag),
45 label="fast")
46
47
48 add.indicator(strategy.st, name="FRAMA",
49 arguments=list(HLC=quote(HLC(mktdata)), n=nSlow, FC=FCslow,
50 SC=SCslow, triggerLag=slowTriggerLag),
51 label="slow")
52
# #long signals
53 #
54 # #condition 1: our fast FRAMA is above our slow FRAMA
55 # add.signal(strategy.st, name="sigComparison",
56 # arguments=list(columns=c("FRAMA.fast", "FRAMA.slow"),
relationship="gt"),
57
# label="fastFRAMAaboveSlow")
58 #
59 # #condition 2: our fast FRAMA is rising
60 # add.signal(strategy.st, name="sigComparison",
# arguments=list(columns=c("FRAMA.fast", "trigger.fast"),
61 relationship="gt"),
# label="fastFRAMArising")
62
#
63 # #setup: price crosses above the fast FRAMA
64 # add.signal(strategy.st, name="sigComparison",
65 # arguments=list(columns=c("Close", "FRAMA.fast"), relationship="gte"),
66 # label="CloseGteFastFRAMA")
#
67 # #wrap our conditions and our setup into one entry signal
68 # add.signal(strategy.st, name="sigAND",
69 # arguments=list(columns=c("fastFRAMAaboveSlow", "fastFRAMArising",
70 "CloseGteFastFRAMA"), cross=TRUE),
71 # label="longEntry")
#
72 # #our old exit signal
73 # add.signal(strategy.st, name="sigCrossover",
74 # arguments=list(columns=c("Close", "FRAMA.fast"), relationship="lt"),
75 # label="longExit")
76
# #long rules
77
78 # add.rule(strategy.st, name="ruleSignal",
79 # arguments=list(sigcol="longEntry", sigval=TRUE, ordertype="market",
80 # orderside="long", replace=FALSE, prefer="Open",
81 osFUN=osDollarATR,
82 # tradeSize=tradeSize, pctATR=pctATR, atrMod="X"),
# type="enter", path.dep=TRUE)
83 #
84 # add.rule(strategy.st, name="ruleSignal",
85 # arguments=list(sigcol="longExit", sigval=TRUE, orderqty="all",
86 ordertype="market",
87 # orderside="long", replace=FALSE, prefer="Open"),
# type="exit", path.dep=TRUE)
88
89
90
91 #short signals
92 add.signal(strategy.st, name="sigComparison",
93 arguments=list(columns=c("FRAMA.fast", "FRAMA.slow"), relationship="lt"),
94 label="fastFRAMAbelowSlow")
95
#condition 2: our fast FRAMA is falling
96 add.signal(strategy.st, name="sigComparison",
97 arguments=list(columns=c("FRAMA.fast", "trigger.fast"),
98 relationship="lt"),
99 label="fastFRAMAfalling")
10
0
10 #setup: price crosses below the fast FRAMA
add.signal(strategy.st, name="sigCrossover",
1 arguments=list(columns=c("Close", "FRAMA.fast"), relationship="lt"),
10 label="CloseLtFastFRAMA")
2
10 #wrap our conditions and our setup into one entry signal
3 add.signal(strategy.st, name="sigAND",
arguments=list(columns=c("fastFRAMAbelowSlow", "fastFRAMAfalling",
10
"CloseLtFastFRAMA"), cross=TRUE),
4 label="shortEntry")
10
5 #our old exit signal
10 add.signal(strategy.st, name="sigCrossover",
6 arguments=list(columns=c("Close", "FRAMA.fast"), relationship="gt"),
label="shortExit")
10
7 #short rules
10 add.rule(strategy.st, name="ruleSignal",
arguments=list(sigcol="shortEntry", sigval=TRUE, ordertype="market",
8
orderside="short", replace=FALSE, prefer="Open",
10 osFUN=osDollarATR,
9 tradeSize=-tradeSize, pctATR=pctATR, atrMod="X"),
110 type="enter", path.dep=TRUE)
111 add.rule(strategy.st, name="ruleSignal",
arguments=list(sigcol="shortExit", sigval=TRUE, orderqty="all",
112ordertype="market",
113 orderside="short", replace=FALSE, prefer="Open"),
114 type="exit", path.dep=TRUE)
115
116
117#apply strategy
118t1 <- Sys.time()
out <- applyStrategy(strategy=strategy.st,portfolios=portfolio.st)
119t2 <- Sys.time()
12 print(t2-t1)
0
12
1 #set up analytics
12 updatePortf(portfolio.st)
2 dateRange <- time(getPortfolio(portfolio.st)$summary)[-1]
updateAcct(portfolio.st,dateRange)
12 updateEndEq(account.st)
3
12
4
12
5
12
6
12
7
12
8
12
9
13
0
13
1
13
2
13
3
13
4
13
5
13
6
13
7
13
8
13
9
14
0
14
1
14
2
14
3
14
4
14
5
14
6
14
7
14
8
14
9
15
0
15
1

First, a quick little side-note: since many indicators look for the word low, my usage of the label slow
would cause a bug if I added the lagATR indicator after that point. So try to avoid labels such as high,
low, open, and close in your indicators, or at least declare all indicators that would look for the word
low before declaring the indicator you label in part as slow, if you must go this route. Low is probably
the easiest one for which to overlook this, since slow has so many applications to confirmatory indicators.
(EG: SMA fast vs. SMA slow, etc.)

Again, to reiterate, the system will take a long position when price crosses over (under) a rising (falling) fast
FRAMA thats higher (lower) than the slow FRAMA, and exit that position when the price crosses back
under (over) the fast FRAMA. The cross must happen when the other two conditions are intact, as opposed
to a trade being entered when all three conditions come together, which may be in the middle of a trend.

As the majority of the sample data was in an uptrend (and the fact that the Andreas Clenow-inspired ATR
order-sizing function pays enormous dividends in protecting for a limited time in a counter-trend), I decided
to put the (slightly modifiedwith the one condition of rising in an uptrend or falling in a downtrend) system
to the test by testing it on the non-dominant trend in the samplethat is, to see if the system can stay out at
all points aside from the crisis.

Here are the (not-so-flattering) results:

Trade statistics:

1 EFA EPP EWA EWC EWG


Num.Txns 88.00 80.00 84.00 60.00 70.00
2
Num.Trades 43.00 40.00 40.00 30.00 35.00
3 Net.Trading.PL -1393.99 -1585.91 981.89 875.47 -810.83
4 Avg.Trade.PL -32.42 -39.65 24.55 29.18 -23.17
5 Med.Trade.PL -106.64 -70.14 1.79 -74.83 -46.21
6 Largest.Winner 1238.56 775.14 1106.59 2195.51 449.23
Largest.Loser -661.04 -466.95 -552.10 -565.80 -547.09
7 Gross.Profits 4211.42 3301.63 3677.16 3856.57 2719.33
8 Gross.Losses -5605.42 -4887.54 -2695.27 -2981.10 -3530.16
9 Std.Dev.Trade.PL 344.67 284.29 263.92 462.93 226.75
10 Percent.Positive 32.56 30.00 50.00 26.67 48.57
Percent.Negative 67.44 70.00 50.00 73.33 51.43
11
Profit.Factor 0.75 0.68 1.36 1.29 0.77
12 Avg.Win.Trade 300.82 275.14 183.86 482.07 159.96
13 Med.Win.Trade 73.89 172.89 56.79 245.71 121.09
14 Avg.Losing.Trade -193.29 -174.55 -134.76 -135.50 -196.12
15 Med.Losing.Trade -156.80 -141.04 -88.56 -108.19 -187.47
Avg.Daily.PL -33.19 -39.65 24.55 29.18 -23.17
16 Med.Daily.PL -103.99 -70.14 1.79 -74.83 -46.21
17 Std.Dev.Daily.PL 337.33 284.29 263.92 462.93 226.75
18 Ann.Sharpe -1.56 -2.21 1.48 1.00 -1.62
19 Max.Drawdown -4696.67 -3090.61 -2193.20 -2032.07 -1990.83
20 Profit.To.Max.Draw -0.30 -0.51 0.45 0.43 -0.41
Avg.WinLoss.Ratio 1.56 1.58 1.36 3.56 0.82
21 Med.WinLoss.Ratio 0.47 1.23 0.64 2.27 0.65
22 Max.Equity 560.75 355.13 2236.74 1567.71 1030.36
23 Min.Equity -4135.91 -2881.48 -1702.76 -2019.64 -960.47
24 End.Equity -1393.99 -1585.91 981.89 875.47 -810.83
25
EWH EWJ EWS EWT EWU
26 Num.Txns 48.00 102.00 74.00 56.00 82.00
27 Num.Trades 23.00 51.00 35.00 27.00 41.00
28 Net.Trading.PL -420.23 -951.54 1424.73 292.07 -1756.36
29 Avg.Trade.PL -18.27 -18.66 40.71 10.82 -42.84
30 Med.Trade.PL -42.63 -54.18 -15.44 3.83 -46.42
Largest.Winner 309.93 1704.54 1165.10 437.42 664.06
31 Largest.Loser -341.09 -460.39 -424.29 -367.22 -367.18
32 Gross.Profits 996.32 5137.50 4424.92 2072.64 2461.62
33 Gross.Losses -1416.55 -6089.05 -3000.19 -1780.57 -4217.98
34 Std.Dev.Trade.PL 135.68 358.27 328.50 180.94 227.57
35 Percent.Positive 39.13 39.22 42.86 51.85 34.15
Percent.Negative 60.87 60.78 57.14 48.15 65.85
36 Profit.Factor 0.70 0.84 1.47 1.16 0.58
37 Avg.Win.Trade 110.70 256.88 294.99 148.05 175.83
38 Med.Win.Trade 91.25 80.40 84.30 100.73 66.50
39 Avg.Losing.Trade -101.18 -196.42 -150.01 -136.97 -156.22
Med.Losing.Trade -92.50 -173.06 -141.06 -144.50 -146.70
40 Avg.Daily.PL -18.27 -18.66 40.71 10.82 -42.84
41 Med.Daily.PL -42.63 -54.18 -15.44 3.83 -46.42
42 Std.Dev.Daily.PL 135.68 358.27 328.50 180.94 227.57
43 Ann.Sharpe -2.14 -0.83 1.97 0.95 -2.99
44 Max.Drawdown -1330.17 -3187.00 -1855.03 -1440.36 -3674.50
Profit.To.Max.Draw -0.32 -0.30 0.77 0.20 -0.48
45 Avg.WinLoss.Ratio 1.09 1.31 1.97 1.08 1.13
46 Med.WinLoss.Ratio 0.99 0.46 0.60 0.70 0.45
47 Max.Equity 791.29 2235.46 2100.37 919.22 280.39
48 Min.Equity -974.85 -2116.00 -1230.08 -885.33 -3394.12
End.Equity -420.23 -951.54 1424.73 292.07 -1756.36
49
50
EWY EWZ EZU IEF IGE
51 Num.Txns 82.00 58.00 90.00 47.00 96.00
52 Num.Trades 41.00 29.00 45.00 24.00 48.00
53 Net.Trading.PL 2644.53 434.29 -1639.77 -1071.52 -1826.08
54 Avg.Trade.PL 64.50 14.98 -36.44 -44.65 -38.04
Med.Trade.PL -36.18 -89.69 -70.13 -56.73 -79.30
55 Largest.Winner 2447.28 2495.03 1222.50 908.54 2146.42
56 Largest.Loser -392.38 -382.20 -455.60 -717.52 -297.67
57 Gross.Profits 5519.58 3649.15 3231.22 2332.00 3162.60
58 Gross.Losses -2875.04 -3214.86 -4870.99 -3403.52 -4988.68
59 Std.Dev.Trade.PL 441.24 521.49 282.42 339.58 349.80
Percent.Positive 48.78 24.14 37.78 41.67 20.83
60 Percent.Negative 51.22 75.86 62.22 58.33 79.17
61 Profit.Factor 1.92 1.14 0.66 0.69 0.63
62 Avg.Win.Trade 275.98 521.31 190.07 233.20 316.26
63 Med.Win.Trade 119.21 91.01 54.82 81.98 82.87
Avg.Losing.Trade -136.91 -146.13 -173.96 -243.11 -131.28
64 Med.Losing.Trade -97.92 -109.64 -155.51 -230.79 -113.58
65 Avg.Daily.PL 64.50 14.98 -36.44 -74.70 -38.04
Med.Daily.PL -36.18 -89.69 -70.13 -71.76 -79.30
66
Std.Dev.Daily.PL 441.24 521.49 282.42 312.88 349.80
67 Ann.Sharpe 2.32 0.46 -2.05 -3.79 -1.73
68 Max.Drawdown -1779.21 -3253.19 -3402.61 -3204.56 -3455.82
69 Profit.To.Max.Draw 1.49 0.13 -0.48 -0.33 -0.53
70 Avg.WinLoss.Ratio 2.02 3.57 1.09 0.96 2.41
Med.WinLoss.Ratio 1.22 0.83 0.35 0.36 0.73
71 Max.Equity 3319.81 2235.92 291.74 1170.92 255.57
72 Min.Equity -1779.21 -1280.22 -3110.88 -2033.64 -3200.25
73 End.Equity 2644.53 434.29 -1639.77 -1071.52 -1826.08
74
75 IYR IYZ LQD RWR SHY
76 Num.Txns 106.00 108.00 43.00 114.00 33.00
Num.Trades 53.00 54.00 21.00 56.00 17.00
77 Net.Trading.PL -3809.10 -3010.91 1863.94 -3690.62 -3715.43
78 Avg.Trade.PL -71.87 -55.76 88.76 -65.90 -218.55
79 Med.Trade.PL -107.50 -94.91 -14.30 -95.48 -165.13
80 Largest.Winner 1714.13 2673.04 1618.71 1455.78 23.93
Largest.Loser -745.50 -463.08 -236.13 -476.51 -870.37
81 Gross.Profits 3465.76 3941.01 3050.21 2877.22 44.39
82 Gross.Losses -7274.86 -6951.92 -1186.26 -6567.84 -3759.82
83 Std.Dev.Trade.PL 316.10 412.75 387.67 256.76 226.14
84 Percent.Positive 22.64 22.22 47.62 19.64 11.76
85 Percent.Negative 77.36 77.78 52.38 80.36 88.24
Profit.Factor 0.48 0.57 2.57 0.44 0.01
86 Avg.Win.Trade 288.81 328.42 305.02 261.57 22.19
87 Med.Win.Trade 125.96 52.77 178.87 144.25 22.19
88 Avg.Losing.Trade -177.44 -165.52 -107.84 -145.95 -250.65
89 Med.Losing.Trade -151.10 -150.12 -97.91 -134.83 -210.93
90 Avg.Daily.PL -71.87 -55.76 80.29 -65.90 -223.39
Med.Daily.PL -107.50 -94.91 -33.90 -95.48 -188.03
91 Std.Dev.Daily.PL 316.10 412.75 395.74 256.76 232.64
92 Ann.Sharpe -3.61 -2.14 3.22 -4.07 -15.24
93 Max.Drawdown -4518.57 -4628.68 -1075.56 -4511.52 -4429.88
94 Profit.To.Max.Draw -0.84 -0.65 1.73 -0.82 -0.84
Avg.WinLoss.Ratio 1.63 1.98 2.83 1.79 0.09
95 Med.WinLoss.Ratio 0.83 0.35 1.83 1.07 0.11
96 Max.Equity 709.48 561.64 2649.32 820.90 714.45
97 Min.Equity -3809.10 -4067.04 -318.88 -3690.62 -3715.43
98 End.Equity -3809.10 -3010.91 1863.94 -3690.62 -3715.43
99
10 TLT XLB XLE XLF XLI
Num.Txns 73.00 72.00 82.00 104.00 106.00
0 Num.Trades 37.00 36.00 41.00 52.00 53.00
10 Net.Trading.PL -2881.18 75.64 -738.57 -705.52 -1281.19
1 Avg.Trade.PL -77.87 2.10 -18.01 -13.57 -24.17
10 Med.Trade.PL -147.94 -45.01 -94.63 -71.06 -77.50
Largest.Winner 1425.91 1831.45 2087.67 1058.03 1218.87
2
Largest.Loser -486.72 -423.07 -299.82 -711.69 -480.88
10 Gross.Profits 3086.09 3723.24 3173.04 5277.71 4948.54
3 Gross.Losses -5967.27 -3647.61 -3911.61 -5983.23 -6229.73
10 Std.Dev.Trade.PL 338.67 369.57 371.02 313.49 307.17
4 Percent.Positive 24.32 36.11 14.63 34.62 30.19
Percent.Negative 75.68 63.89 85.37 65.38 69.81
10 Profit.Factor 0.52 1.02 0.81 0.88 0.79
5 Avg.Win.Trade 342.90 286.40 528.84 293.21 309.28
10 Med.Win.Trade 151.67 158.38 237.83 139.29 204.28
6 Avg.Losing.Trade -213.12 -158.59 -111.76 -175.98 -168.37
10 Med.Losing.Trade -195.66 -128.42 -96.70 -144.43 -147.64
Avg.Daily.PL -86.21 2.10 -18.01 -13.57 -24.17
7 Med.Daily.PL -149.61 -45.01 -94.63 -71.06 -77.50
10 Std.Dev.Daily.PL 339.60 369.57 371.02 313.49 307.17
8 Ann.Sharpe -4.03 0.09 -0.77 -0.69 -1.25
10 Max.Drawdown -3946.88 -2772.07 -2742.16 -2243.85 -2727.83
Profit.To.Max.Draw -0.73 0.03 -0.27 -0.31 -0.47
9 Avg.WinLoss.Ratio 1.61 1.81 4.73 1.67 1.84
110Med.WinLoss.Ratio 0.78 1.23 2.46 0.96 1.38
111 Max.Equity 139.90 1411.59 335.20 1066.45 848.83
Min.Equity -3806.97 -1978.82 -2742.16 -1573.88 -2028.21
112End.Equity -2881.18 75.64 -738.57 -705.52 -1281.19
113
114 XLK XLP XLU XLV XLY
115Num.Txns 94.00 84.00 86.00 62.00 66.00
116Num.Trades 47.00 41.00 42.00 31.00 33.00
Net.Trading.PL -1651.16 -3264.51 -4665.83 -2093.02 507.06
117Avg.Trade.PL -35.13 -79.62 -111.09 -67.52 15.37
118Med.Trade.PL -99.55 -129.52 -90.84 -80.14 -100.97
119Largest.Winner 2403.16 1008.09 174.64 1447.68 2090.68
12 Largest.Loser -526.85 -460.10 -419.92 -533.05 -352.17
0 Gross.Profits 4484.79 2660.58 600.44 2419.62 4101.12
Gross.Losses -6135.95 -5925.09 -5266.27 -4512.64 -3594.06
12 Std.Dev.Trade.PL 419.01 287.43 134.66 364.01 430.90
1 Percent.Positive 31.91 19.51 21.43 16.13 30.30
12 Percent.Negative 68.09 80.49 78.57 83.87 69.70
2 Profit.Factor 0.73 0.45 0.11 0.54 1.14
12 Avg.Win.Trade
Med.Win.Trade
298.99
106.63
332.57
84.26
66.72
46.23
483.92
86.14
410.11
202.57
3 Avg.Losing.Trade -191.75 -179.55 -159.58 -173.56 -156.26
12 Med.Losing.Trade -168.10 -161.95 -152.33 -128.20 -151.78
4 Avg.Daily.PL -35.13 -79.62 -111.09 -67.52 15.37
12 Med.Daily.PL -99.55 -129.52 -90.84 -80.14 -100.97
Std.Dev.Daily.PL 419.01 287.43 134.66 364.01 430.90
5 Ann.Sharpe -1.33 -4.40 -13.10 -2.94 0.57
12 Max.Drawdown -4435.53 -5189.24 -4665.83 -3779.96 -2264.20
6 Profit.To.Max.Draw -0.37 -0.63 -1.00 -0.55 0.22
12 Avg.WinLoss.Ratio 1.56 1.85 0.42 2.79 2.62
7 Med.WinLoss.Ratio 0.63 0.52 0.30 0.67 1.33
Max.Equity 861.83 1156.76 0.00 1686.94 2771.26
12 Min.Equity -3573.71 -4032.47 -4665.83 -2093.02 -613.72
8 End.Equity -1651.16 -3264.51 -4665.83 -2093.02 507.06
12
9
13
0
13
1
13
2
13
3
13
4
13
5
13
6
13
7
13
8
13
9
14
0
14
1
14
2
14
3
14
4
14
5
14
6
14
7
14
8
14
9
15
0
15
1
15
2
15
3
15
4
15
5
15
6
15
7
15
8
15
9
16
0
16
1
16
2
16
3
16
4
16
5
16
6
16
7
16
8
16
9
17
0
17
1
17
2
17
3
17
4
17
5
17
6
17
7
17
8
17
9
1
> (aggPF <- sum(tStats$Gross.Profits)/-sum(tStats$Gross.Losses))
2 [1] 0.7443694
3 > (aggCorrect <- mean(tStats$Percent.Positive))
4 [1] 31.708
5 > (numTrades <- sum(tStats$Num.Trades))
[1] 1166
6
> (meanAvgWLR <- mean(tStats$Avg.WinLoss.Ratio))
7 [1] 1.824333
8

In other words, we can already see that the proposed confirmatory indicator is a dud. To display the raw
instrument daily stats at this point would also be uninteresting, so well move past that.

Duration statistics:

1 durStats <- durationStatistics(Portfolio=portfolio.st, Symbols=sort(symbols))


2 print(t(durStats))
EFA EPP EWA EWC EWG EWH EWJ EWS EWT EWU EWY EWZ EZU IEF IGE IYR
3 Min 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
4 Q1 2 1 1 4 1 2 1 3 1 1 1 1 2 2 1 1
5 Med 4 4 4 8 5 4 4 5 5 4 3 5 4 5 5 3
6 Mean 10 8 9 13 10 7 9 11 13 8 10 11 8 10 9 7
Q3 7 8 7 16 10 6 8 10 10 10 7 8 7 8 8 7
7 Max 83 72 79 74 77 55 98 76 79 72 105 71 83 66 90 59
8 WMin 1 1 1 7 1 1 1 1 1 1 1 1 1 1 6 1
9 WQ1 3 2 1 14 1 3 1 4 2 1 1 4 2 7 8 6
10 WMed 10 6 6 23 5 6 2 10 10 4 3 8 4 8 18 9
11 WMean 21 14 13 26 13 11 13 18 22 13 16 24 11 20 26 15
WQ3 26 14 9 29 13 7 9 26 21 15 14 41 7 39 30 17
12 WMax 83 72 79 74 77 55 98 76 79 72 105 71 83 66 90 59
13 LMin 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
14 LQ1 2 1 1 4 2 2 2 3 1 2 1 1 2 1 1 1
15 LMed 4 3 4 6 4 3 4 4 4 4 1 4 5 2 3 3
LMean 4 5 6 9 6 4 6 5 4 6 3 7 6 4 4 4
16 LQ3 6 6 6 12 8 6 8 5 5 7 3 7 7 6 6 5
17 LMax 21 23 22 33 21 14 25 32 8 29 12 68 26 10 14 36
18
19 IYZ LQD RWR SHY TLT XLB XLE XLF XLI XLK XLP XLU XLV XLY
20 Min 1 1 1 1 1 1 1 1 1 1 1 1 1 1
21 Q1 1 1 1 4 2 2 1 2 2 2 2 2 2 2
Med 5 3 3 6 4 6 4 5 4 3 4 4 5 5
22
23
24
25
26 Mean 9 9 6 9 8 12 10 13 9 9 8 6 8 14
Q3 7 5 6 12 7 14 7 18 11 10 7 6 8 11
27 Max 105 91 67 29 55 82 97 91 55 67 67 34 35 100
28 WMin 1 1 1 3 1 2 7 1 1 1 1 1 3 2
29 WQ1 3 3 8 4 2 7 9 3 3 2 4 1 7 7
30 WMed 8 5 10 6 6 17 22 20 10 15 15 4 17 26
WMean 21 17 18 6 18 23 40 26 17 20 22 9 19 35
31 WQ3 28 18 24 7 32 22 69 34 26 26 32 13 35 56
32 WMax 105 91 67 8 55 82 97 91 55 67 67 34 35 100
33 LMin 1 1 1 1 1 1 1 1 1 1 1 1 1 1
34 LQ1 1 1 1 4 2 2 1 2 2 1 1 2 1 1
35 LMed 4 1 2 6 4 3 3 4 4 3 3 4 4 4
LMean 5 2 3 9 5 6 5 6 6 4 4 4 6 4
36 LQ3 7 3 5 12 7 8 6 8 10 5 6 5 7 6
37 LMax 29 7 15 29 19 29 40 21 19 21 20 16 30 13
38
39
40
41

Basically, we can see that there are some really long trades that win, but between this table and the previous
trade stats output, that is more than swamped by the legions of losers. Here is the market exposure:

1 #market exposure
tmp <- list()
2
length(tmp) <- length(symbols)
3 for(i in 1:nrow(dStats)) {
4 totalDays <- nrow(get(rownames(dStats)[i]))
5 mktExposure <- dStats$Total.Days[i]/totalDays
6 tmp[[i]] <- c(rownames(dStats)[i], round(mktExposure, 3))
}
7 mktExposure <- data.frame(do.call(rbind, tmp))
8 colnames(mktExposure) <- c("Symbol","MktExposure")
9 print(mktExposure)
10
11 Symbol MktExposure
12 1 EFA 0.168
2 EPP 0.125
13 3 EWA 0.149
14 4 EWC 0.15
15 5 EWG 0.133
16 6 EWH 0.063
7 EWJ 0.176
17 8 EWS 0.145
18 9 EWT 0.133
19 10 EWU 0.135
20 11 EWY 0.152
21 12 EWZ 0.126
13 EZU 0.147
22 14 IEF 0.102
23 15 IGE 0.168
24 16 IYR 0.152
25 17 IYZ 0.186
26 18 LQD 0.083
19 RWR 0.149
27 20 SHY 0.052
28 21 TLT 0.126
29 22 XLB 0.168
30 23 XLE 0.16
24 XLF 0.249
31 25 XLI 0.196
32
33
34
35
36 26 XLK 0.168
27 XLP 0.129
37 28 XLU 0.101
38 29 XLV 0.1
39 30 XLY 0.168
40
41
42
43

In other words, even though the market exposure is rather small, the system still manages to hemorrhage a
great deal during those small exposures, which does not sing many praises for the proposed system.

Here is the code for a cash sharpe and the equity curve comparisons:

1
2
3 #portfolio cash PL
4 portString <- paste0("portfolio.", portfolio.st)
5 portPL <- .blotter[[portString]]$summary$Net.Trading.PL
6
#Cash Sharpe
7 (SharpeRatio.annualized(portPL, geometric=FALSE))
8
9 #Portfolio comparisons to SPY
10 instRets <- PortfReturns(account.st)
11
12 #Correlations
13 instCors <- cor(instRets)
diag(instRets) <- NA
14 corMeans <- rowMeans(instCors, na.rm=TRUE)
15 names(corMeans) <- gsub(".DailyEndEq", "", names(corMeans))
16 print(round(corMeans,3))
17 mean(corMeans)
18
portfRets <- xts(rowMeans(instRets)*ncol(instRets), order.by=index(instRets))
19 portfRets <- portfRets[!is.na(portfRets)]
20 cumPortfRets <- cumprod(1+portfRets)
21 firstNonZeroDay <- as.character(index(portfRets)[min(which(portfRets!=0))])
22 getSymbols("SPY", from=firstNonZeroDay, to=to)
23 SPYrets <- diff(log(Cl(SPY)))[-1]
cumSPYrets <- cumprod(1+SPYrets)
24 comparison <- cbind(cumPortfRets, cumSPYrets)
25 colnames(comparison) <- c("strategy", "SPY")
26 chart.TimeSeries(comparison, legend.loc = "topleft",
27 colors=c("green","red"))
28
29

Which gives us the following results:

1 (SharpeRatio.annualized(portPL, geometric=FALSE))
2 Net.Trading.PL
3 Annualized Sharpe Ratio (Rf=0%) -0.2687879
In short, the idea of using a slower FRAMA does not seem to hold much water. And here are the portfolio
statistics to confirm it:

1
> SharpeRatio.annualized(portfRets)
2 [,1]
3 Annualized Sharpe Ratio (Rf=0%) -0.2950648
4 > Return.annualized(portfRets)
5 [,1]
Annualized Return -0.01560975
6 > maxDrawdown(portfRets)
7 [1] 0.1551006
8

But why?

For that, well look at a picture of the equity curve of an individual instrument, complete with overlaid
indicators.

1
chart.Posn(portfolio.st, "XLF")
2 tmp <- FRAMA(HLC(XLF), n=nFast, FC=FCfast, SC=SCfast, triggerLag=fastTriggerLag)
3 add_TA(tmp$FRAMA, on=1, col="purple", lwd=3)
4 add_TA(tmp$trigger, on=1, col="blue", lwd=0.5)
5 tmp2 <- FRAMA(HLC(XLF), n=nSlow, FC=FCslow, SC=SCslow, triggerLag=slowTriggerLag)
6 add_TA(tmp2$FRAMA, on=1, col="orange", lwd=3)
tmp2 <- lagATR(HLC=HLC(XLF), n=period)
7 add_TA(tmp2$atr, col="purple", lwd=2)
8

Which produces the following plot:


The primary indicator is in purple, while the confirmatory indicator is in orange. And now we see the reason
why: because although the FRAMA (n=252, FC=40, SC=252) is a seemingly fine parametrization in and of
itself, as a big-picture/long-term-trend/greater smoothing indicator, it does not seem like the best choice, at
least in the conventional sense as using something such as the SMA200, ROC200 > 0, or RS Rank (see this
post from SystemTraderSuccess).

Why? Because from my intuition, adaptive moving average indicators all aim to do the same thingthey aim
to be a more accurate way of aggregating lots of data in order to tell you what is happening to as close as
current time as they can get. That is, if you look at the presentation by Dr. John Ehlers (see this link), youll
notice how similar all of the indicators are. All of them effectively aim to maximize near-term smoothness
and eliminate as much lag as possible. That is, if youre looking to make short-term momentum trades that
last five days, if your indicator has a five-day lag (EG a 10-day running median), well, your indicator isnt of
much use in that case, because by the time you receive the signal, the opportunity is over!

However, while eliminating lag is usually desirable, in one case, it isnt. To go off on a tangent, the Japanese
trading system called Ichimoku Kinko Hyo (which may be investigated in the future), created by Goichi
Hosoda, deliberately makes use of lagging current price action to create a cloud. That is, if you want a
confirmatory indicator, you want something robust (especially to the heightened volatility during
corrections, bear markets, downtrends, etc.), and something that *has* a bit of lag to it, to confirm the
relationship between the more up-to-date indicator (E.G. an adaptive moving average, a short-term oscillator
such as RSI2, etc.), and the overarching, long-term trend.

The failure to do so in this case results in problematic counter-trend trades before the financial crisis. While
the trading during the financial crisis had a very choppy equity curve during the height of the crisis itself,
this was for an individual instrument, and note, that by the end of the crisis, the strategy had indeed made
money. The greater problem was that due to the similarities in kind of the confirmatory indicator with the
one used for entries and exits, then occasionally, the confirmatory indicator would overtake the indicator it
was supposed to confirm, even in a sideways or upwards market, which resulted in several disastrous trades.

And while the indicator used for entries and exits should be as up-to-date as possible so as to get in and out
in as timely a fashion as possible, a confirmatory indicator, first and foremost, should not reverse the entire
systems understanding of the market mode on a whim, and secondly, should try to be more backward
looking, so as to better do its job of confirmation. Thus, in my opinion, the recommendation of this slower
FRAMA to be used as a confirmatory indicator by ETFHQ was rather ill-advised. Thus, the investigation
will continue into finding a more suitable confirmatory indicator.
Thanks for reading.

FRAMA Part II: Replicating A Simple Strategy


Posted on June 28, 2014 Posted in Dr. John Ehlers, ETFs, QuantStrat, R, Trading Tagged R 20
Comments

This post will begin the investigation into FRAMA strategies, with the aim of ultimately finding a FRAMA
trading strategy with less market exposure, fewer whipsaw trades, and fewer counter-trend trades. This post
will also introduce new analytics regarding trade duration.

To begin the investigation into developing strategies based on the previously-introduced FRAMA, Im going
to replicate the simple strategy from ETFHQ use a 126 day FRAMA with a fast constant of 4 (that is, an
EMA that goes as fast as a 4-day EMA), and all the way up to a slow constant of 300. For my ATR order-
sizing, which, once again, was inspired by Andreas Clenow in the post on leverage being pointless, Im
going to use 2 percent of notional capital, with a 10 day ATR for my order sizing (ATR 20 and 30 display
slightly weaker results, but nevertheless, are very close in performance).

Once again, lets start by looking at the strategy, using our same 30 instruments as with our TVI demos (I
thought about testing on mutual funds, but due to the obnoxious fees that mutual funds charge for trying to
trade with them, I feel that Id have to employ too much magical thinking to neglect their obscene trading
transaction costs):

1 require(DSTrading)
2 require(IKTrading)
require(quantstrat)
3
4 initDate="1990-01-01"
5 from="2003-01-01"
6 to="2010-12-31"
7 options(width=70)
8
#to rerun the strategy, rerun everything below this line
9 source("demoData.R") #contains all of the data-related boilerplate.
1
0 #trade sizing and initial equity settings
11tradeSize <- 10000
1 initEq <- tradeSize*length(symbols)
2
1 strategy.st <- portfolio.st <- account.st <- "FRAMA_I"
rm.strat(portfolio.st)
3 rm.strat(strategy.st)
1 initPortf(portfolio.st, symbols=symbols, initDate=initDate, currency='USD')
4 initAcct(account.st, portfolios=portfolio.st, initDate=initDate,
1 currency='USD',initEq=initEq)
5 initOrders(portfolio.st, initDate=initDate)
strategy(strategy.st, store=TRUE)
1
6 #Parameters
1
7 FC=4
1 SC=300
8 n=126
triggerLag=1
1 pctATR=.02
9 period=10
2
0 #indicators
2
1 add.indicator(strategy.st, name="FRAMA",
arguments=list(HLC=quote(HLC(mktdata)),n=n,
2
FC=FC, SC=SC, triggerLag=triggerLag),
2 label="frama")
2
3 add.indicator(strategy.st, name="lagATR",
2 arguments=list(HLC=quote(HLC(mktdata)), n=period),
4 label="atrX")
2
5
#signals
2
6 add.signal(strategy.st, name="sigCrossover",
2 arguments=list(columns=c("Close", "FRAMA.frama"), relationship="gte"),
7 label="longEntry")
2
8 add.signal(strategy.st, name="sigCrossover",
2 arguments=list(columns=c("Close", "FRAMA.frama"), relationship="lt"),
label="longExit")
9
3 #rules
0
3 add.rule(strategy.st, name="ruleSignal",
1 arguments=list(sigcol="longEntry", sigval=TRUE, ordertype="market",
3 orderside="long", replace=FALSE, prefer="Open",
osFUN=osDollarATR,
2 tradeSize=tradeSize, pctATR=pctATR, atrMod="X"),
3 type="enter", path.dep=TRUE)
3
3 add.rule(strategy.st, name="ruleSignal",
4 arguments=list(sigcol="longExit", sigval=TRUE, orderqty="all",
3 ordertype="market",
orderside="long", replace=FALSE, prefer="Open"),
5 type="exit", path.dep=TRUE)
3
6 #apply strategy
3 t1 <- Sys.time()
7 out <- applyStrategy(strategy=strategy.st,portfolios=portfolio.st)
3 t2 <- Sys.time()
print(t2-t1)
8
3
9 #set up analytics
4 updatePortf(portfolio.st)
0 dateRange <- time(getPortfolio(portfolio.st)$summary)[-1]
4 updateAcct(portfolio.st,dateRange)
updateEndEq(account.st)
1
4
2
4
3
4
4
4
5
4
6
4
7
4
8
4
9
5
0
5
1
5
2
5
3
5
4
5
5
5
6
5
7
5
8
5
9
6
0
6
1
6
2
6
3
6
4
6
5
6
6
6
7
6
8
6
9
7
0
7
1
7
2
7
3
7
4
7
5
7
6
7
7
7
8
7
9
8
0

Its a fairly simple strategybuy the next days open when the price crosses above the indicator, and vice
versa. In other words, its about as simple a strategy as you can get as its sole purpose was to demonstrate
the effectiveness of the indicator. And while someone interested can peruse through ETFHQ to find all of the
indicator relative tests, the general gist is that adaptive moving averages work very well, and the FRAMA
(the fractal adaptive moving average) works slightly better than the rest. Ultimately though, if one believes
ETFHQs analysis (and I do), then even one good trend-following indicator will be sufficient.

Here are the trade statistics:

1 EFA EPP EWA EWC EWG


Num.Txns 289.00 245.00 281.00 219.00 248.00
2
Num.Trades 145.00 123.00 140.00 109.00 121.00
3 Net.Trading.PL 9233.11 17020.32 14917.84 14298.85 13603.78
4 Avg.Trade.PL 63.68 138.38 106.56 131.18 112.43
5 Med.Trade.PL -46.29 -26.79 -24.81 -21.06 -28.14
6 Largest.Winner 2454.58 4499.10 3301.82 4031.95 3582.43
Largest.Loser -523.15 -847.71 -607.41 -613.76 -531.39
7 Gross.Profits 23874.49 29202.05 28060.29 23541.10 24820.41
8 Gross.Losses -14641.38 -12181.73 -13142.45 -9242.26 -11216.63
9 Std.Dev.Trade.PL 420.81 624.11 518.71 565.75 565.31
10 Percent.Positive 42.07 46.34 46.43 46.79 46.28
11 Percent.Negative 57.93 53.66 53.57 53.21 53.72
Profit.Factor 1.63 2.40 2.14 2.55 2.21
12 Avg.Win.Trade 391.39 512.32 431.70 461.59 443.22
13 Med.Win.Trade 199.18 238.18 220.98 236.81 179.68
14 Avg.Losing.Trade -174.30 -184.57 -175.23 -159.35 -172.56
15 Med.Losing.Trade -152.31 -121.13 -159.74 -133.38 -128.70
Avg.Daily.PL 63.07 137.42 105.72 128.59 112.43
16 Med.Daily.PL -49.26 -29.12 -27.68 -22.15 -28.14
17 Std.Dev.Daily.PL 422.22 626.59 520.49 567.74 565.31
18 Ann.Sharpe 2.37 3.48 3.22 3.60 3.16
19 Max.Drawdown -2338.49 -1945.85 -3026.93 -2001.41 -2047.83
20 Profit.To.Max.Draw 3.95 8.75 4.93 7.14 6.64
Avg.WinLoss.Ratio 2.25 2.78 2.46 2.90 2.57
21 Med.WinLoss.Ratio 1.31 1.97 1.38 1.78 1.40
22 Max.Equity 9902.70 17058.92 14996.93 14298.85 14604.43
23 Min.Equity -136.30 -189.12 -159.59 -233.07 -315.54
24 End.Equity 9233.11 17020.32 14917.84 14298.85 13603.78
25
26 EWH EWJ EWS EWT EWU
Num.Txns 271.00 243.00 275.00 199.00 227.00
27 Num.Trades 135.00 119.00 133.00 96.00 111.00
28 Net.Trading.PL 11548.79 5965.14 12676.51 12221.36 12044.63
29 Avg.Trade.PL 85.55 50.13 95.31 127.31 108.51
30 Med.Trade.PL -27.05 -26.14 -12.78 14.04 -7.08
Largest.Winner 2668.92 1872.67 2773.40 2749.00 2521.64
31 Largest.Loser -572.88 -521.96 -593.95 -537.06 -603.96
32 Gross.Profits 23173.00 17577.09 23801.66 19413.97 21927.72
33 Gross.Losses -11624.21 -11611.96 -11125.16 -7192.61 -9883.09
34 Std.Dev.Trade.PL 501.77 395.06 470.11 506.25 512.20
35 Percent.Positive 44.44 43.70 46.62 53.12 49.55
Percent.Negative 55.56 56.30 53.38 46.88 50.45
36 Profit.Factor 1.99 1.51 2.14 2.70 2.22
37 Avg.Win.Trade 386.22 338.02 383.90 380.67 398.69
Med.Win.Trade 125.17 140.16 212.49 172.84 195.04
38
Avg.Losing.Trade -154.99 -173.31 -156.69 -159.84 -176.48
39 Med.Losing.Trade -111.58 -146.64 -115.28 -138.75 -158.23
40 Avg.Daily.PL 86.78 38.81 94.45 108.42 108.20
41 Med.Daily.PL -25.57 -32.55 -17.73 12.24 -7.80
42 Std.Dev.Daily.PL 503.45 376.87 471.79 473.73 514.53
Ann.Sharpe 2.74 1.63 3.18 3.63 3.34
43 Max.Drawdown -2298.32 -3445.56 -2017.06 -2764.34 -2071.61
44 Profit.To.Max.Draw 5.02 1.73 6.28 4.42 5.81
45 Avg.WinLoss.Ratio 2.49 1.95 2.45 2.38 2.26
46 Med.WinLoss.Ratio 1.12 0.96 1.84 1.25 1.23
47 Max.Equity 12708.66 6336.41 13177.76 12221.36 12640.57
Min.Equity -272.68 -307.36 -331.04 0.00 -57.47
48 End.Equity 11548.79 5965.14 12676.51 12221.36 12044.63
49
50 EWY EWZ EZU IEF IGE
51 Num.Txns 261.00 265.00 270.00 216.00 249.00
52 Num.Trades 130.00 133.00 134.00 107.00 125.00
Net.Trading.PL 10513.27 14496.80 11233.90 13370.63 12428.65
53 Avg.Trade.PL 80.87 109.00 83.84 124.96 99.43
54 Med.Trade.PL 21.32 -42.35 -34.59 -41.49 -93.07
55 Largest.Winner 1550.67 2633.38 3163.76 2799.11 3710.24
56 Largest.Loser -614.98 -682.75 -553.54 -542.02 -576.53
57 Gross.Profits 23615.06 28466.25 25227.96 22877.10 26829.04
Gross.Losses -13101.78 -13969.45 -13994.06 -9506.47 -14400.39
58 Std.Dev.Trade.PL 417.96 548.34 538.74 546.44 660.65
59 Percent.Positive 50.77 43.61 42.54 42.06 32.80
60 Percent.Negative 49.23 56.39 57.46 57.94 67.20
61 Profit.Factor 1.80 2.04 1.80 2.41 1.86
62 Avg.Win.Trade 357.80 490.80 442.60 508.38 654.37
Med.Win.Trade 207.28 210.90 194.52 221.16 367.42
63 Avg.Losing.Trade -204.72 -186.26 -181.74 -153.33 -171.43
64 Med.Losing.Trade -187.43 -163.60 -144.77 -129.05 -154.06
65 Avg.Daily.PL 77.86 105.49 83.84 124.96 77.08
66 Med.Daily.PL 19.08 -44.57 -34.59 -41.49 -93.37
Std.Dev.Daily.PL 418.17 548.93 538.74 546.44 614.05
67 Ann.Sharpe 2.96 3.05 2.47 3.63 1.99
68 Max.Drawdown -2462.61 -2188.41 -2310.88 -2650.59 -3045.12
69 Profit.To.Max.Draw 4.27 6.62 4.86 5.04 4.08
70 Avg.WinLoss.Ratio 1.75 2.64 2.44 3.32 3.82
71 Med.WinLoss.Ratio 1.11 1.29 1.34 1.71 2.38
Max.Equity 10513.27 14760.11 12629.07 14339.37 12428.65
72 Min.Equity -339.01 -214.04 -203.63 -278.08 -268.60
73 End.Equity 10513.27 14496.80 11233.90 13370.63 12428.65
74
75 IYR IYZ LQD RWR SHY
76 Num.Txns 253.00 257.00 222.00 267.00 300.00
Num.Trades 125.00 127.00 108.00 133.00 143.00
77
Net.Trading.PL 9702.92 8599.09 13277.24 12090.68 15021.96
78 Avg.Trade.PL 77.62 67.71 122.94 90.91 105.05
79 Med.Trade.PL -60.97 -47.00 -17.31 -63.38 -41.73
80 Largest.Winner 2602.17 2511.55 2526.23 2810.42 1987.06
81 Largest.Loser -864.63 -619.97 -339.49 -758.94 -971.00
Gross.Profits 22264.43 20356.47 20777.57 25087.09 30006.10
82 Gross.Losses -12561.51 -11757.38 -7500.32 -12996.41 -14984.14
83 Std.Dev.Trade.PL 488.33 426.35 486.90 528.23 499.11
84 Percent.Positive 36.80 43.31 46.30 39.10 44.06
85 Percent.Negative 63.20 56.69 53.70 60.90 55.94
86 Profit.Factor 1.77 1.73 2.77 1.93 2.00
Avg.Win.Trade 484.01 370.12 415.55 482.44 476.29
87 Med.Win.Trade 313.81 182.80 139.12 228.24 229.73
88 Avg.Losing.Trade -159.01 -163.30 -129.32 -160.45 -187.30
89 Med.Losing.Trade -126.56 -112.84 -103.66 -147.59 -145.26
90 Avg.Daily.PL 75.21 66.83 122.94 88.59 105.05
Med.Daily.PL -61.69 -50.50 -17.31 -65.60 -41.73
91 Std.Dev.Daily.PL 489.56 427.93 486.90 529.57 499.11
92 Ann.Sharpe 2.44 2.48 4.01 2.66 3.34
Max.Drawdown -5488.96 -2253.39 -1261.10 -5062.88 -2852.91
93
Profit.To.Max.Draw 1.77 3.82 10.53 2.39 5.27
94 Avg.WinLoss.Ratio 3.04 2.27 3.21 3.01 2.54
95 Med.WinLoss.Ratio 2.48 1.62 1.34 1.55 1.58
96 Max.Equity 13313.44 9225.39 14084.98 15192.88 16570.24
97 Min.Equity -152.91 -522.27 -347.48 -394.76 -1036.81
End.Equity 9702.92 8599.09 13277.24 12090.68 15021.96
98
99 TLT XLB XLE XLF XLI
100 Num.Txns 238.00 247.00 229.00 245.00 261.00
101 Num.Trades 118.00 122.00 115.00 121.00 130.00
102 Net.Trading.PL 7117.62 6227.48 10335.40 -8.45 6351.34
103 Avg.Trade.PL 60.32 51.04 89.87 -0.07 48.86
Med.Trade.PL -71.33 -62.80 -65.87 -56.76 -45.18
104 Largest.Winner 2548.77 2083.24 2407.81 1895.31 1571.81
105 Largest.Loser -509.75 -544.43 -484.90 -626.99 -465.20
106 Gross.Profits 20099.36 19500.08 21827.84 12869.00 17364.07
107 Gross.Losses -12981.73 -13272.60 -11492.44 -12877.45 -11012.73
Std.Dev.Trade.PL 506.64 421.98 566.48 345.43 379.26
108 Percent.Positive 31.36 36.89 34.78 35.54 41.54
109 Percent.Negative 68.64 63.11 65.22 64.46 58.46
110 Profit.Factor 1.55 1.47 1.90 1.00 1.58
111 Avg.Win.Trade 543.23 433.34 545.70 299.28 321.56
112 Med.Win.Trade 230.04 248.59 241.31 153.68 129.61
Avg.Losing.Trade -160.27 -172.37 -153.23 -165.10 -144.90
113 Med.Losing.Trade -130.27 -159.19 -148.44 -134.74 -131.29
114 Avg.Daily.PL 60.32 47.96 68.35 -8.00 34.56
115 Med.Daily.PL -71.33 -65.49 -66.25 -58.07 -46.28
116 Std.Dev.Daily.PL 506.64 422.35 519.59 335.64 343.76
117 Ann.Sharpe 1.89 1.80 2.09 -0.38 1.60
Max.Drawdown -4938.54 -3692.51 -2780.65 -5704.14 -3013.95
118 Profit.To.Max.Draw 1.44 1.69 3.72 0.00 2.11
119 Avg.WinLoss.Ratio 3.39 2.51 3.56 1.81 2.22
120 Med.WinLoss.Ratio 1.77 1.56 1.63 1.14 0.99
121 Max.Equity 9318.18 6780.72 10335.40 4191.68 6357.94
Min.Equity -693.51 -213.25 -557.67 -1512.46 -795.23
122 End.Equity 7117.62 6227.48 10335.40 -8.45 6351.34
123
124 XLK XLP XLU XLV XLY
125 Num.Txns 254.00 280.00 241.00 218.00 220.00
126 Num.Trades 127.00 137.00 121.00 107.00 109.00
127 Net.Trading.PL 2940.29 2543.61 7904.42 3189.25 6727.03
Avg.Trade.PL 23.15 18.57 65.33 29.81 61.72
128 Med.Trade.PL -72.35 -85.92 -38.84 -88.65 -71.80
129 Largest.Winner 2050.23 1782.84 1240.83 1927.28 2667.81
130 Largest.Loser -749.16 -679.39 -598.65 -662.12 -559.61
131 Gross.Profits 16321.02 17361.88 18269.97 14178.93 18237.47
Gross.Losses -13380.73 -14818.27 -10365.55 -10989.67 -11510.44
132
Std.Dev.Trade.PL 389.23 363.63 363.21 418.10 525.74
133 Percent.Positive 35.43 32.12 43.80 28.97 39.45
134 Percent.Negative 64.57 67.88 56.20 71.03 60.55
135 Profit.Factor 1.22 1.17 1.76 1.29 1.58
136 Avg.Win.Trade 362.69 394.59 344.72 457.38 424.13
Med.Win.Trade 158.36 236.63 180.99 238.62 159.38
137 Avg.Losing.Trade -163.18 -159.34 -152.43 -144.60 -174.40
138 Med.Losing.Trade -135.65 -131.38 -124.59 -122.90 -146.41
139 Avg.Daily.PL 23.15 18.57 63.70 29.81 61.72
140 Med.Daily.PL -72.35 -85.92 -41.32 -88.65 -71.80
141 Std.Dev.Daily.PL 389.23 363.63 364.29 418.10 525.74
Ann.Sharpe 0.94 0.81 2.78 1.13 1.86
142 Max.Drawdown -3074.10 -4531.59 -2545.84 -4623.78 -4041.34
143 Profit.To.Max.Draw 0.96 0.56 3.10 0.69 1.66
144 Avg.WinLoss.Ratio 2.22 2.48 2.26 3.16 2.43
145 Med.WinLoss.Ratio 1.17 1.80 1.45 1.94 1.09
Max.Equity 2981.10 2993.23 8632.88 3902.68 6838.89
146 Min.Equity -1716.68 -1538.36 -165.00 -1213.50 -310.63
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163 End.Equity 2940.29 2543.61 7904.42 3189.25 6727.03
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

And the aggregate trade statistics:

1
> (aggPF <- sum(tStats$Gross.Profits)/-sum(tStats$Gross.Losses))
2 [1] 1.828178
3 > (aggCorrect <- mean(tStats$Percent.Positive))
4 [1] 41.55233
5 > (numTrades <- sum(tStats$Num.Trades))
6 [1] 3704
> (meanAvgWLR <- mean(tStats$Avg.WinLoss.Ratio))
7 [1] 2.619
8

Far from spectacular. Less than 50% hit rate, the profit factor definitely indicates that there is massive room
for improvement as well.

Here are the daily statistics:

1 EFA EPP EWA EWC EWG


Total.Net.Profit 9233.11 17020.32 14917.84 14298.85 13603.78
2
Total.Days 1280.00 1330.00 1330.00 1296.00 1264.00
3 Winning.Days 690.00 729.00 725.00 719.00 702.00
4 Losing.Days 590.00 601.00 605.00 577.00 562.00
5 Avg.Day.PL 7.21 12.80 11.22 11.03 10.76
6 Med.Day.PL 12.85 16.84 17.06 18.59 21.33
Largest.Winner 725.53 521.47 428.25 648.73 510.14
7
Largest.Loser -973.81 -1162.04 -722.38 -505.11 -841.33
8 Gross.Profits 72427.12 85143.30 80490.48 70817.88 75036.35
9 Gross.Losses -63194.01 -68122.98 -65572.64 -56519.03 -61432.57
10 Std.Dev.Daily.PL 139.51 153.35 140.28 125.46 141.11
11 Percent.Positive 53.91 54.81 54.51 55.48 55.54
Percent.Negative 46.09 45.19 45.49 44.52 44.46
12 Profit.Factor 1.15 1.25 1.23 1.25 1.22
13 Avg.Win.Day 104.97 116.79 111.02 98.49 106.89
14 Med.Win.Day 83.48 95.05 90.88 83.65 84.31
15 Avg.Losing.Day -107.11 -113.35 -108.38 -97.95 -109.31
16 Med.Losing.Day -81.61 -83.94 -84.18 -72.76 -84.31
Avg.Daily.PL 7.21 12.80 11.22 11.03 10.76
17 Med.Daily.PL 12.85 16.84 17.06 18.59 21.33
18 Std.Dev.Daily.PL.1 139.51 153.35 140.28 125.46 141.11
19 Ann.Sharpe 0.82 1.32 1.27 1.40 1.21
20 Max.Drawdown -2338.49 -1945.85 -3026.93 -2001.41 -2047.83
Profit.To.Max.Draw 3.95 8.75 4.93 7.14 6.64
21 Avg.WinLoss.Ratio 0.98 1.03 1.02 1.01 0.98
22 Med.WinLoss.Ratio 1.02 1.13 1.08 1.15 1.00
23 Max.Equity 9902.70 17058.92 14996.93 14298.85 14604.43
24 Min.Equity -136.30 -189.12 -159.59 -233.07 -315.54
25 End.Equity 9233.11 17020.32 14917.84 14298.85 13603.78
26
EWH EWJ EWS EWT EWU
27 Total.Net.Profit 11548.79 5965.14 12676.51 12221.36 12044.63
28 Total.Days 1221.00 1130.00 1300.00 1138.00 1252.00
29 Winning.Days 644.00 588.00 712.00 610.00 689.00
30 Losing.Days 577.00 542.00 588.00 528.00 563.00
31 Avg.Day.PL 9.46 5.28 9.75 10.74 9.62
Med.Day.PL 11.07 13.74 17.01 18.92 18.71
32 Largest.Winner 456.34 640.14 578.24 780.22 596.56
33 Largest.Loser -495.32 -496.23 -1058.32 -835.42 -812.47
34 Gross.Profits 71689.04 67809.75 70413.47 71565.95 71295.50
35 Gross.Losses -60140.25 -61844.61 -57736.96 -59344.59 -59250.87
Std.Dev.Daily.PL 138.92 148.13 130.19 150.04 132.82
36 Percent.Positive 52.74 52.04 54.77 53.60 55.03
37 Percent.Negative 47.26 47.96 45.23 46.40 44.97
38 Profit.Factor 1.19 1.10 1.22 1.21 1.20
39 Avg.Win.Day 111.32 115.32 98.90 117.32 103.48
40 Med.Win.Day 89.52 94.38 79.32 95.13 87.31
Avg.Losing.Day -104.23 -114.10 -98.19 -112.40 -105.24
41 Med.Losing.Day -81.34 -92.34 -75.96 -85.69 -82.84
42 Avg.Daily.PL 9.46 5.28 9.75 10.74 9.62
43 Med.Daily.PL 11.07 13.74 17.01 18.92 18.71
44 Std.Dev.Daily.PL.1 138.92 148.13 130.19 150.04 132.82
Ann.Sharpe 1.08 0.57 1.19 1.14 1.15
45
Max.Drawdown -2298.32 -3445.56 -2017.06 -2764.34 -2071.61
46 Profit.To.Max.Draw 5.02 1.73 6.28 4.42 5.81
47 Avg.WinLoss.Ratio 1.07 1.01 1.01 1.04 0.98
48 Med.WinLoss.Ratio 1.10 1.02 1.04 1.11 1.05
49 Max.Equity 12708.66 6336.41 13177.76 12221.36 12640.57
Min.Equity -272.68 -307.36 -331.04 0.00 -57.47
50 End.Equity 11548.79 5965.14 12676.51 12221.36 12044.63
51
52 EWY EWZ EZU IEF IGE
53 Total.Net.Profit 10513.27 14496.80 11233.90 13370.63 12428.65
54 Total.Days 1297.00 1351.00 1282.00 1186.00 1362.00
55 Winning.Days 714.00 743.00 705.00 628.00 730.00
Losing.Days 583.00 608.00 577.00 558.00 632.00
56 Avg.Day.PL 8.11 10.73 8.76 11.27 9.13
57 Med.Day.PL 15.39 16.83 16.09 13.04 12.81
58 Largest.Winner 461.13 661.59 726.99 660.63 666.40
59 Largest.Loser -819.21 -837.40 -1254.82 -555.37 -643.72
Gross.Profits 77069.26 77329.78 74286.39 79557.53 81524.20
60 Gross.Losses -66555.99 -62832.98 -63052.49 -66186.90 -69095.55
61 Std.Dev.Daily.PL 146.05 135.63 142.76 158.58 142.55
Percent.Positive 55.05 55.00 54.99 52.95 53.60
62
Percent.Negative 44.95 45.00 45.01 47.05 46.40
63 Profit.Factor 1.16 1.23 1.18 1.20 1.18
64 Avg.Win.Day 107.94 104.08 105.37 126.68 111.68
65 Med.Win.Day 88.89 81.86 84.23 99.02 92.92
66 Avg.Losing.Day -114.16 -103.34 -109.28 -118.61 -109.33
Med.Losing.Day -80.09 -78.39 -82.94 -94.81 -90.22
67 Avg.Daily.PL 8.11 10.73 8.76 11.27 9.13
68 Med.Daily.PL 15.39 16.83 16.09 13.04 12.81
69 Std.Dev.Daily.PL.1 146.05 135.63 142.76 158.58 142.55
70 Ann.Sharpe 0.88 1.26 0.97 1.13 1.02
71 Max.Drawdown -2462.61 -2188.41 -2310.88 -2650.59 -3045.12
Profit.To.Max.Draw 4.27 6.62 4.86 5.04 4.08
72 Avg.WinLoss.Ratio 0.95 1.01 0.96 1.07 1.02
73 Med.WinLoss.Ratio 1.11 1.04 1.02 1.04 1.03
74 Max.Equity 10513.27 14760.11 12629.07 14339.37 12428.65
75 Min.Equity -339.01 -214.04 -203.63 -278.08 -268.60
End.Equity 10513.27 14496.80 11233.90 13370.63 12428.65
76
77 IYR IYZ LQD RWR SHY
78 Total.Net.Profit 9702.92 8599.09 13277.24 12090.68 15021.96
79 Total.Days 1272.00 1232.00 1231.00 1306.00 1350.00
80 Winning.Days 689.00 656.00 687.00 708.00 738.00
81 Losing.Days 583.00 576.00 544.00 598.00 612.00
Avg.Day.PL 7.63 6.98 10.79 9.26 11.13
82 Med.Day.PL 12.50 11.72 14.81 11.46 20.75
83 Largest.Winner 550.83 601.69 1475.28 648.22 591.25
84 Largest.Loser -749.58 -803.69 -724.79 -960.12 -988.98
85 Gross.Profits 68544.80 62158.11 60933.53 74573.82 80464.45
86 Gross.Losses -58841.88 -53559.03 -47656.28 -62483.14 -65442.49
Std.Dev.Daily.PL 131.85 123.46 119.48 139.10 140.36
87 Percent.Positive 54.17 53.25 55.81 54.21 54.67
88 Percent.Negative 45.83 46.75 44.19 45.79 45.33
89 Profit.Factor 1.16 1.16 1.28 1.19 1.23
90 Avg.Win.Day 99.48 94.75 88.70 105.33 109.03
Med.Win.Day 82.65 72.40 70.23 83.85 88.76
91 Avg.Losing.Day -100.93 -92.98 -87.60 -104.49 -106.93
92 Med.Losing.Day -72.35 -70.97 -69.84 -78.11 -88.06
93 Avg.Daily.PL 7.63 6.98 10.79 9.26 11.13
94 Med.Daily.PL 12.50 11.72 14.81 11.46 20.75
95 Std.Dev.Daily.PL.1 131.85 123.46 119.48 139.10 140.36
Ann.Sharpe 0.92 0.90 1.43 1.06 1.26
96 Max.Drawdown -5488.96 -2253.39 -1261.10 -5062.88 -2852.91
97 Profit.To.Max.Draw 1.77 3.82 10.53 2.39 5.27
98 Avg.WinLoss.Ratio 0.99 1.02 1.01 1.01 1.02
99 Med.WinLoss.Ratio 1.14 1.02 1.01 1.07 1.01
Max.Equity 13313.44 9225.39 14084.98 15192.88 16570.24
100
Min.Equity -152.91 -522.27 -347.48 -394.76 -1036.81
101 End.Equity 9702.92 8599.09 13277.24 12090.68 15021.96
102
103 TLT XLB XLE XLF XLI
104 Total.Net.Profit 7117.62 6227.48 10335.40 -8.45 6351.34
105 Total.Days 1126.00 1252.00 1336.00 1208.00 1291.00
Winning.Days 576.00 679.00 732.00 626.00 694.00
106 Losing.Days 550.00 573.00 604.00 582.00 597.00
107 Avg.Day.PL 6.32 4.97 7.74 -0.01 4.92
108 Med.Day.PL 7.01 12.34 15.29 6.50 11.06
109 Largest.Winner 706.10 586.14 525.30 425.95 479.01
110 Largest.Loser -609.88 -815.74 -501.16 -446.61 -384.75
Gross.Profits 70845.43 64778.65 73739.30 55919.96 61941.72
111 Gross.Losses -63727.80 -58551.17 -63403.90 -55928.41 -55590.37
112 Std.Dev.Daily.PL 158.57 130.49 131.97 122.51 116.99
113 Percent.Positive 51.15 54.23 54.79 51.82 53.76
114 Percent.Negative 48.85 45.77 45.21 48.18 46.24
Profit.Factor 1.11 1.11 1.16 1.00 1.11
115 Avg.Win.Day 123.00 95.40 100.74 89.33 89.25
116 Med.Win.Day 93.07 72.97 79.85 66.21 73.41
Avg.Losing.Day -115.87 -102.18 -104.97 -96.10 -93.12
117
Med.Losing.Day -89.17 -77.13 -79.13 -69.41 -72.87
118 Avg.Daily.PL 6.32 4.97 7.74 -0.01 4.92
119 Med.Daily.PL 7.01 12.34 15.29 6.50 11.06
120 Std.Dev.Daily.PL.1 158.57 130.49 131.97 122.51 116.99
121 Ann.Sharpe 0.63 0.61 0.93 0.00 0.67
Max.Drawdown -4938.54 -3692.51 -2780.65 -5704.14 -3013.95
122 Profit.To.Max.Draw 1.44 1.69 3.72 0.00 2.11
123 Avg.WinLoss.Ratio 1.06 0.93 0.96 0.93 0.96
124 Med.WinLoss.Ratio 1.04 0.95 1.01 0.95 1.01
125 Max.Equity 9318.18 6780.72 10335.40 4191.68 6357.94
126 Min.Equity -693.51 -213.25 -557.67 -1512.46 -795.23
End.Equity 7117.62 6227.48 10335.40 -8.45 6351.34
127
128 XLK XLP XLU XLV XLY
129 Total.Net.Profit 2940.29 2543.61 7904.42 3189.25 6727.03
130 Total.Days 1210.00 1326.00 1322.00 1153.00 1179.00
131 Winning.Days 664.00 704.00 710.00 593.00 611.00
Losing.Days 546.00 622.00 612.00 560.00 568.00
132 Avg.Day.PL 2.43 1.92 5.98 2.77 5.71
133 Med.Day.PL 14.64 11.03 12.12 5.31 8.48
134 Largest.Winner 437.09 537.52 546.32 453.96 450.42
135 Largest.Loser -765.80 -750.98 -855.10 -726.49 -447.69
136 Gross.Profits 57610.32 62334.98 61795.49 53165.92 58852.52
Gross.Losses -54670.02 -59791.38 -53891.07 -49976.67 -52125.49
137 Std.Dev.Daily.PL 122.10 118.49 115.44 117.37 120.29
138 Percent.Positive 54.88 53.09 53.71 51.43 51.82
139 Percent.Negative 45.12 46.91 46.29 48.57 48.18
140 Profit.Factor 1.05 1.04 1.15 1.06 1.13
141 Avg.Win.Day 86.76 88.54 87.04 89.66 96.32
Med.Win.Day 71.15 73.84 70.10 72.61 78.75
142 Avg.Losing.Day -100.13 -96.13 -88.06 -89.24 -91.77
143 Med.Losing.Day -72.57 -74.82 -65.52 -71.56 -70.88
144 Avg.Daily.PL 2.43 1.92 5.98 2.77 5.71
145 Med.Daily.PL 14.64 11.03 12.12 5.31 8.48
Std.Dev.Daily.PL.1 122.10 118.49 115.44 117.37 120.29
146 Ann.Sharpe 0.32 0.26 0.82 0.37 0.75
147 Max.Drawdown -3074.10 -4531.59 -2545.84 -4623.78 -4041.34
148 Profit.To.Max.Draw 0.96 0.56 3.10 0.69 1.66
149 Avg.WinLoss.Ratio 0.87 0.92 0.99 1.00 1.05
150 Med.WinLoss.Ratio 0.98 0.99 1.07 1.01 1.11
Max.Equity 2981.10 2993.23 8632.88 3902.68 6838.89
151 Min.Equity -1716.68 -1538.36 -165.00 -1213.50 -310.63
152 End.Equity 2940.29 2543.61 7904.42 3189.25 6727.03
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

Now, Id like to introduce some new analytics found in my IKTrading packagenamely, trade duration
statistics. This is a simple little function that breaks down the trades by duration, in aggregate, winners, and
losers, using the usual five-number summary and the mean time. Its programmed under the assumption that
the units are days. Once you start drilling into more frequent trading, one would likely need a bit more
refined analysis. However, as most freely available data occurs at the daily frequency, this function should
be sufficient for most analyses.

Here is the input and output for this strategy:

1 durStats <- durationStatistics(Portfolio=portfolio.st, Symbols=sort(symbols))


2 print(t(durStats))
1 EFA EPP EWA EWC EWG EWH EWJ EWS EWT EWU EWY EWZ EZU IEF IGE IYR
Min 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2
Q1 2 2 2 3 2 2 2 2 2 2 2 3 2 2 2 3
3 Med 6 6 5 7 6 4 5 6 6 6 6 6 6 4 6 6
4 Mean 12 14 13 16 14 12 12 13 16 15 13 13 12 15 14 13
5 Q3 14 15 14 17 13 12 11 14 18 14 15 14 13 17 14 12
6 Max 119 132 135 122 126 185 130 139 106 132 105 95 131 144 125 128
WMin 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1
7 WQ1 9 7 3 8 3 2 2 6 3 6 5 7 5 6 9 7
8 WMed 14 14 14 18 12 11 8 13 14 14 13 14 13 17 19 15
9 WMean 22 25 22 28 24 21 20 23 24 27 21 24 23 28 30 28
10 WQ3 20 28 26 34 25 20 25 23 38 28 27 37 22 38 42 33
11 WMax 119 132 135 122 126 185 130 139 106 132 105 95 131 144 125 128
LMin 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
12 LQ1 1 1 1 2 1 2 2 1 1 1 1 1 1 1 1 2
13 LMed 3 4 3 4 3 3 3 3 3 3 3 3 3 3 3 4
14 LMean 4 5 5 6 5 5 6 5 7 4 5 5 5 5 6 5
15 LQ3 5 7 6 7 7 6 8 6 6 6 6 6 6 5 6 6
LMax 30 22 22 34 28 30 25 41 64 17 28 43 22 40 62 40
16
17 IYZ LQD RWR SHY TLT XLB XLE XLF XLI XLK XLP XLU XLV XLY
18 Min 1 1 1 1 1 1 1 1 1 1 1 1 1 1
19 Q1 3 1 2 2 2 3 2 2 2 2 2 3 2 3
20 Med 6 4 5 6 5 7 6 5 7 6 4 7 5 8
21 Mean 13 15 13 12 12 14 15 13 12 13 13 15 14 15
Q3 13 14 12 14 12 15 16 15 13 13 13 14 13 14
22 Max 115 151 128 109 90 105 113 130 99 116 117 121 132 123
23 WMin 1 1 1 1 1 6 1 1 1 1 1 1 1 1
24 WQ1 6 3 7 6 9 12 9 9 6 6 5 7 9 11
25 WMed 13 13 14 14 21 16 19 17 12 14 17 16 15 14
26 WMean 23 27 27 22 29 28 31 27 21 27 29 27 35 28
WQ3 34 28 27 28 43 34 48 32 20 38 45 40 44 28
27 WMax 115 151 128 109 90 105 113 130 99 116 117 121 132 123
28 LMin 1 1 1 1 1 1 1 1 1 1 1 1 1 1
29
30
31
32 LQ1 2 1 1 2 1 1 1 2 1 1 1 1 1 2
33 LMed 4 2 3 4 3 3 3 3 4 4 4 4 4 4
34 LMean 5 5 4 5 5 6 6 6 7 5 6 5 6 6
35 LQ3 6 5 6 6 6 7 7 7 8 7 7 7 7 8
LMax 33 25 32 42 31 36 38 41 36 19 41 39 69 35
36
37
38
39

From top to bottom in this transposed table (or left to right in the original), we have aggregate trade duration
statistics, the same statistics on winners, and finally, losers. This paints a picture of this current strategy as
having a profile of a classic trend follower: let your winners run, and cut your losses. Or, to set it to a higher
standard, the occasional winner at the price of plenty of small whipsaws, with the occasional long-duration
loser. Note that this loser may not have been a loser the entire timeit could very well have been a trade that
was going sideways for a long time and finally sunk into negative territory near the end, but it seems that
every instrument has had at least one somewhat long-running trade that wound up losing at least a penny.

On the winning side of the trade, the winning trades stay in the market for long berths, with the best ones
riding waves that last for around half a year. Ultimately, this is the appeal of trend followingthe idea of just
getting in once, and just having the market pay you. The goal of investigating the FRAMA (and potentially
other trend indicators), is to try and locate those long profit waves while avoiding the whipsaws,
countertrends, and so on.

One other interesting piece of analytics Im incorporating into this demo is the idea of market exposureor
what percentage of the time that the strategy is actually *in* the market. Here is the code and the results:

1
2 #market exposure
tmp <- list()
3 length(tmp) <- length(symbols)
4 for(i in 1:nrow(dStats)) {
5 totalDays <- nrow(get(rownames(dStats)[i]))
6 mktExposure <- dStats$Total.Days[i]/totalDays
7 tmp[[i]] <- c(rownames(dStats)[i], round(mktExposure, 3))
}
8 mktExposure <- data.frame(do.call(rbind, tmp))
9 colnames(mktExposure) <- c("Symbol","MktExposure")
10 print(mktExposure)
11

Essentially, this little piece of code takes advantage of the daily statistics output to compute market
exposure. Heres the output:

1 Symbol MktExposure
1 EFA 0.635
2
2 EPP 0.66
3 3 EWA 0.66
4 4 EWC 0.643
5 5 EWG 0.627
6 6 EWH 0.606
7 EWJ 0.561
7 8 EWS 0.645
8 9 EWT 0.565
9 10 EWU 0.621
10 11 EWY 0.644
11 12 EWZ 0.67
13 EZU 0.636
12
13
14
15 14 IEF 0.589
15 IGE 0.676
16
16 IYR 0.631
17 17 IYZ 0.611
18 18 LQD 0.611
19 19 RWR 0.648
20 20 SHY 0.67
21 TLT 0.559
21 22 XLB 0.621
22 23 XLE 0.663
23 24 XLF 0.6
24 25 XLI 0.641
25 26 XLK 0.6
27 XLP 0.658
26 28 XLU 0.656
27 29 XLV 0.572
28 30 XLY 0.585
29
30
31

So basically, around 60-66% of the time spent in the market, most of which are short, sporadic, losing
trades, with the occasional long winner.

Heres what the equity curve looks like:

As can be seen during the crisis, this baseline strategy is taking lots of tradesfor no reason at all.

And here are the three aggregate portfolio statistics:

1 > SharpeRatio.annualized(portfRets)
[,1]
2
Annualized Sharpe Ratio (Rf=0%) 1.334861
3
4 > Return.annualized(portfRets)
5 [,1]
6 Annualized Return 0.1288973
7 > maxDrawdown(portfRets)
[1] 0.1562275
8

The largest drawdown occurs during the crisis, but beyond that, the annualized returns are solid. What I find
most impressive is that the annualized Sharpe Ratio over the course of this backtest, even with what seems
to be a period of drawdowns that can be removed with what seems to be relative ease (most market timing
trend-followers seem to do a decent job of avoiding most of the brunt of the crisis).

And finally, to demonstrate the indicator and investigate areas for improvement, heres the equity curve of
XLF (not XLB this time), since XLF lost eight dollars over the course of the backtest.

One advantage that I think the FRAMA has over the Trend Vigor is that as it is an indicator thats
superimposed directly on the price action, its easier to understand visually. (Also, the math is definitely
more intuitive.) As we can see from the XLF equity curve, the base strategy presented by ETFHQ could
certainly use a confirmatory, slower-moving indicator to keep out counter-trend trading. After all, while the
tiny little whipsaw trades are undoubtedly a nuisance, correcting counter-trend trading is a lower-hanging
fruit, and would seem to be more profitable in addressing.

Thanks for reading.

The Continuing Search For Robust Momentum


Indicators: the Fractal Adaptive Moving Average
Posted on June 22, 2014 Posted in Dr. John Ehlers, ETFs, R, Trading Tagged R 14 Comments

Following from the last post and setting aside the not-working-as-advertised Trend Vigor indicator, we will
turn our attention to the world of adaptive moving averages. In this case, I will be working with the
FRAMAthe FRactal Adaptive Moving Average. The reason I am starting off with this one is that according
to ETFHQ in this post, FRAMA is an indicator that seems to have very strong performance, even using what
definitely seems to be a very simple strategy (long if the price crosses over the indicator, exit vice versa),
which would most likely leave one open to whipsaws.
But before then, Id like to make an introduction to the FRAMA, by linking to the original Dr. John Ehlers
paper, here.

While I wont attempt to give a better formal explanation than the man that created the indicator (which is
why the paper is there), the way I intuitively think about the FRAMA (or the adaptive moving average
family of indicators, found here) is that they are improvements of the exponential moving average that
attempt to smooth the indicator during cyclical market periods to avoid whipsaws, and to have a faster
response during periods of strong trends, so as to minimize the damage done due to an ending trend.

The FRAMA itself compares two periods of n/2 days (the last n/2 days, and the last n/2 days before those
last n/2 days) to the total period (n days). Intuitively, if there is a straight trend upwards, then the expression
(log(N1+N2)-log(N3))/log(2), where N1 is the difference of highest high and lowest low over the last n/2
days and N2 is identical except for the previous n/2 days before the last n/2 days, and N3 is the same
quantity over all n days, will be equal to zero, and thus, the exponent of that would be equal to 1, which is
analogous to an EMA of 1 day. Similarly, when there is a great deal of congestion, then the expression
log(N1+N2) will be greater than log(N3), and so the exponent (that is, the fractal dimension) of the exponent
would be closer to 2 (or greater, since I implemented the modified FRAMA).

Lets look at the code:

1
2
3 "FRAMA" <- function(HLC, n=20, FC=1, SC=200, triggerLag=1, ...) {
4 price <- ehlersPriceMethod(HLC, ...)
5 if (n%%2==1) n=n-1 #n must be even
6 N3 <- (runMax(Hi(HLC), n)-runMin(Lo(HLC), n))/n
N1 <- (runMax(Hi(HLC), n/2)-runMin(Lo(HLC), n/2))/(n/2)
7 lagSeries <- lag(HLC, n/2)
8 N2 <- (runMax(Hi(lagSeries), n/2)-runMin(Lo(lagSeries), n/2))/(n/2)
9 dimen <- (log(N1+N2)-log(N3))/log(2)
10 w <- log(2/(SC+1))
11 oldAlpha <- exp(w*(dimen-1))
oldN <- (2-oldAlpha)/oldAlpha
12 newN <- ((SC-FC)*(oldN-1)/(SC-1))+FC
13 alpha <- 2/(newN+1)
14 alpha[which(alpha > 1)] <- 1
15 alpha[which(alpha < w)] <- w
alphaComplement <- 1-alpha
16 initializationIndex <- index(alpha[is.na(alpha)])
17 alpha[is.na(alpha)] <- 1; alphaComplement[is.na(alphaComplement)] <- 0
18 FRAMA <- rep(0, length(price))
19 FRAMA[1] <- price[1]
20 FRAMA <- computeFRAMA(alpha, alphaComplement, FRAMA, price)
FRAMA <- xts(FRAMA, order.by=index(price))
21 FRAMA[initializationIndex] <- alpha[initializationIndex] <- NA
22 trigger <- lag(FRAMA, triggerLag)
23 out <- cbind(FRAMA=FRAMA, trigger=trigger)
24 return(out)
25 }
26
27
NumericVector computeFRAMA(NumericVector alpha, NumericVector alphaComplement,
NumericVector FRAMA, NumericVector price) {
int n = price.size();
for(int i=1; i<n; i++) {
FRAMA[i] = alpha[i]*price[i] + alphaComplement[i]*FRAMA[i-1];
}
return FRAMA;
}
Essentially, from the second chunk of code, this is an advanced form of the exponential moving average that
takes into account the amount of movement over a greater time period relative to the swing at two finer
intervals in the two halves of that period. The methodology for the modified FRAMA is thanks to ETFHQ
(once again), found here.

And while words can make for a bit of explanation, in this case, a picture (or several) is worth far more.
Here is some code I wrote to plot an EMA, and three separate FRAMA computations (the default John
Ehlers settings, the best ETFHQ settings, and the slower ETFHQ settings) on XLB from 2003 through 2010
(yes, the same XLB from our Trend Vigor backtest, because it was the go-to instrument for all our individual
equity curves).

1
2
3 from="2003-01-01"
to="2010-12-31"
4 source("demoData.R")
5
6 tmp <- FRAMA(HLC(XLB))
7 tmp2 <- FRAMA(HLC(XLB), FC=4, n=126, SC=300)
8 tmp3 <- FRAMA(HLC(XLB), FC=40, n=252, SC=252)
9 ema <- EMA(x=Cl(XLB),n=126)
10
myTheme<-chart_theme()
11 myTheme$col$dn.col<-'gray2'
12 myTheme$col$dn.border <-'gray2'
13 myTheme$col$up.border <-'gray2'
14
15 chart_Series(XLB,
TA="add_TA(tmp$FRAMA, col='blue', on=1, lwd=3);
16
add_TA(tmp2$FRAMA, col='green', on=1, lwd=3);
17 add_TA(tmp3$FRAMA, col='red', on=1, lwd=3);
18 add_TA(ema$EMA, col='orange', on=1, lwd=3)",
19 theme=myTheme)
20
21 legend(x=5, y=40, legend=c("FRAMA FC=1, n=20, SC=200",
"FRAMA FC=4, n=126, SC=300",
22 "FRAMA FC=40, n=252, SC=252",
23 "EMA n=126"),
24 fill=c("blue", "green", "red", "orange"), bty="n")
25
26

This produces the following plot:


From this perspective, the improvements are clear. Essentially, the long-term FRAMA (FC 40, n 252, SC
252) possesses much of the smoothness of the 126 day EMA, while being far more responsive to the turns in
price action to keep open equity at the end of a trend. The two faster FRAMAs, on the other hand, hug the
price action more closely, yet still retain a degree of smoothness.

Heres the code to zoom in on 2007-2008.

1
2 chart_Series(XLB,
TA="add_TA(tmp$FRAMA, col='blue', on=1, lwd=3);
3 add_TA(tmp2$FRAMA, col='green', on=1, lwd=3);
4 add_TA(tmp3$FRAMA, col='red', on=1, lwd=3);
5 add_TA(ema$EMA, col='orange', on=1, lwd=3)",
6 theme=myTheme, subset="2007::2008")
7
8 legend(x=5, y=30, legend=c("FRAMA FC=1, n=20, SC=200",
"FRAMA FC=4, n=126, SC=300",
9 "FRAMA FC=40, n=252, SC=252",
10 "EMA n=126"),
11 fill=c("blue", "green", "red", "orange"), bty="n")
12

And, the corresponding plot.


Here, we can see some more properties. While the default John Ehlers settings (blue) seemingly tracks price
action very closely, the indicator usually finds itself right in the middle of the price action, but still has the
occasional trend following property when price action breaks through it at the start of the financial crisis. In
other words, it seems that it can hurt you both as a trend follower (whipsaws), and as a mean reverting
indicator (as seen when XLB starts falling in the crisis), so this gives rise to the idea that an indicator can
track the price too well.

On the other hand, the 126 day FRAMA (the ETFHQ settings, in green) seems to look like a dynamic
support and resistance indicator that the talking heads go on and on about (yet give very little advice on how
to actually objectively compute), in that the price action seems to touch it every so often, but not oscillate
around it. It breaks in one direction and manages to stay in that direction, until it breaks in the other
direction, and sustain a move to that direction. This seems like a foundation of a future trading strategy.

Finally, the 252 day FRAMA (the ETFHQ settings for the long-term FRAMA indicator, in red) looks like a
confirmatory indicator or filter.

Notice that by comparison, the 126 day EMA seems to lag as much if not more than the 252 day FRAMA,
and from this vantage point, it seems that the results are not as good for the same amount of data processed.

Overall, it seems that by trading off smoothness and responsiveness, one can see the foundations of a
possible system.

The potential trading systems here will be explored in the future.

Thanks for reading.

Trend Vigor Part IV: Shorting and Walk


Forward Test
Posted on June 17, 2014 Posted in Dr. John Ehlers, ETFs, QuantStrat, R, Trading Tagged R 10
Comments

While Trend Vigor has potential on the long end (as seen in part III of this investigation here), as Andreas
Clenow has stated in his article Trend Following Does Not Work On Stocks, the short side of trend
following gets killed in equities. And, since by far and away most of the securities in this backtest were
equity-based ETFs (most of the ones available before 2003 were equity index ETFs), the results can
basically be summed up as buying insurance for Black Swans. On the plus side, Trend Vigor at very high
period settings (longer than 120) is able to capture some of the upside from being short in the depths of the
financial crisis, but unfortunately gives most of it back.

To begin, heres the code for this strategy, starting off at the previous settings of a period of 20 and delta 0
with ATR order sizing. The demo data has slightly changed in that the initialization, from, and to parameters
are now found in the demo scripts, rather than the file itself, which, as a result, is no longer a standalone file.

1 require(DSTrading)
require(IKTrading)
2
require(quantstrat)
3
4 initDate="1990-01-01"
5 from="2003-01-01"
6 to="2010-12-31"
7
8 #to rerun the strategy, rerun everything below this line
source("demoData.R") #contains all of the data-related boilerplate.
9
1 #trade sizing and initial equity settings
0 tradeSize <- -10000
initEq <- -tradeSize*length(symbols)
11
1 strategy.st <- portfolio.st <- account.st <- "TVI_short"
2 rm.strat(portfolio.st)
1 rm.strat(strategy.st)
3 initPortf(portfolio.st, symbols=symbols, initDate=initDate, currency='USD')
initAcct(account.st, portfolios=portfolio.st, initDate=initDate,
1 currency='USD',initEq=initEq)
4 initOrders(portfolio.st, initDate=initDate)
1 strategy(strategy.st, store=TRUE)
5
1 #parameters (trigger lag unchanged, defaulted at 1)
6 delta=0
period=20
1 pctATR=.02 #control risk with this parameter
7
1 #indicators
8 add.indicator(strategy.st, name="TVI", arguments=list(x=quote(Cl(mktdata)),
1 period=period, delta=delta), label="TVI")
9 add.indicator(strategy.st,
n=period), label="atrX")
name="lagATR", arguments=list(HLC=quote(HLC(mktdata)),
2
0 #signals
2 add.signal(strategy.st, name="sigThreshold",
1 arguments=list(threshold=-1, column="vigor.TVI", relationship="lte",
2 cross=FALSE),
label="TVIltThresh")
2 add.signal(strategy.st, name="sigComparison",
2 arguments=list(columns=c("vigor.TVI","trigger.TVI"), relationship="lt"),
3 label="TVIltLag")
2 add.signal(strategy.st, name="sigAND",
4 arguments=list(columns=c("TVIltThresh","TVIltLag"), cross=TRUE),
label="shortEntry")
2 add.signal(strategy.st, name="sigCrossover",
5 arguments=list(columns=c("vigor.TVI","trigger.TVI"), relationship="gt"),
2 label="shortExit")
6
2 #rules
7 add.rule(strategy.st, name="ruleSignal",
arguments=list(sigcol="shortEntry", sigval=TRUE, ordertype="market",
2 orderside="short", replace=FALSE, prefer="Open",
8 osFUN=osDollarATR,
2 tradeSize=tradeSize, pctATR=pctATR, atrMod="X"),
9 type="enter", path.dep=TRUE)
add.rule(strategy.st, name="ruleSignal",
3 arguments=list(sigcol="shortExit", sigval=TRUE, orderqty="all",
0 ordertype="market",
3 orderside="short", replace=FALSE, prefer="Open"),
1 type="exit", path.dep=TRUE)
3
2
3 #apply strategy
t1 <- Sys.time()
3 out <- applyStrategy(strategy=strategy.st,portfolios=portfolio.st)
3 t2 <- Sys.time()
4 print(t2-t1)
3
5
3
6
3
7
3
8
3
9
4
0
4
1
4
2
4
3
4
4
4
5
4
6
4
7
4
8
4
9
5
0
5
1
5
2
5
3
5
4
5
5
5
6
5
7
5
8
5
9
6
0
6
1
6
2
6
3

And here is the output:


1
> (aggPF <- sum(tStats$Gross.Profits)/-sum(tStats$Gross.Losses))
2 [1] 0.7088293
3 > (numTrades <- sum(tStats$Num.Trades))
4 [1] 947
5 > (aggCorrect <- sum(tStats$Num.Trades*tStats$Percent.Positive/100)/numTrades)
6 [1] 0.2734925
> (meanAvgWLR <- mean(tStats$Avg.WinLoss.Ratio))
7 [1] 2.073667
8

So, already, we can see that its pretty much a bloodbathnamely because throughout 2003 through 2010, the
general trend was upwards, and also, because of the use of constant ATR order sizing, when the moves are
largest (during the heightened volatility), our position size is smallest, relative to it. Which isnt to say that
this is a particularly bad idea considering that a short position can get whipsawed badly, but that such a
short-term detection system has no sense of the overall larger trend.

Here are some more portfolio statistics.

1
> SharpeRatio.annualized(portfRets)
2 [,1]
3 Annualized Sharpe Ratio (Rf=0%) -0.3647753
4 > Return.annualized(portfRets)
5 [,1]
6 Annualized Return -0.04075671
> maxDrawdown(portfRets)
7 [1] 0.3464871
8 >
9

In other words, this strategy simply costs you an annualized 4% a year, just to get the pop-up during the
financial crisis, and then proceed to give that all back to the market anyway. In other words, its a really silly
form of insurance, especially considering that due to the heightened volatility in times of extreme crisis, the
ATR order sizing function *already* functions as a massive hedge. For the sake of completeness, heres the
equity curve of this strategy.

And heres the usual equity curve of XLB.


Note that just when all the blood is in the water, the ATR order-sizing function actually works *against* the
strategy. This is due to the fact that with equities, that are bought in the expectation of price appreciation as
an investment (rather than, say, a commodity, whose prices need to fluctuate, and whose price appreciation
perhaps means adverse consequences outside of the investment universe, or an exchange rate, which is by
nature long in one instrument, short another, so may not be marked by severe volatility to the downside), and
thus, trends to the upside are more sustained, while moves to the downside happen much more quickly, and
by the time there is sufficient evidence (at any level of evidence) of a move to the downside, the largest
part of the move already happened, and its much more likely that a short trade would get whipsawed for a
loss.

If the other extreme is triedthat is, a more conservative delta parameter (.1), and a much larger period
(greater than 120 days, to attempt to implement this more as a filter, in this case, 140), these are the results:

1
> (aggPF <- sum(tStats$Gross.Profits)/-sum(tStats$Gross.Losses))
2 [1] 1.157702
3 > (numTrades <- sum(tStats$Num.Trades))
4 [1] 77
5 > (aggCorrect <- sum(tStats$Num.Trades*tStats$Percent.Positive/100)/numTrades)
6 [1] 0.4155857
> (meanAvgWLR <- mean(tStats$Avg.WinLoss.Ratio))
7 [1] NaN
8

The NaN means that one or more of the instruments had so few trades that there were no losers (most likely
1 or 2 trades that just so happened to get lucky), E.G. XLU had 1 trade.

Again, nothing worth writing home over. Even after I tried several different settings (for instance, if the delta
parameter is too high, most of the move to the downside in the crisis will be missed, and any profit will get
consumed by the recovery, and then some), when the best result barely breaks even in a once-in-a-lifetime
crisis, and so many other configurations either bite too easily on minor dips in an uptrend, or the converse,
are too afraid to enter even in a once-in-a-lifetime opportunity, its best to not even try to fit this square peg
into a round hole, and just not even think about trying Trend Vigor on the short end in equities.

For the record, heres the equity curve.


So even when the indicator gets the once-in-a-lifetime black swan opportunity, it still manages to do little
noteworthy. To put it into perspective, lets once again look at XLB.

Basically, enter late, exit late (meaning theres a lot of lag to this computation) on the filter end, and bite too
easily on the short-term trading end.

In other words, as a standalone indicator, Id be careful with it. Originally, this indicator was meant to be a
predictor of trending vs. cycling. And essentially, at least when it comes to equities, it fails miserably, taking
many trades it shouldnt in an environment that steadily grinds upwards. This makes me believe that in a
trend that grinds downwards, that a long strategy would be similarly disastrous. In short, in my opinion, the
Trend Vigor indicator fails its original stated purpose, which is to partition markets into
trending/cycling/trending downwards.

This all in mind, lets see what happened to our holdout datathat is, from 2011 onwards using the long-only
ATR position-sizing strategy through 2011 to present day (that is, the current date as of the time of this
writing, which is June 9th, 2014, or 2014-06-09).

Nothing spectacular, thats for certain. Here are the results:


Trade stats:

1 EFA EPP EWA EWC EWG


Num.Txns 31.00 39.00 37.00 27.00 29.00
2
Num.Trades 16.00 20.00 19.00 14.00 15.00
3 Net.Trading.PL 1006.37 -1067.24 -777.68 -239.11 1820.57
4 Avg.Trade.PL 62.90 -53.36 -40.93 -17.08 121.37
5 Med.Trade.PL -132.88 -71.38 -98.26 -332.33 -151.21
6 Largest.Winner 1434.98 1085.83 1678.21 1057.21 1517.68
Largest.Loser -1380.12 -1025.44 -1268.16 -953.35 -834.48
7 Gross.Profits 4939.32 4273.32 4932.19 4821.37 5546.32
8 Gross.Losses -3932.95 -5340.56 -5709.87 -5060.48 -3725.75
9 Std.Dev.Trade.PL 702.30 626.78 735.31 804.69 761.01
10 Percent.Positive 43.75 40.00 47.37 42.86 40.00
11 Percent.Negative 56.25 60.00 52.63 57.14 60.00
Profit.Factor 1.26 0.80 0.86 0.95 1.49
12 Avg.Win.Trade 705.62 534.16 548.02 803.56 924.39
13 Med.Win.Trade 720.56 533.59 363.94 874.10 889.67
14 Avg.Losing.Trade -436.99 -445.05 -570.99 -632.56 -413.97
15 Med.Losing.Trade -319.93 -297.21 -514.73 -625.85 -394.68
Avg.Daily.PL 13.16 -59.45 -50.63 -121.83 79.13
16 Med.Daily.PL -140.36 -80.61 -131.59 -429.16 -187.01
17 Std.Dev.Daily.PL 697.17 643.35 755.38 731.48 771.27
18 Ann.Sharpe 0.30 -1.47 -1.06 -2.64 1.63
19 Max.Drawdown -2826.18 -3230.34 -3731.81 -3230.98 -2594.95
20 Profit.To.Max.Draw 0.36 -0.33 -0.21 -0.07 0.70
Avg.WinLoss.Ratio 1.61 1.20 0.96 1.27 2.23
21 Med.WinLoss.Ratio 2.25 1.80 0.71 1.40 2.25
22 Max.Equity 2628.13 352.15 229.19 1555.99 3032.24
23 Min.Equity -1639.66 -2878.19 -3507.75 -1674.99 -1430.39
24 End.Equity 1006.37 -1067.24 -777.68 -239.11 1820.57
25
26 EWH EWJ EWS EWT EWU
Num.Txns 31.00 33.00 33.00 31.00 33.00
27 Num.Trades 15.00 17.00 17.00 16.00 17.00
28 Net.Trading.PL -230.79 -1209.81 -348.15 -2362.66 -2162.86
29 Avg.Trade.PL -15.39 -71.17 -20.48 -147.67 -127.23
30 Med.Trade.PL -178.21 -319.55 -199.30 -150.33 -76.03
Largest.Winner 2303.00 2887.37 1185.85 1179.33 1032.23
31 Largest.Loser -1069.43 -2169.74 -1076.99 -1795.83 -1195.97
32 Gross.Profits 5306.60 5403.59 4539.11 3425.73 3320.74
33 Gross.Losses -5537.39 -6613.40 -4887.26 -5788.39 -5483.60
34 Std.Dev.Trade.PL 963.23 1029.16 698.54 728.75 672.01
35 Percent.Positive 33.33 35.29 41.18 37.50 41.18
Percent.Negative 66.67 64.71 58.82 62.50 58.82
36 Profit.Factor 0.96 0.82 0.93 0.59 0.61
37 Avg.Win.Trade 1061.32 900.60 648.44 570.96 474.39
38 Med.Win.Trade 975.54 597.00 578.61 491.34 371.68
39 Avg.Losing.Trade -553.74 -601.22 -488.73 -578.84 -548.36
Med.Losing.Trade -491.03 -487.30 -489.20 -575.76 -426.36
40
Avg.Daily.PL -23.37 -130.20 -89.64 -179.67 -199.37
41 Med.Daily.PL -291.79 -321.44 -212.21 -153.16 -133.24
42 Std.Dev.Daily.PL 999.07 1032.75 658.59 742.60 622.35
43 Ann.Sharpe -0.37 -2.00 -2.16 -3.84 -5.09
44 Max.Drawdown -2594.56 -4926.69 -3641.30 -4719.71 -4105.55
Profit.To.Max.Draw -0.09 -0.25 -0.10 -0.50 -0.53
45 Avg.WinLoss.Ratio 1.92 1.50 1.33 0.99 0.87
46 Med.WinLoss.Ratio 1.99 1.23 1.18 0.85 0.87
47 Max.Equity 2143.41 2447.92 1925.63 928.36 915.55
48 Min.Equity -2540.25 -3809.54 -1715.67 -3791.36 -3190.00
49 End.Equity -230.79 -1209.81 -348.15 -2362.66 -2162.86
50
EWY EWZ EZU IEF IGE
51 Num.Txns 35.00 38.00 41.00 31.00 33.00
52 Num.Trades 18.00 19.00 21.00 16.00 17.00
53 Net.Trading.PL -2694.52 -2396.04 859.85 3933.39 1868.20
54 Avg.Trade.PL -149.70 -126.11 40.95 245.84 109.89
Med.Trade.PL 12.78 -286.33 14.46 51.79 40.66
55
Largest.Winner 583.36 809.58 1157.57 2216.26 1422.14
56 Largest.Loser -1506.45 -791.25 -658.35 -496.69 -1458.75
57 Gross.Profits 2579.07 2727.04 4061.44 6119.33 6139.07
58 Gross.Losses -5273.59 -5123.08 -3201.60 -2185.94 -4270.87
59 Std.Dev.Trade.PL 562.04 467.07 465.97 740.00 814.68
Percent.Positive 50.00 31.58 52.38 50.00 52.94
60 Percent.Negative 50.00 68.42 47.62 50.00 47.06
61 Profit.Factor 0.49 0.53 1.27 2.80 1.44
62 Avg.Win.Trade 286.56 454.51 369.22 764.92 682.12
63 Med.Win.Trade 262.99 453.56 221.78 549.08 426.84
64 Avg.Losing.Trade -585.95 -394.08 -320.16 -273.24 -533.86
Med.Losing.Trade -466.95 -354.64 -304.80 -286.43 -399.31
65 Avg.Daily.PL -164.86 -126.11 14.04 239.13 3.55
66 Med.Daily.PL -45.85 -286.33 -17.84 -3.45 -36.71
67 Std.Dev.Daily.PL 575.53 467.07 461.04 765.47 709.12
68 Ann.Sharpe -4.55 -4.29 0.48 4.96 0.08
Max.Drawdown -3796.28 -3435.45 -2154.32 -2166.31 -3368.63
69 Profit.To.Max.Draw -0.71 -0.70 0.40 1.82 0.55
70 Avg.WinLoss.Ratio 0.49 1.15 1.15 2.80 1.28
71 Med.WinLoss.Ratio 0.56 1.28 0.73 1.92 1.07
72 Max.Equity 738.72 180.61 1947.51 4512.77 1868.20
73 Min.Equity -3057.56 -3254.84 -1321.26 -576.85 -1540.72
End.Equity -2694.52 -2396.04 859.85 3933.39 1868.20
74
75 IYR IYZ LQD RWR SHY
76 Num.Txns 27.00 29.00 35.00 27.00 31.00
77 Num.Trades 14.00 15.00 17.00 14.00 16.00
78 Net.Trading.PL 3676.71 1141.84 3885.88 2503.47 2087.28
79 Avg.Trade.PL 262.62 76.12 228.58 178.82 130.46
Med.Trade.PL 216.71 59.28 140.49 167.95 83.51
80 Largest.Winner 1597.44 2165.96 813.01 1725.22 2018.03
81 Largest.Loser -1205.43 -1087.93 -880.30 -1435.08 -564.72
82 Gross.Profits 6179.06 5208.19 7516.04 6097.92 4069.39
83 Gross.Losses -2502.35 -4066.35 -3630.16 -3594.45 -1982.11
Std.Dev.Trade.PL 752.85 894.64 896.25 886.91 592.27
84 Percent.Positive 57.14 60.00 52.94 57.14 56.25
85 Percent.Negative 42.86 40.00 47.06 42.86 43.75
86 Profit.Factor 2.47 1.28 2.07 1.70 2.05
87 Avg.Win.Trade 772.38 578.69 835.12 762.24 452.15
88 Med.Win.Trade 694.95 319.46 673.49 454.00 281.30
Avg.Losing.Trade -417.06 -677.72 -453.77 -599.08 -283.16
89 Med.Losing.Trade -291.44 -694.92 -444.53 -435.46 -235.46
90 Avg.Daily.PL 198.73 77.33 59.12 96.11 111.87
91 Med.Daily.PL 94.41 32.47 -10.69 54.71 71.05
92 Std.Dev.Daily.PL 743.03 928.40 579.72 865.11 608.21
Ann.Sharpe 4.25 1.32 1.62 1.76 2.92
93
Max.Drawdown -3147.23 -3389.11 -2718.68 -3029.80 -1495.18
94 Profit.To.Max.Draw 1.17 0.34 1.43 0.83 1.40
95 Avg.WinLoss.Ratio 1.85 0.85 1.84 1.27 1.60
96 Med.WinLoss.Ratio 2.38 0.46 1.52 1.04 1.19
97 Max.Equity 4203.56 2147.66 4370.31 2604.67 2311.64
Min.Equity -651.36 -3389.11 -594.50 -1612.16 -776.36
98 End.Equity 3676.71 1141.84 3885.88 2503.47 2087.28
99
100 TLT XLB XLE XLF XLI
101 Num.Txns 27.00 35.00 25.00 27.00 31.00
102 Num.Trades 14.00 18.00 13.00 14.00 16.00
103 Net.Trading.PL 4188.91 1525.85 3015.76 3312.93 5243.37
Avg.Trade.PL 299.21 84.77 231.98 236.64 327.71
104 Med.Trade.PL -29.23 99.39 -25.64 47.93 139.79
105 Largest.Winner 3310.84 909.91 2265.85 1907.25 2116.29
106 Largest.Loser -829.51 -894.26 -1356.04 -652.95 -873.32
107 Gross.Profits 6548.35 4078.77 6369.44 5587.83 7236.98
Gross.Losses -2359.44 -2552.93 -3353.68 -2274.90 -1993.61
108 Std.Dev.Trade.PL 1025.04 460.16 1021.63 735.76 767.98
109 Percent.Positive 50.00 55.56 46.15 57.14 62.50
Percent.Negative 50.00 44.44 53.85 42.86 37.50
110
Profit.Factor 2.78 1.60 1.90 2.46 3.63
111 Avg.Win.Trade 935.48 407.88 1061.57 698.48 723.70
112 Med.Win.Trade 436.88 334.09 1028.27 607.54 565.35
113 Avg.Losing.Trade -337.06 -319.12 -479.10 -379.15 -332.27
114 Med.Losing.Trade -296.04 -262.59 -335.76 -367.86 -203.93
Avg.Daily.PL 257.88 43.28 108.37 212.17 300.65
115 Med.Daily.PL -77.71 94.92 -79.46 8.01 50.98
116 Std.Dev.Daily.PL 1054.69 438.26 960.17 759.85 787.00
117 Ann.Sharpe 3.88 1.57 1.79 4.43 6.06
118 Max.Drawdown -3113.33 -2417.02 -3108.53 -2224.39 -2732.59
119 Profit.To.Max.Draw 1.35 0.63 0.97 1.49 1.92
Avg.WinLoss.Ratio 2.78 1.28 2.22 1.84 2.18
120 Med.WinLoss.Ratio 1.48 1.27 3.06 1.65 2.77
121 Max.Equity 5888.75 1525.85 3093.03 3738.75 5376.79
122 Min.Equity -164.65 -1872.16 -225.30 -1541.00 -1030.57
123 End.Equity 4188.91 1525.85 3015.76 3312.93 5243.37
124
XLK XLP XLU XLV XLY
125 Num.Txns 23.00 35.00 28.00 29.00 29.00
126 Num.Trades 12.00 18.00 14.00 15.00 15.00
127 Net.Trading.PL 3958.91 4574.37 4589.84 9011.73 3926.53
128 Avg.Trade.PL 329.91 254.13 327.85 600.78 261.77
129 Med.Trade.PL 341.28 -96.61 6.57 292.17 100.86
Largest.Winner 1620.74 2992.30 2675.47 4335.47 1417.86
130 Largest.Loser -1651.62 -940.12 -720.35 -886.02 -1211.34
131 Gross.Profits 6146.50 7850.27 7382.03 10689.31 7051.77
132 Gross.Losses -2187.59 -3275.90 -2792.19 -1677.58 -3125.25
133 Std.Dev.Trade.PL 881.64 930.65 1015.70 1235.25 813.32
134 Percent.Positive 66.67 38.89 50.00 60.00 53.33
Percent.Negative 33.33 61.11 50.00 40.00 46.67
135 Profit.Factor 2.81 2.40 2.64 6.37 2.26
136 Avg.Win.Trade 768.31 1121.47 1054.58 1187.70 881.47
137 Med.Win.Trade 688.70 925.57 994.86 1188.08 980.24
138 Avg.Losing.Trade -546.90 -297.81 -398.88 -279.60 -446.46
Med.Losing.Trade -225.21 -263.58 -350.39 -232.60 -258.03
139 Avg.Daily.PL 272.88 172.49 327.85 615.92 221.10
140 Med.Daily.PL 226.83 -109.64 6.57 255.91 37.76
141 Std.Dev.Daily.PL 901.16 890.38 1015.70 1280.43 828.05
142 Ann.Sharpe 4.81 3.08 5.12 7.64 4.24
143 Max.Drawdown -3054.65 -2491.74 -1541.47 -2349.89 -2867.34
Profit.To.Max.Draw 1.30 1.84 2.98 3.83 1.37
144 Avg.WinLoss.Ratio 1.40 3.77 2.64 4.25 1.97
145 Med.WinLoss.Ratio 3.06 3.51 2.84 5.11 3.80
146 Max.Equity 4217.59 5106.00 5446.02 9151.52 4598.69
147 Min.Equity -1749.61 -1029.25 -898.16 -380.08 -1603.57
End.Equity 3958.91 4574.37 4589.84 9011.73 3926.53
148
149
> (aggPF <- sum(tStats$Gross.Profits)/-sum(tStats$Gross.Losses))
150 [1] 1.463801
151 > (aggCorrect <- mean(tStats$Percent.Positive))
152 [1] 48.769
153 > (numTrades <- sum(tStats$Num.Trades))
[1] 482
154 > (meanAvgWLR <- mean(tStats$Avg.WinLoss.Ratio))
155 [1] 1.749667
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

Overall, it still was profitable, but definitely not impressively so. For the first time, the 50% mark got
broken, which essentially contradicted the uniqueness of the indicator to begin with.

Here are the daily stats:

1 EFA EPP EWA EWC EWG


Total.Net.Profit 1006.37 -1067.24 -777.68 -239.11 1820.57
2
Total.Days 552.00 543.00 541.00 506.00 547.00
3 Winning.Days 298.00 277.00 271.00 268.00 289.00
4 Losing.Days 254.00 266.00 270.00 238.00 258.00
5 Avg.Day.PL 1.82 -1.97 -1.44 -0.47 3.33
6 Med.Day.PL 17.00 2.90 3.39 10.01 17.65
Largest.Winner 529.45 471.21 468.52 368.67 484.27
7 Largest.Loser -680.76 -725.06 -519.09 -545.42 -655.86
8 Gross.Profits 33513.80 30081.53 30541.36 24265.15 34491.17
9 Gross.Losses -32507.43 -31148.77 -31319.04 -24504.26 -32670.61
10 Std.Dev.Daily.PL 158.32 146.60 146.24 126.51 161.06
11 Percent.Positive 53.99 51.01 50.09 52.96 52.83
Percent.Negative 46.01 48.99 49.91 47.04 47.17
12 Profit.Factor 1.03 0.97 0.98 0.99 1.06
13 Avg.Win.Day 112.46 108.60 112.70 90.54 119.35
14 Med.Win.Day 97.46 89.05 94.25 74.00 97.54
15 Avg.Losing.Day -127.98 -117.10 -116.00 -102.96 -126.63
Med.Losing.Day -93.07 -91.19 -93.91 -84.12 -90.41
16 Avg.Daily.PL 1.82 -1.97 -1.44 -0.47 3.33
17 Med.Daily.PL 17.00 2.90 3.39 10.01 17.65
18 Std.Dev.Daily.PL.1 158.32 146.60 146.24 126.51 161.06
19 Ann.Sharpe 0.18 -0.21 -0.16 -0.06 0.33
20 Max.Drawdown -2826.18 -3230.34 -3731.81 -3230.98 -2594.95
Profit.To.Max.Draw 0.36 -0.33 -0.21 -0.07 0.70
21 Avg.WinLoss.Ratio 0.88 0.93 0.97 0.88 0.94
22 Med.WinLoss.Ratio 1.05 0.98 1.00 0.88 1.08
23 Max.Equity 2628.13 352.15 229.19 1555.99 3032.24
24 Min.Equity -1639.66 -2878.19 -3507.75 -1674.99 -1430.39
End.Equity 1006.37 -1067.24 -777.68 -239.11 1820.57
25
26 EWH EWJ EWS EWT EWU
Total.Net.Profit -230.79 -1209.81 -348.15 -2362.66 -2162.86
27
Total.Days 485.00 483.00 473.00 467.00 523.00
28 Winning.Days 250.00 257.00 241.00 230.00 267.00
29 Losing.Days 235.00 226.00 232.00 237.00 256.00
30 Avg.Day.PL -0.48 -2.50 -0.74 -5.06 -4.14
31 Med.Day.PL 7.87 18.54 10.40 -7.66 8.92
Largest.Winner 442.74 856.67 728.55 509.94 419.63
32 Largest.Loser -588.60 -1761.76 -1098.11 -612.79 -859.75
33 Gross.Profits 26844.49 34106.49 27148.71 25496.48 28167.12
34 Gross.Losses -27075.28 -35316.31 -27496.86 -27859.13 -30329.98
35 Std.Dev.Daily.PL 144.50 205.32 156.16 147.47 148.73
36 Percent.Positive 51.55 53.21 50.95 49.25 51.05
Percent.Negative 48.45 46.79 49.05 50.75 48.95
37 Profit.Factor 0.99 0.97 0.99 0.92 0.93
38 Avg.Win.Day 107.38 132.71 112.65 110.85 105.49
39 Med.Win.Day 84.03 116.20 83.22 89.79 88.48
40 Avg.Losing.Day -115.21 -156.27 -118.52 -117.55 -118.48
Med.Losing.Day -87.60 -120.69 -102.84 -89.96 -87.51
41 Avg.Daily.PL -0.48 -2.50 -0.74 -5.06 -4.14
42 Med.Daily.PL 7.87 18.54 10.40 -7.66 8.92
43 Std.Dev.Daily.PL.1 144.50 205.32 156.16 147.47 148.73
44 Ann.Sharpe -0.05 -0.19 -0.07 -0.54 -0.44
45 Max.Drawdown -2594.56 -4926.69 -3641.30 -4719.71 -4105.55
Profit.To.Max.Draw -0.09 -0.25 -0.10 -0.50 -0.53
46 Avg.WinLoss.Ratio 0.93 0.85 0.95 0.94 0.89
47 Med.WinLoss.Ratio 0.96 0.96 0.81 1.00 1.01
48 Max.Equity 2143.41 2447.92 1925.63 928.36 915.55
49 Min.Equity -2540.25 -3809.54 -1715.67 -3791.36 -3190.00
50 End.Equity -230.79 -1209.81 -348.15 -2362.66 -2162.86
51
EWY EWZ EZU IEF IGE
52 Total.Net.Profit -2694.52 -2396.04 859.85 3933.39 1868.20
53 Total.Days 462.00 414.00 522.00 550.00 511.00
54 Winning.Days 234.00 191.00 272.00 301.00 266.00
55 Losing.Days 228.00 223.00 250.00 249.00 245.00
Avg.Day.PL -5.83 -5.79 1.65 7.15 3.66
56 Med.Day.PL 2.90 -12.33 13.44 17.64 8.26
57 Largest.Winner 623.44 473.66 535.69 557.51 498.52
58 Largest.Loser -770.87 -395.63 -693.00 -532.96 -700.75
59 Gross.Profits 25858.43 18710.54 30720.38 34230.37 30004.54
60 Gross.Losses -28552.95 -21106.58 -29860.53 -30296.98 -28136.35
Std.Dev.Daily.PL 154.74 123.77 154.44 150.09 148.66
61 Percent.Positive 50.65 46.14 52.11 54.73 52.05
62 Percent.Negative 49.35 53.86 47.89 45.27 47.95
63 Profit.Factor 0.91 0.89 1.03 1.13 1.07
64 Avg.Win.Day 110.51 97.96 112.94 113.72 112.80
Med.Win.Day 85.46 78.98 91.36 95.75 94.04
65
Avg.Losing.Day -125.23 -94.65 -119.44 -121.67 -114.84
66 Med.Losing.Day -99.45 -75.00 -85.26 -96.03 -93.28
67 Avg.Daily.PL -5.83 -5.79 1.65 7.15 3.66
68 Med.Daily.PL 2.90 -12.33 13.44 17.64 8.26
69 Std.Dev.Daily.PL.1 154.74 123.77 154.44 150.09 148.66
Ann.Sharpe -0.60 -0.74 0.17 0.76 0.39
70 Max.Drawdown -3796.28 -3435.45 -2154.32 -2166.31 -3368.63
71 Profit.To.Max.Draw -0.71 -0.70 0.40 1.82 0.55
72 Avg.WinLoss.Ratio 0.88 1.03 0.95 0.93 0.98
73 Med.WinLoss.Ratio 0.86 1.05 1.07 1.00 1.01
74 Max.Equity 738.72 180.61 1947.51 4512.77 1868.20
Min.Equity -3057.56 -3254.84 -1321.26 -576.85 -1540.72
75 End.Equity -2694.52 -2396.04 859.85 3933.39 1868.20
76
77 IYR IYZ LQD RWR SHY
78 Total.Net.Profit 3676.71 1141.84 3885.88 2503.47 2087.28
79 Total.Days 585.00 529.00 608.00 582.00 481.00
Winning.Days 318.00 280.00 330.00 317.00 268.00
80 Losing.Days 267.00 249.00 278.00 265.00 213.00
Avg.Day.PL 6.28 2.16 6.39 4.30 4.34
81
Med.Day.PL 13.80 11.00 13.47 15.00 32.73
82 Largest.Winner 337.12 656.22 500.32 373.09 317.45
83 Largest.Loser -553.69 -486.69 -917.90 -653.56 -379.80
84 Gross.Profits 29882.84 30424.77 34069.25 30740.26 24931.27
85 Gross.Losses -26206.13 -29282.93 -30183.37 -28236.79 -22843.99
Std.Dev.Daily.PL 126.57 148.05 141.44 133.93 118.12
86 Percent.Positive 54.36 52.93 54.28 54.47 55.72
87 Percent.Negative 45.64 47.07 45.72 45.53 44.28
88 Profit.Factor 1.14 1.04 1.13 1.09 1.09
89 Avg.Win.Day 93.97 108.66 103.24 96.97 93.03
90 Med.Win.Day 75.05 86.40 88.16 80.63 76.66
Avg.Losing.Day -98.15 -117.60 -108.57 -106.55 -107.25
91 Med.Losing.Day -76.33 -91.42 -79.49 -79.00 -84.65
92 Avg.Daily.PL 6.28 2.16 6.39 4.30 4.34
93 Med.Daily.PL 13.80 11.00 13.47 15.00 32.73
94 Std.Dev.Daily.PL.1 126.57 148.05 141.44 133.93 118.12
Ann.Sharpe 0.79 0.23 0.72 0.51 0.58
95 Max.Drawdown -3147.23 -3389.11 -2718.68 -3029.80 -1495.18
96 Profit.To.Max.Draw 1.17 0.34 1.43 0.83 1.40
97 Avg.WinLoss.Ratio 0.96 0.92 0.95 0.91 0.87
98 Med.WinLoss.Ratio 0.98 0.95 1.11 1.02 0.91
99 Max.Equity 4203.56 2147.66 4370.31 2604.67 2311.64
Min.Equity -651.36 -3389.11 -594.50 -1612.16 -776.36
100 End.Equity 3676.71 1141.84 3885.88 2503.47 2087.28
101
102 TLT XLB XLE XLF XLI
103 Total.Net.Profit 4188.91 1525.85 3015.76 3312.93 5243.37
104 Total.Days 471.00 542.00 558.00 558.00 610.00
105 Winning.Days 249.00 284.00 287.00 296.00 340.00
Losing.Days 222.00 258.00 271.00 262.00 270.00
106 Avg.Day.PL 8.89 2.82 5.40 5.94 8.60
107 Med.Day.PL 11.18 8.22 6.80 9.76 17.38
108 Largest.Winner 862.40 403.44 588.27 479.24 546.63
109 Largest.Loser -1060.30 -512.20 -714.31 -517.42 -683.29
Gross.Profits 35487.37 29115.38 32217.78 30912.49 35259.17
110 Gross.Losses -31298.46 -27589.53 -29202.02 -27599.56 -30015.80
111 Std.Dev.Daily.PL 196.23 133.68 149.57 138.38 140.46
112 Percent.Positive 52.87 52.40 51.43 53.05 55.74
113 Percent.Negative 47.13 47.60 48.57 46.95 44.26
114 Profit.Factor 1.13 1.06 1.10 1.12 1.17
Avg.Win.Day 142.52 102.52 112.26 104.43 103.70
115 Med.Win.Day 102.88 87.66 92.71 78.10 83.42
116 Avg.Losing.Day -140.98 -106.94 -107.76 -105.34 -111.17
117 Med.Losing.Day -109.53 -80.39 -75.03 -79.98 -86.96
118 Avg.Daily.PL 8.89 2.82 5.40 5.94 8.60
Med.Daily.PL 11.18 8.22 6.80 9.76 17.38
119
Std.Dev.Daily.PL.1 196.23 133.68 149.57 138.38 140.46
120 Ann.Sharpe 0.72 0.33 0.57 0.68 0.97
121 Max.Drawdown -3113.33 -2417.02 -3108.53 -2224.39 -2732.59
122 Profit.To.Max.Draw 1.35 0.63 0.97 1.49 1.92
123 Avg.WinLoss.Ratio 1.01 0.96 1.04 0.99 0.93
Med.WinLoss.Ratio 0.94 1.09 1.24 0.98 0.96
124 Max.Equity 5888.75 1525.85 3093.03 3738.75 5376.79
125 Min.Equity -164.65 -1872.16 -225.30 -1541.00 -1030.57
126 End.Equity 4188.91 1525.85 3015.76 3312.93 5243.37
127
128 XLK XLP XLU XLV XLY
129 Total.Net.Profit 3958.91 4574.37 4589.84 9011.73 3926.53
Total.Days 602.00 626.00 601.00 654.00 630.00
130 Winning.Days 330.00 336.00 327.00 364.00 336.00
131 Losing.Days 272.00 290.00 274.00 290.00 294.00
132 Avg.Day.PL 6.58 7.31 7.64 13.78 6.23
133 Med.Day.PL 16.15 13.40 19.19 16.24 14.51
Largest.Winner 499.03 497.92 355.08 621.11 421.68
134 Largest.Loser -683.59 -531.11 -428.09 -537.68 -741.65
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152 Gross.Profits 34611.16 36209.36 33101.33 41438.23 34800.70
Gross.Losses -30652.25 -31634.99 -28511.49 -32426.50 -30874.17
153 Std.Dev.Daily.PL 145.31 141.74 129.06 150.70 138.44
154 Percent.Positive 54.82 53.67 54.41 55.66 53.33
155 Percent.Negative 45.18 46.33 45.59 44.34 46.67
156 Profit.Factor 1.13 1.14 1.16 1.28 1.13
Avg.Win.Day 104.88 107.77 101.23 113.84 103.57
157 Med.Win.Day 83.12 85.88 81.77 88.52 82.08
158 Avg.Losing.Day -112.69 -109.09 -104.06 -111.82 -105.01
159 Med.Losing.Day -83.28 -79.67 -81.43 -78.85 -73.23
160 Avg.Daily.PL 6.58 7.31 7.64 13.78 6.23
161 Med.Daily.PL 16.15 13.40 19.19 16.24 14.51
Std.Dev.Daily.PL.1 145.31 141.74 129.06 150.70 138.44
162 Ann.Sharpe 0.72 0.82 0.94 1.45 0.71
163 Max.Drawdown -3054.65 -2491.74 -1541.47 -2349.89 -2867.34
164 Profit.To.Max.Draw 1.30 1.84 2.98 3.83 1.37
165 Avg.WinLoss.Ratio 0.93 0.99 0.97 1.02 0.99
Med.WinLoss.Ratio 1.00 1.08 1.00 1.12 1.12
166
Max.Equity 4217.59 5106.00 5446.02 9151.52 4598.69
167 Min.Equity -1749.61 -1029.25 -898.16 -380.08 -1603.57
168 End.Equity 3958.91 4574.37 4589.84 9011.73 3926.53
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

Basically, it seems that while the domestic side of equities seemed to do fairly well, the international side of
the trade really hurt. For once, the perils of diversification are apparent. Here are the portfolio statistics:
1
> SharpeRatio.annualized(portfRets)
2 [,1]
3 Annualized Sharpe Ratio (Rf=0%) 0.4074399
4 > Return.annualized(portfRets)
5 [,1]
Annualized Return 0.04448638
6
> maxDrawdown(portfRets)
7 [1] 0.1439702
8

So, ho-hum annualized returns, but the Sharpe Ratio at this point is far from stellar, and the drawdowns are
definitely disappointing. Here is the resultant equity curve comparison.

In other words, it kept pace with the S&P 500 up until the beginning of 2013 (when in fact, their
performance was just about equal), with less violent (but longer-lasting) drawdowns. Unfortunately, starting
in mid-2013, the S&P 500 roared away, while the strategy just seemed to be flat, at the new equity high. This
would probably anger quite a few investors. Lets check out an equity curve from a losing security and see
what happened.

1 #Individual instrument equity curve


2 chart.Posn(portfolio.st, "EWJ")
3 tmp <- TVI(Cl(EWJ), period=period, delta=delta, triggerLag=1)
4 add_TA(tmp$vigor, lwd=3)
5 add_TA(tmp$trigger, on=5, col="red", lwd=1.5)
tmp2 <- lagATR(HLC=HLC(EWJ), n=period)
6 add_TA(tmp2$atr, col="blue", lwd=2)
7
In short, Trend Vigor as an entry indicator seems to be like the rest of the usual trend following indicators.
Susceptible to buying tops and getting caught in cycles, gives back open equity (see that long trade in 2012-
2013), takes counter-trend trades, but essentially at the price of incorporating a bunch of mathematics far
more complex than the usual SMAs and EMAs, and at best, to marginally better results.

So does this mean that there was absolutely nothing to take away from this?

Well, no. Trend Vigor is something that can be added to a repertoire of indicators. Unlike the usual SMA and
EMA fare, the advantage that Trend Vigor has is that over longer time horizons, assuming gradual trends (as
opposed to the steep drops in things such as equities), is that it still can get things right more often than not,
and when it does, the average win to loss profile is usually impressive. However, a marginal improvement
over the basics isnt what trend vigor was originally advertised to be, so much as a reliable market mode
indicator. And in a trending environment, even your basic SMA crossovers will make money. In an
oscillating environment, even the most basic RSI plug-and-chug will make money. The key, of course, is to
try and find an indicator that will tell you what to deploy when. And for that purpose, unlike what was
advertised in the original John Ehlers presentation, Trend Vigor, as far as this investigation has led me, is
*not* that.

Thanks for reading.

Trend Vigor Part III: ATR position sizing,


Annualized Sharpe above 1.4, and Why Leverage
Is Pointless
Posted on June 11, 2014 Posted in Dr. John Ehlers, ETFs, QuantStrat, R, Trading Tagged R 14
Comments

To continue the investigation of Trend Vigor (see part 1 here, and part 2 here), lets examine the importance
of position sizing. Also, this post will show the way to obtain this equity curve:
Before starting this post, I would like to defer to an authority in terms of the importance of position sizing.
That would be one Andreas Clenow, author of an extremely highly-rated book about trend-following. Heres
his post: Why Leverage Is Pointless

Now before starting the main thrust of this post, Id like to make a quick comparison regarding the 30 ETFs
I selected for this demonamely, their inter-instrument correlations.

1
2
tmp <- list()
3 length(tmp) <- length(symbols)
4 for (i in 1:length(symbols)) {
5 tmp[[i]] <-Cl(get(symbols[i]))
6 }
tmp <- do.call(cbind, tmp)
7 baseCors <- cor(tmp)
8 diag(baseCors) <- NA
9 instrumentAverageBaseCors <- rowMeans(baseCors, na.rm=TRUE)
1 names(instrumentAverageBaseCors) <- gsub(".Close", "",
0 names(instrumentAverageBaseCors))
instrumentAverageBaseCors
11(grandMeanBaseCors <- mean(instrumentAverageBaseCors))
1
2
1
2
3
> instrumentAverageBaseCors
4 XLB XLE XLF XLP XLI XLU XLV
5 0.8208166 0.7872692 0.2157401 0.7618719 0.7882733 0.8049700 0.7487639
6 XLK XLY RWR EWJ EWG EWU EWC
7 0.7785739 0.5912142 0.7055041 0.6665144 0.8112501 0.7735207 0.8159072
EWY EWA EWH EWS IYZ EZU IYR
8 0.8231610 0.8234274 0.8022086 0.7971305 0.6875318 0.7669643 0.6894201
9 EWT EWZ EFA IGE EPP LQD SHY
1 0.7746172 0.7227011 0.8047205 0.8034852 0.8274662 0.5552580 0.4339562
0 IEF TLT
11 0.3954464 0.3863955
> (grandMeanBaseCors <- mean(instrumentAverageBaseCors))
1 [1] 0.7054693
2
1
3
In other words, pretty ugly. All sorts of ugly, but I suppose this is what happens when limiting the choices to
ETFs in inception since 2003. So remember that number. A correlation north of .70 on average among all the
instruments.

Now, onto the main thrust of the topic of this post:

In the previous post, we saw that some highly successful instruments, when analyzed at their own scale,
such as SHY (the short term bonds ETF), had spectacular performances. However, in the grand scheme of
things, due to identical notional risk allocation, the fact that SHY itself just didnt move as much as, say, the
SPDR sector ETFs meant that its performance could not make as much of an impact in the portfolio
performance. This implication meant that despite having 30 instruments in the portfolio, not only were the
base instruments highly correlated (quandl futures data algorithm coming sometime in the future!), but
beyond that, the performance was dominated by the most volatile among them. This is clearly undesirable,
and with most trading information in the public domain looking at a trading system as just a set of
indicators, signals, and rules on one instrument at a time, there is very little emphasis placed on relative
position sizing, with the occasional thoughtful writer saying my order size is based on dividing some
notional amount by some ATR, and leaving it at that.

How important is that one little detail? As Andreas Clenow has pointed out in his post, it is extremely
important, and in many cases, far more important than a couple of simplistic rules.

The approach I take is rooted in futures trading. In futures trading, due to the discontinuous nature of
contracts, in order to formulate a backtest, quants/engineers/traders/whoever have to create a continuous
contract, going back in time, and have to find some way to smooth over those price discontinuities between
the two contracts they roll between at any point in time. More often than not, these changes add up quickly,
and so, any computation that was sensitive to the addition of a scalar quantity was instantly off the table (this
means that anything depending on percentage changes in price? Gone). One solution to this is the Average
True Range, which not only succeeds in this regard, but also isnt penalized by directional volatility, like
standard deviation in a trend (consider a monotonically rising pricea moving average across that time
period would constantly lag the current quantity, and a standard deviation would consistently punish that
divergence). Furthermore, if I have not yet stated it already, the ATR has a very important interpretation for
position sizing:

Its a measure of the actual dollar movement of the security.

What does this mean? It means that rather that rather than ordering a notional quantity of the security, the
trading system can instead order a specific level of *risk*, regardless of the notional price. This allows a
trading system simulation to *force* equal risk contributions from all securities involved in the system. My
implementation of this idea (found in my IKTrading package, see my about page for my github link) grew
into a little bit of a Swiss army knife to include maximum position sizing, and a rebalancing feature.

Heres the function, along with a necessary sister function:

1 "lagATR" <- function(HLC, n=14, maType, lag=1, ...) {


ATR <- ATR(HLC, n=n, maType=maType, ...)
2
ATR <- lag(ATR, lag)
3 out <- ATR$atr
4 colnames(out) <- "atr"
5 return(out)
6 }
7
"osDollarATR" <- function(orderside, tradeSize, pctATR, maxPctATR=pctATR, data,
8 timestamp, symbol,
9 prefer="Open", portfolio, integerQty=TRUE, atrMod="",
1 rebal=FALSE, ...) {
0 if(tradeSize > 0 & orderside == "short"){
11 tradeSize <- tradeSize*-1
}
1 pos <- getPosQty(portfolio, symbol, timestamp)
atrString <- paste0("atr",atrMod)
2
atrCol <- grep(atrString, colnames(mktdata))
1 if(length(atrCol)==0) {
3 stop(paste("Term", atrString, "not found in mktdata column names."))
1 }
4 atrTimeStamp <- mktdata[timestamp, atrCol]
if(is.na(atrTimeStamp) | atrTimeStamp==0) {
1 stop(paste("ATR corresponding to",atrString,"is invalid at this point in time.
5 Add a logical operator to account for this."))
1 }
6 dollarATR <- pos*atrTimeStamp
1 desiredDollarATR <- pctATR*tradeSize
remainingRiskCapacity <- tradeSize*maxPctATR-dollarATR
7
1 if(orderside == "long"){
8 qty <- min(tradeSize*pctATR/atrTimeStamp, remainingRiskCapacity/atrTimeStamp)
1 } else {
9 qty <- max(tradeSize*pctATR/atrTimeStamp, remainingRiskCapacity/atrTimeStamp)
}
2
0
if(integerQty) {
2 qty <- trunc(qty)
1 }
2 if(!rebal) {
2 if(orderside == "long" & qty < 0) {
qty <- 0
2 }
3 if(orderside == "short" & qty > 0) {
2 qty <- 0
4 }
2 }
if(rebal) {
5 if(pos == 0) {
2 qty <- 0
6 }
2 }
return(qty)
7
}
2
8
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
4
0
4
1
4
2
4
3
4
4
4
5
4
6
4
7
4
8
4
9
5
0
5
1
5
2

To get it out of the way, the lagATR function exists to, as its name says, lag the ATR computation, in order to
prevent look-ahead bias. After all, you cannot buy the open using an ATR value computed at the close of that
same day.

Now, moving onto the actual osDollarATR function, the way it works is like this: it has the user specify a
notional trade size (tradeSize), that is, a notional dollar amount, and then the risk level the user would like
on that notional dollar amount (pctATR). And heres where it gets funby multiplying the notional dollar
amount by the percentage ATR, it allows the strategy to basically buy units of ATR. Beyond this, for
strategies that scale in, pyramid, dollar-cost-average, or otherwise stack up positions, there is functionality to
cap the risk, along with a feature that would check if the maximum risk level had been breached, and to pare
down (not featured in this demonstration). Essentially, inherent in this conversion from dollars to ATR is an
implicit variable leverage factor. That is, consider a security A that had an ATR for a given period of $2, that
was priced for $50. Now consider another security B that was priced at $100 with an ATR for the same
period of $1. If you wished to risk a notional 2% of $10,000 (that is, $200 worth of ATR), youd only need
100 units of security A, essentially staying 50% in cash for that transaction, while for security B, youd
actually leverage 2:1 in order to purchase 200 units, even if you lack the notional capital. Obviously, since
this is a computer, the function is assuming that you can actually *obtain* the proper leverage to properly
position-size. But beyond that, this function inherently embodies the idea of showing why leverage is
pointless.

The strategy is identical to the previous posts, using the same TVI(20,0) indicator (or if you want, (20,0,1),
if you take into account the triggerLag parameter), with one key difference: rather than using the equal
dollar weight order-sizing function, I will instead use this new ATR order sizing function.

Heres the code:

1 require(DSTrading)
require(IKTrading)
2 require(quantstrat)
3
4 initDate="1990-01-01"
from="2003-01-01"
5 to="2010-12-31"
6
7 #to rerun the strategy, rerun everything below this line
8 source("demoData.R") #contains all of the data-related boilerplate.
9
1 #trade sizing and initial equity settings
tradeSize <- 10000
0 initEq <- tradeSize*length(symbols)
11
1 strategy.st <- portfolio.st <- account.st <- "TVI_osATR"
2 rm.strat(portfolio.st)
1 rm.strat(strategy.st)
3 initPortf(portfolio.st, symbols=symbols, initDate=initDate, currency='USD')
initAcct(account.st, portfolios=portfolio.st, initDate=initDate,
1 currency='USD',initEq=initEq)
4 initOrders(portfolio.st, initDate=initDate)
1 strategy(strategy.st, store=TRUE)
5
1 #parameters (trigger lag unchanged, defaulted at 1)
6 delta=0
period=20
1 pctATR=.02 #control risk with this parameter
7
1 #indicators
8 add.indicator(strategy.st, name="TVI", arguments=list(x=quote(Cl(mktdata)),
1 period=period, delta=delta), label="TVI")
add.indicator(strategy.st, name="lagATR", arguments=list(HLC=quote(HLC(mktdata)),
9 n=period), label="atrX")
2
0 #signals
2 add.signal(strategy.st, name="sigThreshold",
1 arguments=list(threshold=1, column="vigor.TVI", relationship="gte",
2 cross=FALSE),
label="TVIgtThresh")
2 add.signal(strategy.st, name="sigComparison",
2 arguments=list(columns=c("vigor.TVI","trigger.TVI"), relationship="gt"),
3 label="TVIgtLag")
2 add.signal(strategy.st, name="sigAND",
arguments=list(columns=c("TVIgtThresh","TVIgtLag"), cross=TRUE),
4 label="longEntry")
2 add.signal(strategy.st, name="sigCrossover",
5 arguments=list(columns=c("vigor.TVI","trigger.TVI"), relationship="lt"),
2 label="longExit")
6
2 #rules
add.rule(strategy.st, name="ruleSignal",
7 arguments=list(sigcol="longEntry", sigval=TRUE, ordertype="market",
2 orderside="long", replace=FALSE, prefer="Open",
8 osFUN=osDollarATR,
2 tradeSize=tradeSize, pctATR=pctATR, atrMod="X"),
type="enter", path.dep=TRUE)
9
add.rule(strategy.st, name="ruleSignal",
3 arguments=list(sigcol="longExit", sigval=TRUE, orderqty="all",
0 ordertype="market",
3 orderside="long", replace=FALSE, prefer="Open"),
1 type="exit", path.dep=TRUE)
3
2
3 #apply strategy
t1 <- Sys.time()
3 out <- applyStrategy(strategy=strategy.st,portfolios=portfolio.st)
3 t2 <- Sys.time()
print(t2-t1)
4
3
5
#set up analytics
3 updatePortf(portfolio.st)
6 dateRange <- time(getPortfolio(portfolio.st)$summary)[-1]
3 updateAcct(portfolio.st,dateRange)
7 updateEndEq(account.st)
3
8
3
9
4
0
4
1
4
2
4
3
4
4
4
5
4
6
4
7
4
8
4
9
5
0
5
1
5
2
5
3
5
4
5
5
5
6
5
7
5
8
5
9
6
0
6
1
6
2
6
3
6
4
6
5
6
6
6
7
6
8
6
9
7
0

Notice the addition of the new indicator (using an ATR period tied to the TVI period of 20), and the
modified entry rule. Also, a small detail is the atrMod string modifier. This modifies the string atr, by
appending the modifier to the end of it. While it looks superfluous at first, the reason for this addition is in
case the user wishes to make use of multiple atr indicators, and thereby allowing the order sizing function to
locate the appropriate column. Also note that the label on the indicator has to be the term atr and then the
modifier. If this seems slightly kludge-y, Im open for any suggestions.

One other thing to notethe computation for the ATR order stream should have valid values before the first
order signal fires, or it will not work. That is, consider a system that, for arguments sake, has a 20-day
period to compute its indicator (such as TVI(20,0)), but a 100-day ATR computation. At the beginning of the
data, it could very well be the case that there is not yet a valid value for the ATR computation, and therefore,
a valid order quantity cannot be returned.

So, those two notes about using this function dealt with, lets move onto the results.

Here are the trade stats:

1
#tradeStats
2 tStats <- tradeStats(Portfolios = portfolio.st, use="trades", inclZeroDays=FALSE)
3 tStats[,4:ncol(tStats)] <- round(tStats[,4:ncol(tStats)], 2)
4 print(data.frame(t(tStats[,-c(1,2)])))
5 (aggPF <- sum(tStats$Gross.Profits)/-sum(tStats$Gross.Losses))
(aggCorrect <- mean(tStats$Percent.Positive))
6
(numTrades <- sum(tStats$Num.Trades))
7 (meanAvgWLR <- mean(tStats$Avg.WinLoss.Ratio))
8
1 EFA EPP EWA EWC EWG
Num.Txns 63.00 63.00 57.00 67.00 59.00
2
Num.Trades 32.00 32.00 29.00 34.00 30.00
3 Net.Trading.PL 15389.57 15578.88 16204.18 11846.58 12646.07
4 Avg.Trade.PL 480.92 486.84 558.76 348.43 421.54
5 Med.Trade.PL 185.67 179.37 275.26 -13.31 -15.89
6 Largest.Winner 2440.60 3542.54 3609.82 3040.75 2875.15
Largest.Loser -840.30 -1190.45 -937.03 -1199.78 -912.56
7 Gross.Profits 20142.82 20037.94 20434.89 19120.45 18349.74
8 Gross.Losses -4753.25 -4459.05 -4230.71 -7273.88 -5703.66
9 Std.Dev.Trade.PL 953.83 1055.36 1191.82 1022.49 1097.44
10 Percent.Positive 65.62 59.38 58.62 50.00 43.33
Percent.Negative 34.38 40.62 41.38 50.00 56.67
11 Profit.Factor 4.24 4.49 4.83 2.63 3.22
Avg.Win.Trade 959.18 1054.63 1202.05 1124.73 1411.52
12
Med.Win.Trade 902.74 722.86 592.03 1075.71 1042.79
13 Avg.Losing.Trade -432.11 -343.00 -352.56 -427.88 -335.51
14 Med.Losing.Trade -450.96 -231.60 -284.15 -377.76 -346.90
15 Avg.Daily.PL 489.72 495.27 565.90 314.01 438.00
16 Med.Daily.PL 163.09 133.15 243.61 -56.13 -14.28
Std.Dev.Daily.PL 968.28 1071.71 1213.06 1018.14 1113.09
17 Ann.Sharpe 8.03 7.34 7.41 4.90 6.25
18 Max.Drawdown -2338.43 -2430.09 -2168.66 -2982.50 -2904.73
19 Profit.To.Max.Draw 6.58 6.41 7.47 3.97 4.35
20 Avg.WinLoss.Ratio 2.22 3.07 3.41 2.63 4.21
21 Med.WinLoss.Ratio 2.00 3.12 2.08 2.85 3.01
Max.Equity 15968.41 16789.50 17435.72 13048.24 13773.99
22 Min.Equity -17.93 -188.46 0.00 -393.45 -100.42
23 End.Equity 15389.57 15578.88 16204.18 11846.58 12646.07
24
25 EWH EWJ EWS EWT EWU
26 Num.Txns 57.00 69.00 53.00 61.00 55.00
Num.Trades 29.00 34.00 27.00 31.00 27.00
27 Net.Trading.PL 12085.74 7457.81 13356.23 6906.24 7492.71
28 Avg.Trade.PL 416.75 219.35 494.68 222.78 277.51
29 Med.Trade.PL 192.70 -34.71 425.41 -52.39 87.70
30 Largest.Winner 2924.25 2586.20 3268.76 1965.93 2715.28
31 Largest.Loser -1552.50 -854.08 -631.60 -1052.89 -999.50
Gross.Profits 16111.39 12289.56 15881.04 13110.95 12459.02
32 Gross.Losses -4025.66 -4831.75 -2524.81 -6204.71 -4966.31
33 Std.Dev.Trade.PL 925.26 736.30 848.37 883.21 872.02
34 Percent.Positive 68.97 47.06 70.37 48.39 59.26
35 Percent.Negative 31.03 52.94 29.63 51.61 40.74
36 Profit.Factor 4.00 2.54 6.29 2.11 2.51
Avg.Win.Trade 805.57 768.10 835.84 874.06 778.69
37 Med.Win.Trade 465.57 571.09 576.83 517.53 542.01
38 Avg.Losing.Trade -447.30 -268.43 -315.60 -387.79 -451.48
39 Med.Losing.Trade -413.37 -206.93 -338.84 -322.41 -433.08
40 Avg.Daily.PL 434.15 169.87 504.61 129.14 284.11
Med.Daily.PL 201.67 -36.02 430.95 -54.67 72.31
41 Std.Dev.Daily.PL 937.40 687.94 863.57 725.09 888.60
42 Ann.Sharpe 7.35 3.92 9.28 2.83 5.08
43 Max.Drawdown -2229.93 -4036.69 -2021.12 -3147.85 -2599.57
44 Profit.To.Max.Draw 5.42 1.85 6.61 2.19 2.88
45 Avg.WinLoss.Ratio 1.80 2.86 2.65 2.25 1.72
Med.WinLoss.Ratio 1.13 2.76 1.70 1.61 1.25
46 Max.Equity 13043.23 8395.92 14415.11 6906.24 9160.15
47 Min.Equity -33.87 -274.69 -699.37 -788.28 -327.38
48 End.Equity 12085.74 7457.81 13356.23 6906.24 7492.71
49
50 EWY EWZ EZU IEF IGE
Num.Txns 63.00 65.00 57.00 62.00 67.00
51
Num.Trades 32.00 33.00 29.00 31.00 34.00
52 Net.Trading.PL 9736.49 16814.33 13135.27 17932.39 13435.41
53 Avg.Trade.PL 304.27 509.53 452.94 578.46 395.16
54 Med.Trade.PL 61.08 295.06 94.54 362.74 32.80
55 Largest.Winner 2278.76 2821.49 2805.66 4412.27 2955.08
Largest.Loser -915.90 -1170.96 -1222.74 -836.09 -763.29
56 Gross.Profits 14597.54 22199.95 18539.53 21651.92 18691.32
57 Gross.Losses -4861.05 -5385.61 -5404.25 -3719.52 -5255.91
58 Std.Dev.Trade.PL 815.28 1006.45 1097.26 1097.78 984.69
59 Percent.Positive 53.12 57.58 55.17 70.97 52.94
60 Percent.Negative 46.88 42.42 44.83 29.03 47.06
Profit.Factor 3.00 4.12 3.43 5.82 3.56
61 Avg.Win.Trade 858.68 1168.42 1158.72 984.18 1038.41
62 Med.Win.Trade 617.31 1071.08 1068.20 552.55 708.61
63 Avg.Losing.Trade -324.07 -384.69 -415.71 -413.28 -328.49
64 Med.Losing.Trade -293.26 -391.20 -339.56 -420.83 -303.28
Avg.Daily.PL 296.04 510.77 465.74 578.46 324.22
65 Med.Daily.PL 8.30 249.20 89.51 362.74 17.63
66 Std.Dev.Daily.PL 827.41 1022.53 1115.19 1097.78 907.45
67 Ann.Sharpe 5.68 7.93 6.63 8.36 5.67
Max.Drawdown -2689.16 -2599.61 -2764.56 -1475.57 -2439.52
68 Profit.To.Max.Draw 3.62 6.47 4.75 12.15 5.51
69 Avg.WinLoss.Ratio 2.65 3.04 2.79 2.38 3.16
70 Med.WinLoss.Ratio 2.10 2.74 3.15 1.31 2.34
71 Max.Equity 9736.49 17637.00 14909.94 18695.22 13435.41
Min.Equity -392.89 0.00 0.00 -127.86 -654.86
72 End.Equity 9736.49 16814.33 13135.27 17932.39 13435.41
73
74 IYR IYZ LQD RWR SHY
75 Num.Txns 57.00 67.00 60.00 57.00 54.00
76 Num.Trades 29.00 34.00 30.00 29.00 25.00
77 Net.Trading.PL 13555.67 7434.57 12091.15 13301.24 31955.85
Avg.Trade.PL 467.44 218.66 403.04 458.66 1278.23
78 Med.Trade.PL 137.55 -65.13 133.08 142.52 261.88
79 Largest.Winner 6726.10 1967.48 2512.92 2396.20 13432.83
80 Largest.Loser -511.83 -931.17 -1902.27 -664.22 -887.59
81 Gross.Profits 17122.17 13327.47 16376.88 17323.42 34748.07
82 Gross.Losses
Std.Dev.Trade.PL
-3566.50 -5892.89 -4285.72 -4022.18 -2792.21
1379.47 754.07 947.51 914.56 2874.15
83 Percent.Positive 62.07 44.12 66.67 55.17 64.00
84 Percent.Negative 37.93 55.88 33.33 44.83 36.00
85 Profit.Factor 4.80 2.26 3.82 4.31 12.44
86 Avg.Win.Trade 951.23 888.50 818.84 1082.71 2171.75
Med.Win.Trade 338.57 542.36 623.46 929.54 1104.65
87 Avg.Losing.Trade -324.23 -310.15 -428.57 -309.40 -310.25
88 Med.Losing.Trade -377.80 -289.92 -311.99 -232.44 -336.51
89 Avg.Daily.PL 471.34 177.85 403.04 461.77 1278.23
90 Med.Daily.PL 129.71 -70.50 133.08 127.80 261.88
91 Std.Dev.Daily.PL 1404.62 726.63 947.51 931.19 2874.15
Ann.Sharpe 5.33 3.89 6.75 7.87 7.06
92 Max.Drawdown -2623.12 -2791.39 -3237.00 -2463.55 -1756.33
93 Profit.To.Max.Draw 5.17 2.66 3.74 5.40 18.19
94 Avg.WinLoss.Ratio 2.93 2.86 1.91 3.50 7.00
95 Med.WinLoss.Ratio 0.90 1.87 2.00 4.00 3.28
96 Max.Equity
Min.Equity
15608.04 8133.92 12349.90 14777.73 32781.60
-473.13 -520.47 -146.25 -314.85 -63.98
97 End.Equity 13555.67 7434.57 12091.15 13301.24 31955.85
98
99 TLT XLB XLE XLF XLI
100 Num.Txns 66.00 69.00 75.00 67.00 61.00
101 Num.Trades 33.00 35.00 38.00 34.00 31.00
Net.Trading.PL 9170.38 6286.92 9724.35 6689.67 9474.51
102 Avg.Trade.PL 277.89 179.63 255.90 196.76 305.63
103 Med.Trade.PL -9.84 -92.05 -2.16 -65.18 165.99
104 Largest.Winner 2658.27 1727.45 2624.41 1948.36 1610.51
105 Largest.Loser -797.00 -821.66 -686.89 -470.70 -762.56
106 Gross.Profits 15454.01 12787.87 15637.04 10744.46 13894.65
Gross.Losses -6283.62 -6500.94 -5912.69 -4054.78 -4420.15
107 Std.Dev.Trade.PL 902.92 707.04 857.84 599.09 700.96
108 Percent.Positive 48.48 45.71 47.37 47.06 54.84
109 Percent.Negative 51.52 54.29 52.63 52.94 45.16
110 Profit.Factor 2.46 1.97 2.64 2.65 3.14
111 Avg.Win.Trade 965.88 799.24 868.72 671.53 817.33
Med.Win.Trade 721.04 790.04 632.93 515.21 885.41
112 Avg.Losing.Trade -369.62 -342.15 -295.63 -225.27 -315.72
113 Med.Losing.Trade -417.82 -309.84 -236.16 -188.27 -301.85
114 Avg.Daily.PL 277.89 126.90 186.61 198.53 262.31
115 Med.Daily.PL -9.84 -97.36 -3.15 -95.20 147.54
Std.Dev.Daily.PL 902.92 644.05 754.17 608.29 669.41
116 Ann.Sharpe 4.89 3.13 3.93 5.18 6.22
117 Max.Drawdown -4200.46 -2545.47 -3708.60 -2393.02 -2159.46
118 Profit.To.Max.Draw 2.18 2.47 2.62 2.80 4.39
119 Avg.WinLoss.Ratio 2.61 2.34 2.94 2.98 2.59
120 Med.WinLoss.Ratio 1.73 2.55 2.68 2.74 2.93
Max.Equity 11046.45 6319.32 10527.81 8171.61 9481.43
121 Min.Equity -367.76 -489.76 -301.10 -458.76 -348.23
End.Equity 9170.38 6286.92 9724.35 6689.67 9474.51
122
123
XLK XLP XLU XLV XLY
124 Num.Txns 65.00 73.00 57.00 71.00 59.00
125 Num.Trades 33.00 37.00 28.00 36.00 30.00
126 Net.Trading.PL 6074.82 6211.79 14167.62 2959.63 10416.38
127 Avg.Trade.PL 184.09 167.89 505.99 82.21 347.21
Med.Trade.PL 45.54 -6.88 218.93 35.12 54.36
128 Largest.Winner 2118.84 1518.72 2715.03 1515.40 2324.63
129 Largest.Loser -800.36 -710.82 -595.12 -1025.77 -814.78
130 Gross.Profits 12263.07 12061.50 16821.17 9472.62 14850.49
131 Gross.Losses -6188.26 -5849.72 -2653.56 -6512.99 -4434.12
132 Std.Dev.Trade.PL 714.36 617.33 862.82 582.88 861.18
Percent.Positive 51.52 45.95 75.00 55.56 53.33
133 Percent.Negative 48.48 54.05 25.00 44.44 46.67
134 Profit.Factor 1.98 2.06 6.34 1.45 3.35
135 Avg.Win.Trade 721.36 709.50 801.01 473.63 928.16
136 Med.Win.Trade 653.80 760.76 782.21 301.14 746.86
Avg.Losing.Trade -386.77 -292.49 -379.08 -407.06 -316.72
137 Med.Losing.Trade -300.13 -203.01 -491.90 -310.13 -267.52
138 Avg.Daily.PL 187.13 164.72 521.39 82.91 302.83
139 Med.Daily.PL 4.72 -7.27 249.47 33.66 23.93
140 Std.Dev.Daily.PL 725.58 625.78 875.33 591.37 840.78
141 Ann.Sharpe 4.09 4.18 9.46 2.23 5.72
Max.Drawdown -2615.33 -2565.79 -1696.88 -2604.95 -2431.47
142 Profit.To.Max.Draw 2.32 2.42 8.35 1.14 4.28
143 Avg.WinLoss.Ratio 1.87 2.43 2.11 1.16 2.93
144 Med.WinLoss.Ratio 2.18 3.75 1.59 0.97 2.79
145 Max.Equity 6786.94 6374.13 14371.31 4236.64 10538.74
146 Min.Equity -523.50 -269.87 0.00 -205.49 -154.97
End.Equity 6074.82 6211.79 14167.62 2959.63 10416.38
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

And aggregate trade stats:

1
> (aggPF <- sum(tStats$Gross.Profits)/-sum(tStats$Gross.Losses))
2 [1] 3.37825
3 > (aggCorrect <- mean(tStats$Percent.Positive))
4 [1] 55.921
5 > (numTrades <- sum(tStats$Num.Trades))
6 [1] 946
> (meanAvgWLR <- mean(tStats$Avg.WinLoss.Ratio))
7 [1] 2.766667
8

If you scroll down to the end of the , you can see that the aggregate profit factor broke above 3 per trade
(that is, when you aggregate all the trades on their own merit, you take away more than $3 for every $1 that
the market claims, and even the standalone average per-instrument win to loss ratio improved (youll see
why in a moment).

Here are the daily stats:

1#dailyStats
2dStats <- dailyStats(Portfolios = portfolio.st, use="Equity")
3rownames(dStats) <- gsub(".DailyEndEq","", rownames(dStats))
4print(data.frame(t(dStats)))
1 EFA EPP EWA
EWC EWG
2
Total.Net.Profit 15389.57 15578.88 16204.18 11846.58
3 12646.07
4 Total.Days 1316.00 1323.00 1303.00
5 1297.00 1281.00
6 Winning.Days 713.00 722.00 730.00
729.00 719.00
7 Losing.Days 603.00 601.00 573.00
8 568.00 562.00
9 Avg.Day.PL 11.69 11.78 12.44
10 9.13 9.87
11 Med.Day.PL 16.38 16.83 21.71
21.41 20.15
12 Largest.Winner 677.61 663.11 1056.94
13 449.52 525.11
14 Largest.Loser -951.74 -1054.27 -1049.55
15 -576.75 -880.58
Gross.Profits 82528.83 93453.33 86183.11 74841.31
16 78603.60
17 Gross.Losses -67139.26 -77874.45 -69978.93 -62994.74
18 -65957.53
19 Std.Dev.Daily.PL 147.33 171.22 159.08
20 134.32 147.41
Percent.Positive 54.18 54.57 56.02
21 56.21 56.13
22 Percent.Negative 45.82 45.43 43.98
23 43.79 43.87
24 Profit.Factor 1.23 1.20 1.23
25 1.19 1.19
Avg.Win.Day 115.75 129.44 118.06
26 102.66 109.32
27 Med.Win.Day 96.00 104.99 98.53
28 88.60 88.28
29 Avg.Losing.Day -111.34 -129.57 -122.13
-110.91 -117.36
30
Med.Losing.Day -86.50 -92.48 -89.56
31 -82.30 -87.95
32 Avg.Daily.PL 11.69 11.78 12.44
33 9.13 9.87
34 Med.Daily.PL 16.38 16.83 21.71
21.41 20.15
35 Std.Dev.Daily.PL.1 147.33 171.22 159.08
36 134.32 147.41
37 Ann.Sharpe 1.26 1.09 1.24
38 1.08 1.06
39 Max.Drawdown -2338.43 -2430.09 -2168.66 -2982.50
-2904.73
40 Profit.To.Max.Draw 6.58 6.41 7.47
41 3.97 4.35
42 Avg.WinLoss.Ratio 1.04 1.00 0.97
43 0.93 0.93
Med.WinLoss.Ratio 1.11 1.14 1.10
44 1.08 1.00
45 Max.Equity 15968.41 16789.50 17435.72 13048.24
46 13773.99
47 Min.Equity -17.93 -188.46 0.00
48 -393.45 -100.42
End.Equity 15389.57 15578.88 16204.18 11846.58
49 12646.07
50
51 EWH EWJ EWS
52 EWT EWU
53 Total.Net.Profit 12085.74 7457.81 13356.23
54 6906.24 7492.71
Total.Days 1246.00 1108.00 1302.00
55 1173.00 1250.00
56 Winning.Days 667.00 568.00 726.00
57 608.00 670.00
58 Losing.Days 579.00 540.00 576.00
565.00 580.00
59 Avg.Day.PL 9.70 6.73 10.26
60 5.89 5.99
61 Med.Day.PL 12.96 11.70 20.48
62 8.74 15.91
63 Largest.Winner 518.58 677.56 659.34
716.23 557.67
64 Largest.Loser -977.28 -498.25 -1032.26
65 -1114.68 -922.23
66 Gross.Profits 76296.60 72956.55 76089.41 69500.58
67 71225.98
Gross.Losses -64210.86 -65498.74 -62733.18 -62594.34
68
-63733.27
69 Std.Dev.Daily.PL 148.85 163.57 140.94
70 149.35 139.57
71 Percent.Positive 53.53 51.26 55.76
72 51.83 53.60
Percent.Negative 46.47 48.74 44.24
73 48.17 46.40
74 Profit.Factor 1.19 1.11 1.21
75 1.11 1.12
76 Avg.Win.Day 114.39 128.44 104.81
77 114.31 106.31
Med.Win.Day 89.18 99.48 82.86
78 92.69 91.01
79 Avg.Losing.Day -110.90 -121.29 -108.91
80 -110.79 -109.88
81 Med.Losing.Day -82.75 -92.33 -86.52
-80.77 -82.34
82 Avg.Daily.PL 9.70 6.73 10.26
83 5.89 5.99
84 Med.Daily.PL 12.96 11.70 20.48
8.74 15.91
85
Std.Dev.Daily.PL.1 148.85 163.57 140.94
86 149.35 139.57
87 Ann.Sharpe 1.03 0.65 1.16
88 0.63 0.68
89 Max.Drawdown -2229.93 -4036.69 -2021.12 -3147.85
-2599.57
90 Profit.To.Max.Draw 5.42 1.85 6.61
91 2.19 2.88
92 Avg.WinLoss.Ratio 1.03 1.06 0.96
93 1.03 0.97
94 Med.WinLoss.Ratio 1.08 1.08 0.96
1.15 1.11
95 Max.Equity 13043.23 8395.92 14415.11
96 6906.24 9160.15
97 Min.Equity -33.87 -274.69 -699.37
98 -788.28 -327.38
End.Equity 12085.74 7457.81 13356.23
99 6906.24 7492.71
100
101 EWY EWZ EZU
102 IEF IGE
103 Total.Net.Profit 9736.49 16814.33 13135.27 17932.39
104 13435.41
Total.Days 1245.00 1368.00 1288.00
105 1220.00 1288.00
106 Winning.Days 687.00 770.00 702.00
107 647.00 710.00
108 Losing.Days 558.00 598.00 586.00
109 573.00 578.00
Avg.Day.PL 7.82 12.29 10.20
110 14.70 10.43
111 Med.Day.PL 19.58 24.81 18.68
112 15.24 22.02
113 Largest.Winner 551.45 638.31 641.61
718.28 641.62
114 Largest.Loser -850.59 -873.96 -1149.58
115 -629.94 -585.35
116 Gross.Profits 78146.89 91623.76 78313.24 89399.23
117 87064.44
118 Gross.Losses -68410.40 -74809.43 -65177.97 -71466.84
-73629.04
119 Std.Dev.Daily.PL 155.20 158.93 147.61
120 169.04 160.78
121 Percent.Positive 55.18 56.29 54.50
122 53.03 55.12
Percent.Negative 44.82 43.71 45.50
123
46.97 44.88
124 Profit.Factor 1.14 1.22 1.20
125 1.25 1.18
126 Avg.Win.Day 113.75 118.99 111.56
127 138.18 122.63
Med.Win.Day 92.47 99.96 89.60
128 111.01 100.82
129 Avg.Losing.Day -122.60 -125.10 -111.23
130 -124.72 -127.39
131 Med.Losing.Day -87.06 -96.89 -82.02
132 -100.19 -101.57
Avg.Daily.PL 7.82 12.29 10.20
133 14.70 10.43
134 Med.Daily.PL 19.58 24.81 18.68
135 15.24 22.02
136 Std.Dev.Daily.PL.1 155.20 158.93 147.61
169.04 160.78
137 Ann.Sharpe 0.80 1.23 1.10
138 1.38 1.03
139 Max.Drawdown -2689.16 -2599.61 -2764.56 -1475.57
-2439.52
140
Profit.To.Max.Draw 3.62 6.47 4.75
141 12.15 5.51
142 Avg.WinLoss.Ratio 0.93 0.95 1.00
143 1.11 0.96
144 Med.WinLoss.Ratio 1.06 1.03 1.09
1.11 0.99
145 Max.Equity 9736.49 17637.00 14909.94 18695.22
146 13435.41
147 Min.Equity -392.89 0.00 0.00
148 -127.86 -654.86
149 End.Equity 9736.49 16814.33 13135.27 17932.39
13435.41
150
151 IYR IYZ LQD
152 RWR SHY
153 Total.Net.Profit 13555.67 7434.57 12091.15 13301.24
154 31955.85
Total.Days 1312.00 1213.00 1290.00
155 1324.00 1403.00
156 Winning.Days 711.00 641.00 720.00
157 713.00 796.00
158 Losing.Days 601.00 572.00 570.00
159 611.00 607.00
Avg.Day.PL 10.33 6.13 9.37
160 10.05 22.78
161 Med.Day.PL 13.97 11.30 13.65
162 14.07 23.56
163 Largest.Winner 690.00 539.17 414.09
164 701.08 743.43
Largest.Loser -995.13 -747.09 -1607.99
165 -999.24 -896.22
166 Gross.Profits 80483.61 60768.48 65938.33 81751.44
167 104570.57
168 Gross.Losses -66927.95 -53333.91 -53847.18 -68450.20
-72614.72
169 Std.Dev.Daily.PL 150.96 123.03 125.94
170 153.36 167.92
171 Percent.Positive 54.19 52.84 55.81
172 53.85 56.74
173 Percent.Negative 45.81 47.16 44.19
46.15 43.26
174 Profit.Factor 1.20 1.14 1.22
175 1.19 1.44
176 Avg.Win.Day 113.20 94.80 91.58
177 114.66 131.37
Med.Win.Day 95.20 70.59 74.82
178
94.50 95.01
179 Avg.Losing.Day -111.36 -93.24 -94.47
180 -112.03 -119.63
181 Med.Losing.Day -79.94 -70.65 -73.01
182 -78.78 -95.52
Avg.Daily.PL 10.33 6.13 9.37
183 10.05 22.78
184 Med.Daily.PL 13.97 11.30 13.65
185 14.07 23.56
Std.Dev.Daily.PL.1 150.96 123.03 125.94
153.36 167.92
Ann.Sharpe 1.09 0.79 1.18
1.04 2.15
Max.Drawdown -2623.12 -2791.39 -3237.00 -2463.55
-1756.33
Profit.To.Max.Draw 5.17 2.66 3.74
5.40 18.19
Avg.WinLoss.Ratio 1.02 1.02 0.97
1.02 1.10
Med.WinLoss.Ratio 1.19 1.00 1.02
1.20 0.99
Max.Equity 15608.04 8133.92 12349.90 14777.73
32781.60
Min.Equity -473.13 -520.47 -146.25
-314.85 -63.98
End.Equity 13555.67 7434.57 12091.15 13301.24
31955.85

TLT XLB XLE


XLF XLI
Total.Net.Profit 9170.38 6286.92 9724.35
6689.67 9474.51
Total.Days 1177.00 1262.00 1306.00
1153.00 1285.00
Winning.Days 613.00 680.00 702.00
607.00 711.00
Losing.Days 564.00 582.00 604.00
546.00 574.00
Avg.Day.PL 7.79 4.98 7.45
5.80 7.37
Med.Day.PL 14.24 13.77 12.90
11.39 12.93
Largest.Winner 779.53 558.63 506.82
417.23 725.14
Largest.Loser -626.74 -760.41 -498.32
-870.83 -603.54
Gross.Profits 80421.50 70434.95 78663.61 58593.75
63680.92
Gross.Losses -71251.12 -64148.03 -68939.26 -51904.08
-54206.41
Std.Dev.Daily.PL 169.42 137.85 145.10
126.64 121.34
Percent.Positive 52.08 53.88 53.75
52.65 55.33
Percent.Negative 47.92 46.12 46.25
47.35 44.67
Profit.Factor 1.13 1.10 1.14
1.13 1.17
Avg.Win.Day 131.19 103.58 112.06
96.53 89.57
Med.Win.Day 100.56 87.71 92.88
73.21 70.48
Avg.Losing.Day -126.33 -110.22 -114.14
-95.06 -94.44
Med.Losing.Day -96.87 -84.01 -92.03
-68.77 -74.02
Avg.Daily.PL 7.79 4.98 7.45
5.80 7.37
Med.Daily.PL 14.24 13.77 12.90
11.39 12.93
Std.Dev.Daily.PL.1 169.42 137.85 145.10
126.64 121.34
Ann.Sharpe 0.73 0.57 0.81
0.73 0.96
Max.Drawdown -4200.46 -2545.47 -3708.60 -2393.02
-2159.46
Profit.To.Max.Draw 2.18 2.47 2.62
2.80 4.39
Avg.WinLoss.Ratio 1.04 0.94 0.98
1.02 0.95
Med.WinLoss.Ratio 1.04 1.04 1.01
1.06 0.95
Max.Equity 11046.45 6319.32 10527.81
8171.61 9481.43
Min.Equity -367.76 -489.76 -301.10
-458.76 -348.23
End.Equity 9170.38 6286.92 9724.35
6689.67 9474.51

XLK XLP XLU


XLV XLY
Total.Net.Profit 6074.82 6211.79 14167.62 2959.63
10416.38
Total.Days 1216.00 1284.00 1388.00
1178.00 1234.00
Winning.Days 674.00 705.00 770.00
617.00 653.00
Losing.Days 542.00 579.00 618.00
561.00 581.00
Avg.Day.PL 5.00 4.84 10.21
2.51 8.44
Med.Day.PL 17.93 15.90 16.14
6.56 12.17
Largest.Winner 574.72 900.15 556.47
473.90 769.98
Largest.Loser -724.67 -556.91 -838.97
-710.57 -629.37
Gross.Profits 61490.68 61791.76 69063.01 54247.40
64353.02
Gross.Losses -55415.86 -55579.98 -54895.40 -51287.76
-53936.65
Std.Dev.Daily.PL 125.72 118.81 118.48
117.04 126.47
Percent.Positive 55.43 54.91 55.48
52.38 52.92
Percent.Negative 44.57 45.09 44.52
47.62 47.08
Profit.Factor 1.11 1.11 1.26
1.06 1.19
Avg.Win.Day 91.23 87.65 89.69
87.92 98.55
Med.Win.Day 73.60 71.94 71.86
72.65 77.55
Avg.Losing.Day -102.24 -95.99 -88.83
-91.42 -92.83
Med.Losing.Day -74.44 -75.68 -64.76
-73.67 -74.04
Avg.Daily.PL 5.00 4.84 10.21
2.51 8.44
Med.Daily.PL 17.93 15.90 16.14
6.56 12.17
Std.Dev.Daily.PL.1 125.72 118.81 118.48
117.04 126.47
Ann.Sharpe 0.63 0.65 1.37
0.34 1.06
Max.Drawdown -2615.33 -2565.79 -1696.88 -2604.95
-2431.47
Profit.To.Max.Draw 2.32 2.42 8.35
1.14 4.28
Avg.WinLoss.Ratio 0.89 0.91 1.01
0.96 1.06
Med.WinLoss.Ratio 0.99 0.95 1.11
0.99 1.05
Max.Equity 6786.94 6374.13 14371.31 4236.64
10538.74
Min.Equity -523.50 -269.87 0.00
-205.49 -154.97
End.Equity 6074.82 6211.79 14167.62 2959.63
10416.38
1 #portfolio cash PL
2 portPL <- .blotter$portfolio.TVI_osATR$summary$Net.Trading.PL
3
#Cash Sharpe
4 (SharpeRatio.annualized(portPL, geometric=FALSE))
5
1 > (SharpeRatio.annualized(portPL, geometric=FALSE))
2 Net.Trading.PL
3 Annualized Sharpe Ratio (Rf=0%) 1.383361

So a cash Sharpe (a conservative estimate) a healthy amount higher than 1. Now lets look at something
interesting. Remember those base instrument correlations at the beginning of this post?

1
2 #Portfolio comparisons to SPY
instRets <- PortfReturns(account.st)
3
4 #Correlations
5 instCors <- cor(instRets)
6 diag(instRets) <- NA
7 corMeans <- rowMeans(instCors, na.rm=TRUE)
names(corMeans) <- gsub(".DailyEndEq", "", names(corMeans))
8 print(round(corMeans,3))
9 mean(corMeans)
10
1
2 > print(round(corMeans,3))
EFA EPP EWA EWC EWG EWH EWJ EWS EWT EWU
3 0.503 0.456 0.406 0.392 0.457 0.392 0.354 0.417 0.355 0.452
4 EWY EWZ EZU IEF IGE IYR IYZ LQD RWR SHY
5 0.399 0.387 0.471 -0.001 0.384 0.322 0.375 0.078 0.313 -0.013
6 TLT XLB XLE XLF XLI XLK XLP XLU XLV XLY
0.009 0.447 0.362 0.407 0.434 0.407 0.333 0.314 0.336 0.412
7
8 > mean(corMeans)
9 [1] 0.3452772
10

With this (somewhat) simplistic market timer, the correlations of some dangerously correlated instruments
have been, on aggregate, sliced by more than 50%. Pretty impressive, no?

Lets look at equity curve comparisons.

1cumPortfRets <- cumprod(1+portfRets)


2firstNonZeroDay <- index(portfRets)[min(which(portfRets!=0))]
3getSymbols("SPY", from=firstNonZeroDay, to="2010-12-31")
4SPYrets <- diff(log(Cl(SPY)))[-1]
cumSPYrets <- cumprod(1+SPYrets)
5comparison <- cbind(cumPortfRets, cumSPYrets)
6colnames(comparison) <- c("strategy", "SPY")
7chart.TimeSeries(comparison, legend.loc = "topleft",
8 main=paste0("Period=", period, ", Delta=",delta),
colors=c("green","red"))
9
To compare, here is the equity curve with all three strategiesbuy and hold the SPY, and the two TVI
strategiesthe ATR in green and the equal dollar weight in black.

Notice how, with better order sizing, that the recession barely even scratched the equity curve?

Here are the aggregate portfolio statistics:

1 #Sharpe, Returns, max DD


2 SharpeRatio.annualized(portfRets)
3 Return.annualized(portfRets)
maxDrawdown(portfRets)
4
1 > SharpeRatio.annualized(portfRets)
[,1]
2 Annualized Sharpe Ratio (Rf=0%) 1.428448
3 > Return.annualized(portfRets)
4 [,1]
5 Annualized Return 0.1504228
6 > maxDrawdown(portfRets)
[1] 0.1103311
7
8

First off: annualized Sharpe Ratio above 1.4. Daily returns. Next, something that personally impresses me:
annualized return higher than maximum drawdown. My interpretation of this is that while you *may* have
the occasional down year, on average, even in the absolute worst case scenario, it takes you less than a year
to recover from your absolute worst drawdown.

And keep in mind, this is with 30 instruments, most of them highly correlated!

Lastly, lets look at an individual instruments equity curve and how the position-sizing algorithm helps out.

1#Individual instrument equity curve


2chart.Posn(portfolio.st, "XLB")
3#The triggerLag is NOT 30 for the strategy, just amplified in this case to illustrate
4exit logic.
#The actual trigger lag is defaulted at 1.
5tmp <- TVI(Cl(XLB), period=period, delta=delta, triggerLag=1)
6add_TA(tmp$vigor, lwd=3)
7add_TA(tmp$trigger, on=5, col="red", lwd=1.5)
8tmp2 <- lagATR(HLC=HLC(XLB), n=period)
9add_TA(tmp2$atr, col="blue", lwd=2)

Remember how even the average win to loss ratios went up? This is why. Notice the height of the blue
rectangles (position sizes up, duration of trade across), in relation to the ATR (the blue line across the
bottom). In the depths of the financial crisis, even though the actual strategy wasnt intelligent enough to
know to keep out, through the use of ATR position sizing, it reduced trade sizes considerably. The result was
a failsafe that prevented a great deal of damage to a system that had no idea it was trading against a massive
longer time horizon trend going in the opposite direction.

Of course, this does not mean that ATR order sizing on entry is a complete catch-all for everything that can
go wrong. At longer time frames, an entry signals calculation may have little relevance to the actual risk of
the position currently. On this strategy, because I was using a 20-day period, I felt that the issue of
rebalancing wouldnt be a major factor, because old positions were exited, and new positions were entered at
a good pace (about 1,000 trades in 7 years is 142 trades per year on average, over 30 instruments, thats
around 4 trades per year per instrument, which puts each trade at a couple of months on average, and
considering that rebalancing can happen monthly to quarterly, rebalancing isnt an issue at this frequency).
However, this does not apply to longer time frames.
For instance, if the period (both for the Trend Vigor and for the ATR computation) were changed to 60 days,
these are the results:

trade stats:

1 EFA EPP EWA EWC EWG


Num.Txns 21.00 19.00 17.00 15.00 21.00
2
Num.Trades 11.00 10.00 9.00 8.00 11.00
3 Net.Trading.PL 10208.50 17160.90 16467.19 16571.75 10873.05
4 Avg.Trade.PL 928.05 1716.09 1829.69 2071.47 988.46
5 Med.Trade.PL 1139.43 1599.47 2284.16 2714.11 1024.49
6 Largest.Winner 3958.71 6239.36 4809.68 4067.28 5039.72
Largest.Loser -2055.34 -1680.48 -1293.99 -552.08 -1506.05
7 Gross.Profits 14866.20 20617.57 19559.85 17387.68 14996.28
8 Gross.Losses -4657.70 -3456.67 -3092.66 -815.93 -4123.23
9 Std.Dev.Trade.PL 1986.71 2532.82 2298.49 1699.23 2040.81
10 Percent.Positive 63.64 70.00 66.67 75.00 63.64
11 Percent.Negative 36.36 30.00 33.33 25.00 36.36
Profit.Factor 3.19 5.96 6.32 21.31 3.64
12 Avg.Win.Trade 2123.74 2945.37 3259.97 2897.95 2142.33
13 Med.Win.Trade 1635.86 2404.87 3413.33 2931.19 1490.68
14 Avg.Losing.Trade -1164.43 -1152.22 -1030.89 -407.97 -1030.81
15 Med.Losing.Trade -1165.87 -1088.41 -954.82 -407.97 -1038.36
Avg.Daily.PL 857.26 1696.47 2070.98 2155.75 940.86
16 Med.Daily.PL 822.59 1306.31 2284.16 2874.79 668.54
17 Std.Dev.Daily.PL 2079.51 2685.65 3206.53 1817.23 2144.75
18 Ann.Sharpe 6.54 10.03 10.25 18.83 6.96
19 Max.Drawdown -5394.64 -3799.80 -3919.36 -3229.19 -5185.89
20 Profit.To.Max.Draw 1.89 4.52 4.20 5.13 2.10
Avg.WinLoss.Ratio 1.82 2.56 3.16 7.10 2.08
21 Med.WinLoss.Ratio 1.40 2.21 3.57 7.18 1.44
22 Max.Equity 13816.60 18136.21 17072.51 16571.75 14015.59
23 Min.Equity 0.00 -135.30 0.00 -132.86 -75.34
24 End.Equity 10208.50 17160.90 16467.19 16571.75 10873.05
25
26 EWH EWJ EWS EWT EWU
Num.Txns 19.00 25.00 19.00 21.00 25.00
27 Num.Trades 10.00 13.00 9.00 11.00 13.00
28 Net.Trading.PL 12558.12 8228.69 15686.23 4112.81 6421.97
29 Avg.Trade.PL 1255.81 632.98 1742.91 373.89 494.00
30 Med.Trade.PL 1286.07 38.30 1543.49 131.24 1188.66
Largest.Winner 5381.90 5983.06 6090.42 2292.56 2041.08
31 Largest.Loser -1189.78 -1476.27 -787.18 -1439.03 -1987.03
32 Gross.Profits 14737.19 12329.23 17166.54 8550.62 10961.68
33 Gross.Losses -2179.07 -4100.54 -1480.31 -4437.82 -4539.71
34 Std.Dev.Trade.PL 1962.01 2047.60 2255.20 1461.94 1278.47
35 Percent.Positive 70.00 53.85 77.78 63.64 61.54
Percent.Negative 30.00 46.15 22.22 36.36 38.46
36 Profit.Factor 6.76 3.01 11.60 1.93 2.41
37 Avg.Win.Trade 2105.31 1761.32 2452.36 1221.52 1370.21
38 Med.Win.Trade 1722.40 454.78 1586.46 1018.02 1478.14
39 Avg.Losing.Trade -726.36 -683.42 -740.16 -1109.45 -907.94
Med.Losing.Trade -908.19 -673.37 -740.16 -1169.46 -877.51
40
Avg.Daily.PL 1161.34 543.61 1762.47 113.24 434.83
41 Med.Daily.PL 1051.12 -79.18 1250.27 73.92 768.38
42 Std.Dev.Daily.PL 2056.75 2112.00 2410.10 1242.73 1316.60
43 Ann.Sharpe 8.96 4.09 11.61 1.45 5.24
44 Max.Drawdown -4368.83 -6749.29 -3010.28 -4204.52 -4997.13
Profit.To.Max.Draw 2.87 1.22 5.21 0.98 1.29
45 Avg.WinLoss.Ratio 2.90 2.58 3.31 1.10 1.51
46 Med.WinLoss.Ratio 1.90 0.68 2.14 0.87 1.68
47 Max.Equity 13935.41 13216.89 15878.52 4375.25 9759.45
48 Min.Equity -281.46 0.00 0.00 -22.49 0.00
49 End.Equity 12558.12 8228.69 15686.23 4112.81 6421.97
50
EWY EWZ EZU IEF IGE
51 Num.Txns 15.00 15.00 19.00 22.00 25.00
Num.Trades 8.00 8.00 10.00 11.00 13.00
52
Net.Trading.PL 13779.39 23013.79 7849.71 10099.65 14095.94
53 Avg.Trade.PL 1722.42 2876.72 784.97 918.15 1084.30
54 Med.Trade.PL 1977.00 2866.24 1019.40 395.20 45.68
55 Largest.Winner 3889.04 6791.13 2859.00 4103.15 5685.82
56 Largest.Loser -1312.72 -1003.77 -1640.20 -1292.50 -1069.15
Gross.Profits 15092.11 24017.56 10979.15 12939.41 17823.91
57 Gross.Losses -1312.72 -1003.77 -3129.45 -2839.76 -3727.97
58 Std.Dev.Trade.PL 1594.21 2830.98 1540.22 1747.80 2125.97
59 Percent.Positive 87.50 87.50 70.00 63.64 53.85
60 Percent.Negative 12.50 12.50 30.00 36.36 46.15
61 Profit.Factor 11.50 23.93 3.51 4.56 4.78
Avg.Win.Trade 2156.02 3431.08 1568.45 1848.49 2546.27
62 Med.Win.Trade 2339.69 3735.41 1562.23 1595.67 2222.50
63 Avg.Losing.Trade -1312.72 -1003.77 -1043.15 -709.94 -621.33
64 Med.Losing.Trade -1312.72 -1003.77 -1205.35 -726.74 -543.04
65 Avg.Daily.PL 1633.02 3143.63 786.64 918.15 989.45
Med.Daily.PL 1614.30 3735.41 1268.81 395.20 -134.88
66 Std.Dev.Daily.PL 1700.14 2947.08 1633.64 1747.80 2191.58
67 Ann.Sharpe 15.25 16.93 7.64 8.34 7.17
68 Max.Drawdown -4564.52 -4072.32 -5298.53 -4019.55 -3449.65
69 Profit.To.Max.Draw 3.02 5.65 1.48 2.51 4.09
70 Avg.WinLoss.Ratio 1.64 3.42 1.50 2.60 4.10
Med.WinLoss.Ratio 1.78 3.72 1.30 2.20 4.09
71 Max.Equity 13779.39 23910.96 10592.36 12909.83 14200.07
72 Min.Equity 0.00 0.00 -165.41 -1675.30 -88.76
73 End.Equity 13779.39 23013.79 7849.71 10099.65 14095.94
74
75 IYR IYZ LQD RWR SHY
76 Num.Txns 17.00 21.00 20.00 19.00 14.00
Num.Trades 9.00 11.00 10.00 10.00 7.00
77 Net.Trading.PL 12982.75 9649.19 4756.41 11097.68 30866.81
78 Avg.Trade.PL 1442.53 877.20 475.64 1109.77 4409.54
79 Med.Trade.PL 1332.53 846.90 172.62 1280.34 449.49
80 Largest.Winner 3712.91 5017.76 3474.77 4332.24 24644.48
Largest.Loser -515.27 -977.05 -891.57 -993.55 -259.33
81 Gross.Profits 13790.04 11967.93 7704.54 13487.26 31126.14
82 Gross.Losses -807.29 -2318.75 -2948.14 -2389.57 -259.33
83 Std.Dev.Trade.PL 1542.81 1654.02 1388.08 1710.13 9013.08
84 Percent.Positive 77.78 72.73 50.00 70.00 85.71
85 Percent.Negative 22.22 27.27 50.00 30.00 14.29
Profit.Factor 17.08 5.16 2.61 5.64 120.03
86 Avg.Win.Trade 1970.01 1495.99 1540.91 1926.75 5187.69
87 Med.Win.Trade 1596.75 1104.29 1437.80 1685.60 1540.67
88 Avg.Losing.Trade -403.65 -772.92 -589.63 -796.52 -259.33
89 Med.Losing.Trade -403.65 -916.94 -725.42 -886.53 -259.33
Avg.Daily.PL 1480.73 770.38 475.64 1130.97 4409.54
90
Med.Daily.PL 1464.64 617.43 172.62 1641.75 449.49
91 Std.Dev.Daily.PL 1644.78 1703.02 1388.08 1812.47 9013.08
92 Ann.Sharpe 14.29 7.18 5.44 9.91 7.77
93 Max.Drawdown -4095.25 -2939.04 -3263.55 -4582.43 -3537.22
94 Profit.To.Max.Draw 3.17 3.28 1.46 2.42 8.73
Avg.WinLoss.Ratio 4.88 1.94 2.61 2.42 20.00
95 Med.WinLoss.Ratio 3.96 1.20 1.98 1.90 5.94
96 Max.Equity 13142.58 9649.19 5704.58 12750.19 31638.96
97 Min.Equity -257.82 -18.03 -876.30 -336.91 -401.25
98 End.Equity 12982.75 9649.19 4756.41 11097.68 30866.81
99
10 TLT XLB XLE XLF XLI
Num.Txns 20.00 23.00 27.00 17.00 17.00
0 Num.Trades 10.00 12.00 14.00 9.00 9.00
10 Net.Trading.PL 7984.42 10276.48 15328.84 2931.55 11452.17
1 Avg.Trade.PL 798.44 856.37 1094.92 325.73 1272.46
10 Med.Trade.PL 635.82 553.43 298.85 353.89 1530.29
Largest.Winner 4084.20 3877.14 10982.05 1552.10 3382.70
2 Largest.Loser -1295.01 -1514.24 -1066.86 -1658.50 -1082.79
10 Gross.Profits 11035.29 13539.19 18826.91 5044.64 13147.30
3 Gross.Losses -3050.87 -3262.71 -3498.08 -2113.09 -1695.13
Std.Dev.Trade.PL 1656.89 1654.32 3020.85 1003.42 1538.10
10 Percent.Positive 60.00 58.33 50.00 77.78 66.67
4 Percent.Negative 40.00 41.67 50.00 22.22 33.33
10 Profit.Factor 3.62 4.15 5.38 2.39 7.76
5 Avg.Win.Trade 1839.22 1934.17 2689.56 720.66 2191.22
Med.Win.Trade 1779.55 1758.72 1297.88 602.56 1887.54
10 Avg.Losing.Trade -762.72 -652.54 -499.73 -1056.55 -565.04
6 Med.Losing.Trade -616.18 -444.05 -502.26 -1056.55 -482.61
10 Avg.Daily.PL 798.44 733.48 993.83 248.29 1246.61
7 Med.Daily.PL 635.82 175.80 -75.82 215.38 1598.19
10 Std.Dev.Daily.PL 1656.89 1676.63 3119.46 1043.56 1642.21
Ann.Sharpe 7.65 6.94 5.06 3.78 12.05
8 Max.Drawdown -4815.13 -3002.83 -3697.94 -3305.04 -2288.62
10 Profit.To.Max.Draw 1.66 3.42 4.15 0.89 5.00
9 Avg.WinLoss.Ratio 2.41 2.96 5.38 0.68 3.88
110Med.WinLoss.Ratio 2.89 3.96 2.58 0.57 3.91
111 Max.Equity
Min.Equity
11680.33
-1228.87
10377.57
-87.21
16209.04
-130.15
4685.40
-225.91
11458.63
0.00
112End.Equity 7984.42 10276.48 15328.84 2931.55 11452.17
113
114 XLK XLP XLU XLV XLY
115Num.Txns 23.00 17.00 21.00 21.00 19.00
116Num.Trades 12.00 9.00 11.00 11.00 10.00
Net.Trading.PL 5168.06 7233.14 9654.01 1295.79 4546.69
117Avg.Trade.PL 430.67 803.68 877.64 117.80 454.67
118Med.Trade.PL 28.36 167.20 412.15 332.08 418.47
119Largest.Winner 2489.14 4607.82 6094.87 1824.31 2341.47
12 Largest.Loser -886.51 -2168.49 -1121.59 -1818.18 -1633.72
0 Gross.Profits 8101.55 10272.30 12840.30 6498.45 8842.45
Gross.Losses -2933.49 -3039.15 -3186.30 -5202.66 -4295.76
12 Std.Dev.Trade.PL 1117.36 1954.14 2261.27 1240.89 1461.48
1 Percent.Positive 50.00 55.56 54.55 54.55 50.00
12 Percent.Negative 50.00 44.44 45.45 45.45 50.00
2 Profit.Factor 2.76 3.38 4.03 1.25 2.06
12 Avg.Win.Trade
Med.Win.Trade
1350.26
1432.23
2054.46
1902.15
2140.05
790.75
1083.08 1768.49
978.13 1744.68
3 Avg.Losing.Trade -488.91 -759.79 -637.26 -1040.53 -859.15
12 Med.Losing.Trade -456.93 -335.80 -779.63 -820.91 -668.55
4 Avg.Daily.PL 336.75 666.37 912.78 47.83 367.23
12 Med.Daily.PL -184.80 -15.93 129.41 -121.08 -404.63
Std.Dev.Daily.PL 1121.11 2042.13 2380.42 1284.94 1522.13
5 Ann.Sharpe 4.77 5.18 6.09 0.59 3.83
12 Max.Drawdown -3136.49 -4108.70 -3440.49 -6294.99 -3508.84
6 Profit.To.Max.Draw 1.65 1.76 2.81 0.21 1.30
12 Avg.WinLoss.Ratio 2.76 2.70 3.36 1.04 2.06
7 Med.WinLoss.Ratio 3.13 5.66 1.01 1.19 2.61
Max.Equity 5216.66 7583.26 11588.28 4179.18 4986.43
12 Min.Equity -88.40 0.00 -144.19 -2115.81 0.00
8 End.Equity 5168.06 7233.14 9654.01 1295.79 4546.69
12
9
13
0
13
1
13
2
13
3
13
4
13
5
13
6
13
7
13
8
13
9
14
0
14
1
14
2
14
3
14
4
14
5
14
6
14
7
14
8
14
9
15
0
15
1
15
2
15
3
15
4
15
5
15
6
15
7
15
8
15
9
16
0
16
1
16
2
16
3
16
4
16
5
16
6
16
7
16
8
16
9
17
0
17
1
17
2
17
3
17
4
17
5
17
6
17
7
17
8
17
9
1
> (aggPF <- sum(tStats$Gross.Profits)/-sum(tStats$Gross.Losses))
2 [1] 4.86916
3 > (aggCorrect <- mean(tStats$Percent.Positive))
4 [1] 65.397
5 > (numTrades <- sum(tStats$Num.Trades))
[1] 309
6
> (meanAvgWLR <- mean(tStats$Avg.WinLoss.Ratio))
7 [1] 3.348667
8

The trade stats look better mainly because of the strength of the indicator to identify periods of good entries.
However, the advantages end there.

Here are the daily stats:

1 EFA EPP EWA EWC EWG


Total.Net.Profit 10208.50 17160.90 16467.19 16571.75 10873.05
2
Total.Days 1315.00 1374.00 1413.00 1462.00 1225.00
3 Winning.Days 717.00 753.00 792.00 815.00 678.00
4 Losing.Days 598.00 621.00 621.00 647.00 547.00
5 Avg.Day.PL 7.76 12.49 11.65 11.33 8.88
6 Med.Day.PL 16.17 18.89 24.11 21.70 18.39
Largest.Winner 854.72 818.41 902.53 735.67 651.33
7 Largest.Loser -891.71 -1089.41 -1022.44 -691.88 -870.92
8 Gross.Profits 88275.97 110279.44 104118.90 97654.12 81458.62
Gross.Losses -78067.47 -93118.55 -87651.72 -81082.37 -70585.57
9
Std.Dev.Daily.PL 169.32 200.83 183.57 157.83 165.30
10 Percent.Positive 54.52 54.80 56.05 55.75 55.35
11 Percent.Negative 45.48 45.20 43.95 44.25 44.65
12 Profit.Factor 1.13 1.18 1.19 1.20 1.15
13 Avg.Win.Day 123.12 146.45 131.46 119.82 120.15
Med.Win.Day 96.83 118.04 108.51 102.89 94.74
14 Avg.Losing.Day -130.55 -149.95 -141.15 -125.32 -129.04
15 Med.Losing.Day -96.63 -102.98 -96.38 -91.98 -93.83
16 Avg.Daily.PL 7.76 12.49 11.65 11.33 8.88
17 Med.Daily.PL 16.17 18.89 24.11 21.70 18.39
18 Std.Dev.Daily.PL.1 169.32 200.83 183.57 157.83 165.30
Ann.Sharpe 0.73 0.99 1.01 1.14 0.85
19 Max.Drawdown -5394.64 -3799.80 -3919.36 -3229.19 -5185.89
20 Profit.To.Max.Draw 1.89 4.52 4.20 5.13 2.10
21 Avg.WinLoss.Ratio 0.94 0.98 0.93 0.96 0.93
22 Med.WinLoss.Ratio 1.00 1.15 1.13 1.12 1.01
Max.Equity 13816.60 18136.21 17072.51 16571.75 14015.59
23 Min.Equity 0.00 -135.30 0.00 -132.86 -75.34
24 End.Equity 10208.50 17160.90 16467.19 16571.75 10873.05
25
26 EWH EWJ EWS EWT EWU
27 Total.Net.Profit 12558.12 8228.69 15686.23 4112.81 6421.97
28 Total.Days 1334.00 1112.00 1337.00 1232.00 1294.00
Winning.Days 706.00 583.00 745.00 630.00 699.00
29 Losing.Days 628.00 529.00 592.00 602.00 595.00
30 Avg.Day.PL 9.41 7.40 11.73 3.34 4.96
31 Med.Day.PL 12.37 16.23 22.24 7.50 17.61
32 Largest.Winner 1132.42 747.36 1048.83 714.29 855.70
33 Largest.Loser -1149.08 -1130.40 -1334.88 -1051.58 -761.51
Gross.Profits 98567.49 88747.53 93204.72 77892.68 79104.53
34 Gross.Losses -86009.37 -80518.84 -77518.49 -73779.88 -72682.57
35 Std.Dev.Daily.PL 201.14 204.93 177.78 167.18 155.18
36 Percent.Positive 52.92 52.43 55.72 51.14 54.02
37 Percent.Negative 47.08 47.57 44.28 48.86 45.98
Profit.Factor 1.15 1.10 1.20 1.06 1.09
38 Avg.Win.Day 139.61 152.23 125.11 123.64 113.17
39 Med.Win.Day 98.81 110.77 95.35 96.74 94.35
40 Avg.Losing.Day -136.96 -152.21 -130.94 -122.56 -122.16
41 Med.Losing.Day -94.53 -109.95 -97.43 -91.36 -93.62
42 Avg.Daily.PL 9.41 7.40 11.73 3.34 4.96
Med.Daily.PL 12.37 16.23 22.24 7.50 17.61
43 Std.Dev.Daily.PL.1 201.14 204.93 177.78 167.18 155.18
44 Ann.Sharpe 0.74 0.57 1.05 0.32 0.51
45 Max.Drawdown -4368.83 -6749.29 -3010.28 -4204.52 -4997.13
46 Profit.To.Max.Draw 2.87 1.22 5.21 0.98 1.29
Avg.WinLoss.Ratio 1.02 1.00 0.96 1.01 0.93
47
Med.WinLoss.Ratio 1.05 1.01 0.98 1.06 1.01
48 Max.Equity 13935.41 13216.89 15878.52 4375.25 9759.45
49 Min.Equity -281.46 0.00 0.00 -22.49 0.00
50 End.Equity 12558.12 8228.69 15686.23 4112.81 6421.97
51
52 EWY EWZ EZU IEF
Total.Net.Profit 13779.39 23013.79 7849.71 10099.65
53 Total.Days 1423.00 1499.00 1260.00 1285.00
54 Winning.Days 777.00 841.00 683.00 659.00
55 Losing.Days 646.00 658.00 577.00 626.00
56 Avg.Day.PL 9.68 15.35 6.23 7.86
57 Med.Day.PL 17.91 24.89 17.35 6.75
Largest.Winner 869.03 1099.10 664.64 1116.66
58 Largest.Loser -838.15 -1215.42 -995.76 -967.58
59 Gross.Profits 109035.17 126735.25 80243.70 99184.62
60 Gross.Losses -95255.78 -103721.46 -72393.99 -89084.97
61 Std.Dev.Daily.PL 197.08 215.29 161.49 193.96
Percent.Positive 54.60 56.10 54.21 51.28
62 Percent.Negative 45.40 43.90 45.79 48.72
63 Profit.Factor 1.14 1.22 1.11 1.11
Avg.Win.Day 140.33 150.70 117.49 150.51
64
Med.Win.Day 111.32 112.94 93.24 116.02
65 Avg.Losing.Day -147.45 -157.63 -125.47 -142.31
66 Med.Losing.Day -103.45 -105.36 -90.08 -108.20
67 Avg.Daily.PL 9.68 15.35 6.23 7.86
68 Med.Daily.PL 17.91 24.89 17.35 6.75
Std.Dev.Daily.PL.1 197.08 215.29 161.49 193.96
69 Ann.Sharpe 0.78 1.13 0.61 0.64
70 Max.Drawdown -4564.52 -4072.32 -5298.53 -4019.55
71 Profit.To.Max.Draw 3.02 5.65 1.48 2.51
72 Avg.WinLoss.Ratio 0.95 0.96 0.94 1.06
73 Med.WinLoss.Ratio 1.08 1.07 1.04 1.07
Max.Equity 13779.39 23910.96 10592.36 12909.83
74 Min.Equity 0.00 0.00 -165.41 -1675.30
75 End.Equity 13779.39 23013.79 7849.71 10099.65
76
77 IGE IYR IYZ LQD RWR
78 Total.Net.Profit 14095.94 12982.75 9649.19 4756.41 11097.68
Total.Days 1461.00 1314.00 1225.00 1350.00 1331.00
79 Winning.Days 793.00 728.00 653.00 718.00 722.00
80 Losing.Days 668.00 586.00 572.00 632.00 609.00
81 Avg.Day.PL 9.65 9.88 7.88 3.52 8.34
82 Med.Day.PL 21.30 16.00 9.14 9.95 13.44
83 Largest.Winner 663.26 578.88 516.66 591.08 614.36
Largest.Loser -819.01 -1139.51 -758.41 -491.67 -1201.72
84 Gross.Profits 116037.20 77715.47 60926.63 64184.63 83589.23
85 Gross.Losses -101941.26 -64732.72 -51277.45 -59428.22 -72491.55
86 Std.Dev.Daily.PL 194.37 150.80 124.66 119.90 164.61
87 Percent.Positive 54.28 55.40 53.31 53.19 54.24
88 Percent.Negative 45.72 44.60 46.69 46.81 45.76
Profit.Factor 1.14 1.20 1.19 1.08 1.15
89 Avg.Win.Day 146.33 106.75 93.30 89.39 115.77
90 Med.Win.Day 118.07 84.95 68.24 72.26 90.32
91 Avg.Losing.Day -152.61 -110.47 -89.65 -94.03 -119.03
92 Med.Losing.Day -115.51 -74.56 -64.29 -74.35 -78.63
Avg.Daily.PL 9.65 9.88 7.88 3.52 8.34
93 Med.Daily.PL 21.30 16.00 9.14 9.95 13.44
94 Std.Dev.Daily.PL.1 194.37 150.80 124.66 119.90 164.61
95 Ann.Sharpe 0.79 1.04 1.00 0.47 0.80
96 Max.Drawdown -3449.65 -4095.25 -2939.04 -3263.55 -4582.43
97 Profit.To.Max.Draw 4.09 3.17 3.28 1.46 2.42
Avg.WinLoss.Ratio 0.96 0.97 1.04 0.95 0.97
98 Med.WinLoss.Ratio 1.02 1.14 1.06 0.97 1.15
99 Max.Equity 14200.07 13142.58 9649.19 5704.58 12750.19
100 Min.Equity -88.76 -257.82 -18.03 -876.30 -336.91
101 End.Equity 14095.94 12982.75 9649.19 4756.41 11097.68
102
SHY TLT XLB XLE XLF
103
Total.Net.Profit 30866.81 7984.42 10276.48 15328.84 2931.55
104 Total.Days 1562.00 1245.00 1331.00 1456.00 1095.00
105 Winning.Days 874.00 644.00 731.00 798.00 570.00
106 Losing.Days 688.00 601.00 600.00 658.00 525.00
107 Avg.Day.PL 19.76 6.41 7.72 10.53 2.68
Med.Day.PL 21.92 10.54 16.37 17.80 7.67
108 Largest.Winner 809.44 1027.71 570.55 843.05 534.17
109 Largest.Loser -975.79 -728.07 -622.80 -1083.92 -930.35
110 Gross.Profits 113467.63 99021.87 80646.28 112733.44 54186.21
111 Gross.Losses -82600.83 -91037.45 -70369.80 -97404.60 -51254.66
112 Std.Dev.Daily.PL 170.13 202.61 148.19 196.05 130.52
Percent.Positive 55.95 51.73 54.92 54.81 52.05
113 Percent.Negative 44.05 48.27 45.08 45.19 47.95
114 Profit.Factor 1.37 1.09 1.15 1.16 1.06
115 Avg.Win.Day 129.83 153.76 110.32 141.27 95.06
116 Med.Win.Day 93.07 115.64 91.77 110.41 74.69
Avg.Losing.Day -120.06 -151.48 -117.28 -148.03 -97.63
117 Med.Losing.Day -92.93 -116.88 -86.95 -105.73 -68.38
118 Avg.Daily.PL 19.76 6.41 7.72 10.53 2.68
Med.Daily.PL 21.92 10.54 16.37 17.80 7.67
119
Std.Dev.Daily.PL.1 170.13 202.61 148.19 196.05 130.52
120 Ann.Sharpe 1.84 0.50 0.83 0.85 0.33
121 Max.Drawdown -3537.22 -4815.13 -3002.83 -3697.94 -3305.04
122 Profit.To.Max.Draw 8.73 1.66 3.42 4.15 0.89
123 Avg.WinLoss.Ratio 1.08 1.02 0.94 0.95 0.97
Med.WinLoss.Ratio 1.00 0.99 1.06 1.04 1.09
124 Max.Equity 31638.96 11680.33 10377.57 16209.04 4685.40
125 Min.Equity -401.25 -1228.87 -87.21 -130.15 -225.91
126 End.Equity 30866.81 7984.42 10276.48 15328.84 2931.55
127
128 XLI XLK XLP XLU XLV
129 Total.Net.Profit 11452.17 5168.06 7233.14 9654.01 1295.79
Total.Days 1323.00 1230.00 1382.00 1348.00 1179.00
130 Winning.Days 731.00 681.00 751.00 735.00 606.00
131 Losing.Days 592.00 549.00 631.00 613.00 573.00
132 Avg.Day.PL 8.66 4.20 5.23 7.16 1.10
133 Med.Day.PL 12.27 15.06 13.67 15.33 5.21
Largest.Winner 667.88 651.97 645.78 544.81 1086.79
134 Largest.Loser -681.83 -702.78 -743.00 -677.52 -784.28
135 Gross.Profits 70933.60 65526.03 68115.23 71114.61 57258.43
136 Gross.Losses -59481.42 -60357.97 -60882.09 -61460.60 -55962.63
137 Std.Dev.Daily.PL 134.55 138.48 123.71 133.61 131.08
138 Percent.Positive 55.25 55.37 54.34 54.53 51.40
Percent.Negative 44.75 44.63 45.66 45.47 48.60
139 Profit.Factor 1.19 1.09 1.12 1.16 1.02
140 Avg.Win.Day 97.04 96.22 90.70 96.75 94.49
141 Med.Win.Day 73.44 75.24 73.21 76.94 77.97
142 Avg.Losing.Day -100.48 -109.94 -96.49 -100.26 -97.67
143 Med.Losing.Day -73.30 -80.20 -73.80 -67.78 -74.02
Avg.Daily.PL 8.66 4.20 5.23 7.16 1.10
144 Med.Daily.PL 12.27 15.06 13.67 15.33 5.21
145 Std.Dev.Daily.PL.1 134.55 138.48 123.71 133.61 131.08
146 Ann.Sharpe 1.02 0.48 0.67 0.85 0.13
147 Max.Drawdown -2288.62 -3136.49 -4108.70 -3440.49 -6294.99
Profit.To.Max.Draw 5.00 1.65 1.76 2.81 0.21
148 Avg.WinLoss.Ratio 0.97 0.88 0.94 0.97 0.97
149 Med.WinLoss.Ratio 1.00 0.94 0.99 1.14 1.05
150 Max.Equity 11458.63 5216.66 7583.26 11588.28 4179.18
151 Min.Equity 0.00 -88.40 0.00 -144.19 -2115.81
152 End.Equity 11452.17 5168.06 7233.14 9654.01 1295.79
153
XLY
154 Total.Net.Profit 4546.69
155 Total.Days 1148.00
156 Winning.Days 603.00
157 Losing.Days 545.00
Avg.Day.PL 3.96
158
Med.Day.PL 9.85
159 Largest.Winner 490.31
160 Largest.Loser -726.59
161 Gross.Profits 54521.44
162 Gross.Losses -49974.75
Std.Dev.Daily.PL 121.37
163 Percent.Positive 52.53
164 Percent.Negative 47.47
165 Profit.Factor 1.09
166 Avg.Win.Day 90.42
167 Med.Win.Day 73.22
Avg.Losing.Day -91.70
168 Med.Losing.Day -69.21
169 Avg.Daily.PL 3.96
170 Med.Daily.PL 9.85
171 Std.Dev.Daily.PL.1 121.37
Ann.Sharpe 0.52
172 Max.Drawdown -3508.84
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192 Profit.To.Max.Draw 1.30
193 Avg.WinLoss.Ratio 0.99
194 Med.WinLoss.Ratio 1.06
195 Max.Equity 4986.43
Min.Equity 0.00
196
End.Equity 4546.69
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
Compared to the previous equity curve, the drawdowns here are more pronounced. So how much do we pay
for having this higher set it and forget it holding period?

1
> SharpeRatio.annualized(portfRets)
2 [,1]
3 Annualized Sharpe Ratio (Rf=0%) 1.099297
4 > Return.annualized(portfRets)
5 [,1]
Annualized Return 0.1393566
6 > maxDrawdown(portfRets)
7 [1] 0.183505
8

Turns out, a fair bit. The Sharpe Ratio comes down quite a bit, the returns are slightly lower, but the
drawdown is much higher, crossing back under that boundary of annualized returns higher than maximum
drawdown. Of course, this isnt all attributable to stale ATR calculations, as order sizing and rebalancing
wont save a strategy from holding onto bad trades, but not rebalancing certainly does nobody any favors at
the longer holding timeframes.

Heres a picture of a single instrument, length of positions, and the indicators.


Would it have been nice to have some rebalancing for those longer timeframe trades? Yep.

Finally, is the equity curve comparison taken further, to the original 100-day period.

And the corresponding three statistics:

1
> SharpeRatio.annualized(portfRets)
2 [,1]
3 Annualized Sharpe Ratio (Rf=0%) 0.8681733
4 > Return.annualized(portfRets)
5 [,1]
Annualized Return 0.1366685
6 > maxDrawdown(portfRets)
7 [1] 0.2241631
8
Definitely not a good look. Sharpe back under 1, and drawdowns at more than 20%? What kind of returns
can we get for such drawdowns? Wait until the end of the post, and Ill show you.

The beginning of the volatility preceding the financial crisis caused some violent drawdowns (notice the
actual bear market didnt cause so much). Could some of this damage have been mitigated?

The answer? Certainly (see the monotonic rise in ATR in 2007).

So, with all of this in mind, as promised, lets see what sort of returns we can get for the 20 day period.

What if we took our original portfolio, and simply doubled the risk allocationin other words, leveraged the
original strategy 2:1?

Heres the one line change:

1 #parameters (trigger lag unchanged, defaulted at 1)


2 delta=0
3 period=20
pctATR=.04 #control risk with this parameter
4

Well, this is what happens:


And the statistics:

1
> SharpeRatio.annualized(portfRets)
2 [,1]
3 Annualized Sharpe Ratio (Rf=0%) 1.465359
4 > Return.annualized(portfRets)
5 [,1]
Annualized Return 0.3088355
6 > maxDrawdown(portfRets)
7 [1] 0.2109036
8

About 31% annualized returns, with slightly over 20% drawdowns. Considering that the stock market has
much higher drawdowns, this is a pretty good risk-return profile. If were willing to go above 30%
drawdown, this is the resulting equity curve:

At this point, the equity curve for SPY becomes almost a flat line by comparisonnot because its drawdowns
are smaller (at the height of the crisis, they were over 60%), but because of proper position sizing. Here are
the corresponding three statistics:
1
> SharpeRatio.annualized(portfRets)
2 [,1]
3 Annualized Sharpe Ratio (Rf=0%) 1.493416
4 > Return.annualized(portfRets)
5 [,1]
Annualized Return 0.4722279
6
> maxDrawdown(portfRets)
7 [1] 0.3022385
8

Of course, beyond this point, if one is willing to tolerate drawdowns, the annualized returns just start to get
silly, but the drawdowns start to really show in 2010, when the fact that this systems exits could still be
improved, and its instrument selection (with a base correlation across all instruments of .7) starts quickly
putting on the brakes on going beyond this point. For now anyway.

Thanks for reading.

Trend Vigor Part IIthe Delta parameter, Ehlers


entries and exits, and (vaguely) intelligent
portfolio management.
Posted on May 29, 2014 Posted in Dr. John Ehlers, ETFs, QuantStrat, R, Trading, Uncategorized Tagged
R Leave a comment

The last post gave a cursory overview of implementing a basic quantstrat strategy, and an introduction to Dr.
Ehlerss Trend Vigor indicator, with a less than intelligent exit. This post will delve further into this
indicator, and how it can be made to act as a long-term trend follower to a short-term momentum trader, to
probably anything in between, with a parameter called delta. Dr. Ehlerss indicators often use some
trigonometric math, the rationale of which is based on signal processing theory, and often times, that math
uses a user-input parameter denoted by a Greek letter, such as alpha, gamma, delta, and so forth.

Rather than leave these esoteric parameters completely unexplored, out of sheer curiosity, I decided to alter
the delta parameter. By tuning the delta parameter, its possible to tune how fast Trend Vigor oscillates, and
thereby, how fast it judges that newer observations are part of a new trend (but at the same time, how much
longer the indicator classifies a trend as ongoing). This would allow a user to tune the Trend Vigor indicator
in a similar fashion as other trend following indicators to capture different sorts of market phenomena, such
as long term trend-following/filtering, to shorter-term phenomena. On the *downside*, this means that as a
user tunes the period and the delta, that he or she could easily overfit.

Furthermore, this blog post is going to make the portfolio analysis portion of the analytics make far more
sense than a roughly-sketched, price-weighted equity curve. The results were that the benefits of
diversification werecertainly less than expected. This backtest is going to implement an equal-weight
asset allocation scheme, which will also showcase that quantstrat can implement custom order-sizing
functions. Equal-weight asset allocation schemes can be improved upon, but thats a discussion for a future
time.

The strategy for this blog post is slightly different, as well. In this case, the strategy will use a more
intelligent exit, by selling when the indicator crosses under its one-day lagged trigger, and buying not only
when the indicator crosses above 1, but also if it should cross over its one-day lagged computation, but still
be above 1. This is so that the strategy would stay in what it perceives as a trend, rather than sell and not
come back until the computation dipped back below 1 (an arbitrary value, to be sure) and came back up
again. The idea for the exit came from one of Dr. Ehlerss presentations, in which he presented several more
trend-following smoothers, some of which are already in the DSTrading package (FRAMA, KAMA,
VIDYA which I call VIDA, and the Ehlers filters), and which Ill visit in the future. The link to the
presentation can be found here:

http://www.mesasoftware.com/Seminars/TradeStation%20World%2005.pdf

One last detail to mind is that between the last blog post and this one, I changed the Trend Vigor indicator to
backfill any leading NAs as zero, since this is an indicator centered around zero. This will allow the strategy
to instantly jump into the middle of a trend, if one was under way the moment the first true value of the
indicator was computed.

My custom order-sizing function is found in my IKTrading package, which is my own personal collection of
non-Ehlers indicators, miscellaneous tools, custom order-sizing functions, and generally serves as a catch-all
for trading ideas I come across that dont have enough content behind them to warrant a package of their
own.

Lets look at the code of the updated indicator.

First, the updated Trend Vigor indicator:

1 "TVI" <- function(x, period=20, delta=.2, triggerLag=1, ...) {


if(period!=0) { #static, length-1 period
2
beta <- cos(2*pi/period)
3 gamma <- 1/cos(4*pi*delta/period)
4 alpha <- gamma - sqrt(gamma*gamma-1)
5 BP <- .5*(1-alpha)*(x-lag(x,2))
6 BP[1] <- BP[2] <- 0
BP <- filter(BP, c(beta*(1+alpha),-1*alpha),method="recursive")
7 BP <- xts(BP, order.by=index(x))
8 signal <- BP - lag(BP, round(period/2))
9 lead <- 1.4*(BP-lag(BP, round(period/4)))
10
11 BP2 <- BP*BP
12 LBP2 <- lag(BP2, round(period/4))
power <- runSum(BP2, period)+runSum(LBP2, period)
13 RMS <- sqrt(power/period)
14 PtoP <- 2*sqrt(2)*RMS
15
16 a1 <- exp(-sqrt(2)*pi/period)
17 b1 <- 2*a1*cos(sqrt(2)*pi/period)
18 coef2 <- b1
coef3 <- -a1*a1
19 coef1 <- 1-coef2-coef3
20 trend <- coef1*(x-lag(x, period))
21 trend[is.na(trend)] <- 0
22 trend <- filter(trend, c(coef2, coef3), method="recursive")
trend <- xts(trend, order.by=index(x))
23 vigor <- trend/PtoP
24 vigor[vigor > 2] <- 2
25 vigor[vigor < -2] <- -2
26 vigor[is.na(vigor)] <- 0
27 trigger <- lag(vigor, triggerLag)
out <- cbind(vigor, signal, lead, trigger)
28 colnames(out) <- c("vigor", "signal", "lead", "trigger")
29 return(out)
30 } else {
31 stop("Dynamic period computation not implemented yet.")
#TODO -- DYNAMIC PERIOD TREND VIGOR
32
}
33 }
34
35
36
37
38
39
40

Delta is a parameter involved in an involved trigonometric calculation, lending to the idea that there may be
some sort of circular relationship with delta, rather than simply a trend sensitivity as I described. That
stated, considering that the default value that Dr. Ehlers used was .2, it implies that the parameter should
probably be held between 0 and 1. Once beyond that, theres no guarantee that the algorithm even runs (at
some point, it will just make later computations come out as NaNs).

Next, Id like to introduce a couple of functions from my IKTrading package.

1 sigAND <- function(label, data=mktdata, columns, cross = FALSE) {


ret_sig = NULL
2
colNums <- rep(0, length(columns))
3 for(i in 1:length(columns)) {
4 colNums[i] <- match.names(columns[i], colnames(data))
5 }
6 ret_sig <- data[, colNums[1]]
for(i in 2:length(colNums)) {
7 ret_sig <- ret_sig & data[, colNums[i]]
8 }
9 ret_sig <- ret_sig*1
10 if (isTRUE(cross))
11 ret_sig <- diff(ret_sig) == 1
colnames(ret_sig) <- label
12 return(ret_sig)
13 }
14
15 osMaxDollar <- function(data, timestamp, orderqty, ordertype, orderside,
16 portfolio, symbol, prefer="Open", tradeSize,
maxSize, integerQty=TRUE,
17 ...) {
18 pos <- getPosQty(portfolio, symbol, timestamp)
19 if(prefer=="Close") {
20 price <- as.numeric(Cl(mktdata[timestamp,]))
21 } else {
price <- as.numeric(Op(mktdata[timestamp,]))
22 }
23 posVal <- pos*price
24 if (orderside=="short") {
25 dollarsToTransact <- max(tradeSize, maxSize-posVal)
26 #If our position is profitable, we don't want to cover needlessly.
if(dollarsToTransact > 0) {dollarsToTransact=0}
27 } else {
28 dollarsToTransact <- min(tradeSize, maxSize-posVal)
29 #If our position is profitable, we don't want to sell needlessly.
30 if(dollarsToTransact < 0) {dollarsToTransact=0}
}
31 qty <- dollarsToTransact/price
32 if(integerQty) {
33 qty <- trunc(qty)
34 }
35 return(qty)
}
36
37
38
39
40
41
42
43

The first function is a basic AND operator for signals in quantstrat. While quantstrat itself has a signal
function called sigFormula, I myself am not exactly a fan of it. The second function, however, is a bit more
innovative, in that it allows a strategy to control positions by their total current dollar value. What it doesnt
do, however, is remember the initial dollar value of a position. That is, if you invested $10,000, with a limit
of $20,000 in a position, and your initial position went to $11,000, this function would only allow up to
another $9,000 worth of the instrument to be ordered. Negative quantities should be used for shorting. That
is, if the goal is to short a security, rather than input 20000 as the maxSize and 10000 as the tradeSize, the
parameters should be -20000 and -10000, respectively.

Again, the order sizing function takes into account the value of the position at the time of a new order, not
the original value of the transaction. That is, the function does not do this: You have an existing position
that you entered into at some previous date, and your position then was $10,000, but now its $15,000, but
Ill order another $10,000 anyway. The function currently does this: You have a position with a current
market value of $15,000. You want to add $10,000 to your position, but have a limit of $20,000. Ill order
the nearest integer quantity to the difference ($5,000).

Moving on, heres the modified strategy.

1 require(DSTrading)
2 require(IKTrading)
require(quantstrat)
3
4
5 #to rerun the strategy, rerun everything below this line
6 source("demoData.R") #contains all of the data-related boilerplate.
7
8 #trade sizing and initial equity settings
9 tradeSize <- 10000
initEq <- tradeSize*length(symbols)
10
11 strategy.st <- portfolio.st <- account.st <- "TVI_TF_2"
12 rm.strat(portfolio.st)
13 rm.strat(strategy.st)
14 initPortf(portfolio.st, symbols=symbols, initDate=initDate, currency='USD')
15 initAcct(account.st, portfolios=portfolio.st, initDate=initDate,
currency='USD',initEq=initEq)
16 initOrders(portfolio.st, initDate=initDate)
17 strategy(strategy.st, store=TRUE)
18
19 #parameters (trigger lag unchanged, defaulted at 1)
20 delta=.2
21 period=100
22 #indicators
23 add.indicator(strategy.st, name="TVI", arguments=list(x=quote(Cl(mktdata)),
24 period=period, delta=delta), label="TVI")
25
26 #signals
27 add.signal(strategy.st, name="sigThreshold",
arguments=list(threshold=1, column="vigor.TVI",
28 relationship="gte", cross=FALSE),
29 label="TVIgtThresh")
30 add.signal(strategy.st, name="sigComparison",
31 arguments=list(columns=c("vigor.TVI","trigger.TVI"),
32 relationship="gt"),
label="TVIgtLag")
33 add.signal(strategy.st, name="sigAND",
34 arguments=list(columns=c("TVIgtThresh","TVIgtLag"),
35 cross=TRUE),
36
37
38
39
40
41 label="longEntry")
42 add.signal(strategy.st, name="sigCrossover",
43 arguments=list(columns=c("vigor.TVI","trigger.TVI"),
44 relationship="lt"),
label="longExit")
45
46 #rules
47 add.rule(strategy.st, name="ruleSignal",
48 arguments=list(sigcol="longEntry", sigval=TRUE, orderqty=100,
49 ordertype="market", orderside="long",
replace=FALSE, prefer="Open", osFUN=osMaxDollar,
50 tradeSize=10000, maxSize=10000),
51 type="enter", path.dep=TRUE)
52
53 add.rule(strategy.st, name="ruleSignal",
54 arguments=list(sigcol="longExit", sigval=TRUE, orderqty="all",
55 ordertype="market", orderside="long", replace=FALSE,
prefer="Open"),
56 type="exit", path.dep=TRUE)
57
58
59 #apply strategy
60 t1 <- Sys.time()
61 out <- applyStrategy(strategy=strategy.st,portfolios=portfolio.st)
62 t2 <- Sys.time()
print(t2-t1)
63
64 #set up analytics
65 updatePortf(portfolio.st)
66 dateRange <- time(getPortfolio(portfolio.st)$summary)[-1]
67 updateAcct(portfolio.st,dateRange)
68 updateEndEq(account.st)
69
70
71
72
73

For the moment, were going to go with the previous settings of delta = .2, and period = 100, but this time,
using an order size of the nearest integer quantity that $10,000 can buy of that particular security. Also,
were going to exit when the indicator shifts from moving up or flat (if its at 2), to downward, and buying
whenever it shifts from moving downward to moving upward (but still has a value above 1). Also, note that
now, there is an initial equity allocation, which will allow for the computation of portfolio returns.

Here are the results.

Trade Stats:

1 #tradeStats
2 tStats <- tradeStats(Portfolios = portfolio.st, use="trades", inclZeroDays=FALSE)
3 tStats[,4:ncol(tStats)] <- round(tStats[,4:ncol(tStats)], 2)
print(data.frame(t(tStats[,-c(1,2)])))
4
1 EFA EPP EWA EWC EWG
Num.Txns 21.00 15.00 27.00 37.00 17.00
2
Num.Trades 11.00 8.00 14.00 19.00 9.00
3 Net.Trading.PL 3389.91 6323.15 6933.26 2213.97 4983.35
Avg.Trade.PL 308.17 790.39 495.23 116.52 553.71
4
Med.Trade.PL 298.45 549.42 107.35 110.98 206.57
5 Largest.Winner 869.60 2507.07 3410.61 1607.61 2600.90
6 Largest.Loser -297.25 -675.35 -452.79 -1191.14 -343.19
7 Gross.Profits 4073.17 7327.60 8446.23 5734.53 5847.80
8 Gross.Losses -683.26 -1004.45 -1512.97 -3520.55 -864.45
Std.Dev.Trade.PL 425.12 1189.75 1118.82 648.91 957.64
9 Percent.Positive 72.73 62.50 57.14 63.16 66.67
10 Percent.Negative 27.27 37.50 42.86 36.84 33.33
11 Profit.Factor 5.96 7.30 5.58 1.63 6.76
12 Avg.Win.Trade 509.15 1465.52 1055.78 477.88 974.63
13 Med.Win.Trade 485.27 1680.62 448.04 313.63 747.17
Avg.Losing.Trade -227.75 -334.82 -252.16 -502.94 -288.15
14 Med.Losing.Trade -266.17 -184.29 -220.96 -440.34 -274.72
15 Avg.Daily.PL 323.18 923.99 490.48 82.59 657.26
16 Med.Daily.PL 305.15 1057.21 54.49 100.34 465.90
17 Std.Dev.Daily.PL 445.03 1218.54 1164.36 650.14 968.40
Ann.Sharpe 11.53 12.04 6.69 2.02 10.77
18 Max.Drawdown -1730.57 -2428.18 -2827.76 -3214.22 -2070.43
19 Profit.To.Max.Draw 1.96 2.60 2.45 0.69 2.41
20 Avg.WinLoss.Ratio 2.24 4.38 4.19 0.95 3.38
21 Med.WinLoss.Ratio 1.82 9.12 2.03 0.71 2.72
22 Max.Equity 3785.99 8030.74 7734.21 4215.37 5775.50
Min.Equity -4.60 -186.62 -399.56 -272.20 -97.78
23 End.Equity 3389.91 6323.15 6933.26 2213.97 4983.35
24
25 EWH EWJ EWS EWT EWU
26 Num.Txns 17.00 19.00 21.00 23.00 24.00
27 Num.Trades 9.00 10.00 11.00 12.00 12.00
28 Net.Trading.PL 6281.71 1861.09 8115.03 1920.39 1113.36
Avg.Trade.PL 697.97 186.11 737.73 160.03 92.78
29 Med.Trade.PL 760.09 18.58 312.10 -180.82 -0.03
30 Largest.Winner 2223.08 2555.03 2736.35 3078.42 1243.53
31 Largest.Loser -496.03 -1392.37 -531.77 -1219.88 -1009.85
32 Gross.Profits 7214.77 4666.47 9381.95 6413.88 3747.87
Gross.Losses -933.06 -2805.38 -1266.92 -4493.49 -2634.51
33 Std.Dev.Trade.PL 959.96 1123.51 1178.37 1280.43 695.45
34 Percent.Positive 66.67 60.00 63.64 33.33 50.00
35 Percent.Negative 33.33 40.00 36.36 66.67 50.00
36 Profit.Factor 7.73 1.66 7.41 1.43 1.42
37 Avg.Win.Trade 1202.46 777.75 1340.28 1603.47 624.64
Med.Win.Trade 1046.89 314.63 1388.79 1505.03 541.51
38 Avg.Losing.Trade -311.02 -701.35 -316.73 -561.69 -439.08
39 Med.Losing.Trade -434.34 -591.09 -287.07 -478.14 -358.87
40 Avg.Daily.PL 785.55 142.07 780.29 69.58 92.78
41 Med.Daily.PL 857.90 6.87 291.84 -320.95 -0.03
Std.Dev.Daily.PL 987.05 1182.47 1233.16 1302.09 695.45
42
Ann.Sharpe 12.63 1.91 10.04 0.85 2.12
43 Max.Drawdown -2240.59 -3140.49 -2181.89 -4191.97 -2682.76
44 Profit.To.Max.Draw 2.80 0.59 3.72 0.46 0.42
45 Avg.WinLoss.Ratio 3.87 1.11 4.23 2.85 1.42
46 Med.WinLoss.Ratio 2.41 0.53 4.84 3.15 1.51
Max.Equity 7033.54 3474.11 8268.38 3740.33 3093.03
47 Min.Equity -101.98 -7.71 -715.49 -451.64 -298.31
48 End.Equity 6281.71 1861.09 8115.03 1920.39 1113.36
49
50 EWY EWZ EZU IEF IGE
51 Num.Txns 23.00 30.00 18.00 24.00 31.00
52 Num.Trades 12.00 15.00 9.00 12.00 16.00
Net.Trading.PL 11094.89 11017.62 3581.04 558.64 1425.90
53 Avg.Trade.PL 924.57 734.51 397.89 46.55 89.12
54 Med.Trade.PL 517.60 474.34 334.80 -21.76 -12.94
55 Largest.Winner 3654.10 3907.76 1415.98 544.99 2085.48
56 Largest.Loser -497.47 -1034.75 -442.68 -286.86 -1357.10
Gross.Profits 12382.75 14795.36 4311.30 1551.73 5886.15
57 Gross.Losses -1287.86 -3777.74 -730.26 -993.09 -4460.25
58 Std.Dev.Trade.PL 1396.50 1528.15 616.20 276.42 860.95
59 Percent.Positive 66.67 60.00 66.67 50.00 50.00
Percent.Negative 33.33 40.00 33.33 50.00 50.00
60 Profit.Factor 9.61 3.92 5.90 1.56 1.32
61 Avg.Win.Trade 1547.84 1643.93 718.55 258.62 735.77
62 Med.Win.Trade 1239.91 1050.52 707.66 245.34 614.69
63 Avg.Losing.Trade -321.97 -629.62 -243.42 -165.52 -557.53
Med.Losing.Trade -312.32 -654.53 -144.05 -161.22 -478.79
64 Avg.Daily.PL 946.10 734.51 397.89 46.55 29.55
65 Med.Daily.PL 347.37 474.34 334.80 -21.76 -95.89
66 Std.Dev.Daily.PL 1462.58 1528.15 616.20 276.42 856.36
67 Ann.Sharpe 10.27 7.63 10.25 2.67 0.55
68 Max.Drawdown -3706.83 -4468.28 -1746.39 -1033.18 -4134.77
Profit.To.Max.Draw 2.99 2.47 2.05 0.54 0.34
69 Avg.WinLoss.Ratio 4.81 2.61 2.95 1.56 1.32
70 Med.WinLoss.Ratio 3.97 1.60 4.91 1.52 1.28
71 Max.Equity 11151.40 14325.48 4132.73 1324.33 3847.27
72 Min.Equity -512.94 -669.31 -127.83 -496.42 -360.99
73 End.Equity 11094.89 11017.62 3581.04 558.64 1425.90
74 IYR IYZ LQD RWR SHY
75 Num.Txns 20.00 21.00 26.00 18.00 20.00
76 Num.Trades 10.00 10.00 13.00 9.00 10.00
77 Net.Trading.PL 3551.70 565.56 278.51 3846.21 1431.72
78 Avg.Trade.PL 355.17 56.56 21.42 427.36 143.17
Med.Trade.PL 285.85 -171.99 17.47 340.07 28.08
79 Largest.Winner 1457.62 1789.36 435.59 1465.93 1298.58
80 Largest.Loser -397.79 -832.16 -516.47 -611.82 -79.25
81 Gross.Profits 4524.52 2743.13 1145.51 4698.97 1605.02
82 Gross.Losses -972.82 -2177.58 -867.00 -852.76 -173.30
83 Std.Dev.Trade.PL 623.44 729.51 238.26 665.66 410.76
Percent.Positive 70.00 30.00 69.23 77.78 60.00
84 Percent.Negative 30.00 70.00 30.77 22.22 40.00
85 Profit.Factor 4.65 1.26 1.32 5.51 9.26
86 Avg.Win.Trade 646.36 914.38 127.28 671.28 267.50
87 Med.Win.Trade 497.94 737.25 32.03 531.59 55.68
88 Avg.Losing.Trade
Med.Losing.Trade
-324.27 -311.08 -216.75 -426.38 -43.32
-298.46 -242.80 -165.48 -426.38 -34.23
89 Avg.Daily.PL 355.17 -19.08 21.42 427.36 143.17
90 Med.Daily.PL 285.85 -211.89 17.47 340.07 28.08
91 Std.Dev.Daily.PL 623.44 730.99 238.26 665.66 410.76
92 Ann.Sharpe 9.04 -0.41 1.43 10.19 5.53
Max.Drawdown -2117.09 -2239.16 -853.57 -2500.81 -206.62
93 Profit.To.Max.Draw 1.68 0.25 0.33 1.54 6.93
94 Avg.WinLoss.Ratio 1.99 2.94 0.59 1.57 6.17
95 Med.WinLoss.Ratio 1.67 3.04 0.19 1.25 1.63
96 Max.Equity 4939.41 1994.72 729.12 5125.30 1496.21
97 Min.Equity 0.00 -803.23 -815.95 0.00 -178.23
End.Equity 3551.70 565.56 278.51 3846.21 1431.72
98
99 TLT XLB XLE XLF XLI
100 Num.Txns 24.00 23.00 35.00 22.00 25.00
101 Num.Trades 12.00 12.00 18.00 11.00 13.00
102 Net.Trading.PL 1685.94 6026.21 -721.62 1073.90 3270.62
103 Avg.Trade.PL 140.49 502.18 -40.09 97.63 251.59
Med.Trade.PL 43.43 511.49 -148.36 53.82 -3.41
104 Largest.Winner 1244.42 2158.21 2243.05 1390.72 1358.00
105 Largest.Loser -595.88 -750.40 -1151.80 -659.29 -378.11
106 Gross.Profits 2725.69 7456.59 4402.78 2346.46 4152.62
107 Gross.Losses -1039.76 -1430.38 -5124.39 -1272.56 -882.00
Std.Dev.Trade.PL 468.08 819.50 771.46 512.62 512.44
108 Percent.Positive 58.33 66.67 22.22 63.64 46.15
109 Percent.Negative 41.67 33.33 77.78 36.36 53.85
110 Profit.Factor 2.62 5.21 0.86 1.84 4.71
111 Avg.Win.Trade 389.38 932.07 1100.69 335.21 692.10
112 Med.Win.Trade 195.01 997.33 857.45 226.90 589.41
Avg.Losing.Trade -207.95 -357.59 -366.03 -318.14 -126.00
113 Med.Losing.Trade -100.91 -301.05 -193.50 -239.29 -59.12
114 Avg.Daily.PL 140.49 499.71 -97.77 97.63 241.51
Med.Daily.PL 43.43 511.49 -152.39 53.82 -18.57
115 Std.Dev.Daily.PL 468.08 887.28 754.14 512.62 533.87
116 Ann.Sharpe 4.76 8.94 -2.06 3.02 7.18
117 Max.Drawdown -2020.60 -2343.85 -5364.07 -1497.18 -1480.30
118 Profit.To.Max.Draw 0.83 2.57 -0.13 0.72 2.21
Avg.WinLoss.Ratio 1.87 2.61 3.01 1.05 5.49
119 Med.WinLoss.Ratio 1.93 3.31 4.43 0.95 9.97
120 Max.Equity 3278.94 6034.85 3638.56 2209.75 4344.89
121 Min.Equity -1033.35 -234.71 -1725.52 -353.34 0.00
122 End.Equity 1685.94 6026.21 -721.62 1073.90 3270.62
123
124 XLK XLP XLU XLV XLY
Num.Txns 25.00 25.00 16.00 21.00 21.00
125 Num.Trades 13.00 12.00 8.00 11.00 11.00
126 Net.Trading.PL 2786.08 1691.84 2071.68 329.36 1596.47
127 Avg.Trade.PL 214.31 140.99 258.96 29.94 145.13
128 Med.Trade.PL 19.79 27.51 -175.95 -152.51 42.65
129 Largest.Winner
Largest.Loser
2153.72 1339.05 2416.22 1492.98 914.92
-586.52 -1482.72 -1180.81 -511.62 -228.81
130 Gross.Profits 4276.67 3888.90 4456.67 2179.92 1974.22
131 Gross.Losses -1490.59 -2197.06 -2385.00 -1850.56 -377.75
132 Std.Dev.Trade.PL 687.96 747.73 1254.25 552.25 310.09
133 Percent.Positive 53.85 50.00 37.50 36.36 63.64
Percent.Negative 46.15 50.00 62.50 63.64 36.36
134 Profit.Factor 2.87 1.77 1.87 1.18 5.23
135 Avg.Win.Trade 610.95 648.15 1485.56 544.98 282.03
136 Med.Win.Trade 437.51 594.68 1966.92 301.18 180.59
137 Avg.Losing.Trade -248.43 -366.18 -477.00 -264.37 -94.44
138 Med.Losing.Trade -220.94 -132.84 -397.83 -238.91 -73.86
Avg.Daily.PL 195.71 125.23 258.96 10.26 149.62
139 Med.Daily.PL -14.41 -24.11 -175.95 -187.75 39.16
140 Std.Dev.Daily.PL 715.13 782.14 1254.25 578.04 326.49
141 Ann.Sharpe 4.34 2.54 3.28 0.28 7.28
142 Max.Drawdown -1984.37 -2106.40 -2360.48 -1327.16 -1540.71
143 Profit.To.Max.Draw
Avg.WinLoss.Ratio
1.40
2.46
0.80
1.77
0.88
3.11
0.25
2.06
1.04
2.99
144 Med.WinLoss.Ratio 1.98 4.48 4.94 1.26 2.45
145 Max.Equity 2883.68 2116.10 4325.65 653.11 2920.67
146 Min.Equity -739.92 -49.59 -1004.33 -1293.46 -393.05
147 End.Equity 2786.08 1691.84 2071.68 329.36 1596.47
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

Already, we can see that the equal dollar weighting scheme may not have been the greatest. For instance, the
gross profits (that is, total dollars gained, not net profit) vary wildly. For instance, the command:

1 summary(tStats$Gross.Profit)

Gives the output:

1 Min. 1st Qu. Median Mean 3rd Qu. Max.


2 1146 2994 4430 5145 6282 14800

Which means that either a few instruments were just fortunate, or more likely, that $10,000 in different
instruments buys different levels of risk. Ideally, with trend following (or any investment strategy, for that
matter), order sizing should be done with some measure of volatility in mind. Jeff Swanson of System
Trader Success uses position sizing scaled with ATR, for instance.

Moving on, here are the daily stats.

1#dailyStats
2dStats <- dailyStats(Portfolios = portfolio.st, use="Equity")
3rownames(dStats) <- gsub(".DailyEndEq","", rownames(dStats))
4print(data.frame(t(dStats)))
1 EFA EPP EWA
EWC EWG
2
Total.Net.Profit 3389.91 6323.15 6933.26
3 2213.97 4983.35
4 Total.Days 715.00 860.00 814.00
5 720.00 606.00
6 Winning.Days 397.00 472.00 457.00
394.00 337.00
7 Losing.Days 318.00 388.00 357.00
8 326.00 269.00
9 Avg.Day.PL 4.74 7.35 8.52
10 3.07 8.22
11 Med.Day.PL 11.05 13.86 24.93
16.08 17.82
12 Largest.Winner 349.71 520.81 651.16
13 383.73 430.91
14 Largest.Loser -441.39 -658.33 -737.68
15 -533.75 -511.74
Gross.Profits 29341.17 51407.19 56127.72 35108.16
16 35014.78
17 Gross.Losses -25951.26 -45084.04 -49194.46 -32894.18
18 -30031.43
19 Std.Dev.Daily.PL 101.85 151.01 173.50
20 121.89 138.19
Percent.Positive 55.52 54.88 56.14
21 54.72 55.61
22 Percent.Negative 44.48 45.12 43.86
45.28 44.39
23
Profit.Factor 1.13 1.14 1.14
24 1.07 1.17
25 Avg.Win.Day 73.91 108.91 122.82
26 89.11 103.90
27 Med.Win.Day 62.74 87.40 100.18
76.90 86.18
28 Avg.Losing.Day -81.61 -116.20 -137.80
29 -100.90 -111.64
30 Med.Losing.Day -60.59 -76.11 -98.03
31 -70.68 -84.29
32 Avg.Daily.PL 4.74 7.35 8.52
3.07 8.22
33 Med.Daily.PL 11.05 13.86 24.93
34 16.08 17.82
35 Std.Dev.Daily.PL.1 101.85 151.01 173.50
36 121.89 138.19
Ann.Sharpe 0.74 0.77 0.78
37 0.40 0.94
38 Max.Drawdown -1730.57 -2428.18 -2827.76 -3214.22
39 -2070.43
40 Profit.To.Max.Draw 1.96 2.60 2.45
41 0.69 2.41
Avg.WinLoss.Ratio 0.91 0.94 0.89
42 0.88 0.93
43 Med.WinLoss.Ratio 1.04 1.15 1.02
44 1.09 1.02
45 Max.Equity 3785.99 8030.74 7734.21
46 4215.37 5775.50
Min.Equity -4.60 -186.62 -399.56
47 -272.20 -97.78
48 End.Equity 3389.91 6323.15 6933.26
49 2213.97 4983.35
50
51 EWH EWJ EWS
EWT EWU
52 Total.Net.Profit 6281.71 1861.09 8115.03
53 1920.39 1113.36
54 Total.Days 694.00 499.00 853.00
55 554.00 639.00
56 Winning.Days 365.00 264.00 469.00
282.00 336.00
57 Losing.Days 329.00 235.00 384.00
58 272.00 303.00
59 Avg.Day.PL 9.05 3.73 9.51
60 3.47 1.74
Med.Day.PL 13.35 13.75 19.75
61
8.49 9.84
62 Largest.Winner 793.54 550.75 760.20
63 603.79 393.65
64 Largest.Loser -821.31 -560.56 -967.53
65 -606.81 -500.81
Gross.Profits 49928.51 29574.53 56989.19 36177.69
66 28874.40
67 Gross.Losses -43646.80 -27713.44 -48874.16 -34257.30
68 -27761.04
69 Std.Dev.Daily.PL 184.78 146.73 167.87
70 164.58 114.57
Percent.Positive 52.59 52.91 54.98
71 50.90 52.58
72 Percent.Negative 47.41 47.09 45.02
73 49.10 47.42
74 Profit.Factor 1.14 1.07 1.17
1.06 1.04
75 Avg.Win.Day 136.79 112.02 121.51
76 128.29 85.94
77 Med.Win.Day 103.78 94.05 89.94
110.89 72.42
78
Avg.Losing.Day -132.67 -117.93 -127.28
79 -125.95 -91.62
80 Med.Losing.Day -93.35 -86.26 -98.90
81 -88.80 -69.88
82 Avg.Daily.PL 9.05 3.73 9.51
3.47 1.74
83 Med.Daily.PL 13.35 13.75 19.75
84 8.49 9.84
85 Std.Dev.Daily.PL.1 184.78 146.73 167.87
86 164.58 114.57
87 Ann.Sharpe 0.78 0.40 0.90
0.33 0.24
88 Max.Drawdown -2240.59 -3140.49 -2181.89 -4191.97
89 -2682.76
90 Profit.To.Max.Draw 2.80 0.59 3.72
91 0.46 0.42
Avg.WinLoss.Ratio 1.03 0.95 0.95
92 1.02 0.94
93 Med.WinLoss.Ratio 1.11 1.09 0.91
94 1.25 1.04
95 Max.Equity 7033.54 3474.11 8268.38
96 3740.33 3093.03
Min.Equity -101.98 -7.71 -715.49
97 -451.64 -298.31
98 End.Equity 6281.71 1861.09 8115.03
99 1920.39 1113.36
100
101 EWY EWZ EZU
102 IEF IGE
Total.Net.Profit 11094.89 11017.62 3581.04
103 558.64 1425.90
104 Total.Days 819.00 938.00 625.00
105 559.00 636.00
106 Winning.Days 457.00 521.00 348.00
282.00 347.00
107 Losing.Days 362.00 417.00 277.00
108 277.00 289.00
109 Avg.Day.PL 13.55 11.75 5.73
110 1.00 2.24
111 Med.Day.PL 28.70 27.38 14.64
1.17 17.39
112 Largest.Winner 802.78 921.65 339.49
113 203.78 400.87
114 Largest.Loser -713.20 -983.67 -593.68
115 -193.81 -486.10
Gross.Profits 70050.73 98473.12 30606.55 11313.46
116
36042.39
117 Gross.Losses -58955.83 -87455.50 -27025.51 -10754.82
118 -34616.50
119 Std.Dev.Daily.PL 206.98 261.11 121.98
120 52.18 138.92
Percent.Positive 55.80 55.54 55.68
121 50.45 54.56
122 Percent.Negative 44.20 44.46 44.32
123 49.55 45.44
124 Profit.Factor 1.19 1.13 1.13
125 1.05 1.04
Avg.Win.Day 153.28 189.01 87.95
126 40.12 103.87
127 Med.Win.Day 124.00 151.02 70.52
128 33.60 90.45
129 Avg.Losing.Day -162.86 -209.73 -97.57
-38.83 -119.78
130 Med.Losing.Day -112.49 -157.93 -69.01
131 -28.87 -100.54
132 Avg.Daily.PL 13.55 11.75 5.73
1.00 2.24
133
Med.Daily.PL 28.70 27.38 14.64
134 1.17 17.39
135 Std.Dev.Daily.PL.1 206.98 261.11 121.98
136 52.18 138.92
137 Ann.Sharpe 1.04 0.71 0.75
0.30 0.26
138 Max.Drawdown -3706.83 -4468.28 -1746.39 -1033.18
139 -4134.77
140 Profit.To.Max.Draw 2.99 2.47 2.05
141 0.54 0.34
142 Avg.WinLoss.Ratio 0.94 0.90 0.90
1.03 0.87
143 Med.WinLoss.Ratio 1.10 0.96 1.02
144 1.16 0.90
145 Max.Equity 11151.40 14325.48 4132.73
146 1324.33 3847.27
Min.Equity -512.94 -669.31 -127.83
147 -496.42 -360.99
148 End.Equity 11094.89 11017.62 3581.04
149 558.64 1425.90
150
151 IYR IYZ LQD
152 RWR SHY
Total.Net.Profit 3551.70 565.56 278.51 3846.21
153 1431.72
154 Total.Days 734.00 573.00 652.00 739.00
155 1113.00
156 Winning.Days 403.00 294.00 346.00 400.00
157 621.00
Losing.Days 331.00 279.00 306.00 339.00
158 492.00
159 Avg.Day.PL 4.84 0.99 0.43
160 5.20 1.29
161 Med.Day.PL 14.36 3.93 3.56
12.15 1.30
162 Largest.Winner 670.92 284.62 121.85
163 697.50 47.06
164 Largest.Loser -589.08 -417.80 -158.88 -604.38
165 -56.73
166 Gross.Profits 38230.24 20613.93 9963.95 39597.03
5662.04
167 Gross.Losses -34678.54 -20048.37 -9685.44 -35750.82
168 -4230.32
169 Std.Dev.Daily.PL 137.96 93.19 39.22
170 142.32 11.76
Percent.Positive 54.90 51.31 53.07
171
54.13 55.80
172 Percent.Negative 45.10 48.69 46.93
173 45.87 44.20
174 Profit.Factor 1.10 1.03 1.03
175 1.11 1.34
Avg.Win.Day 94.86 70.12 28.80
176 98.99 9.12
177 Med.Win.Day 78.84 57.86 23.58
178 76.99 7.16
179 Avg.Losing.Day -104.77 -71.86 -31.65
180 -105.46 -8.60
Med.Losing.Day -71.21 -51.15 -23.52
181 -73.72 -6.71
182 Avg.Daily.PL 4.84 0.99 0.43
183 5.20 1.29
184 Med.Daily.PL 14.36 3.93 3.56
12.15 1.30
185 Std.Dev.Daily.PL.1 137.96 93.19 39.22
142.32 11.76
Ann.Sharpe 0.56 0.17 0.17
0.58 1.74
Max.Drawdown -2117.09 -2239.16 -853.57 -2500.81
-206.62
Profit.To.Max.Draw 1.68 0.25 0.33
1.54 6.93
Avg.WinLoss.Ratio 0.91 0.98 0.91
0.94 1.06
Med.WinLoss.Ratio 1.11 1.13 1.00
1.04 1.07
Max.Equity 4939.41 1994.72 729.12 5125.30
1496.21
Min.Equity 0.00 -803.23 -815.95 0.00
-178.23
End.Equity 3551.70 565.56 278.51 3846.21
1431.72

TLT XLB XLE


XLF XLI
Total.Net.Profit 1685.94 6026.21 -721.62
1073.90 3270.62
Total.Days 561.00 696.00 577.00
413.00 646.00
Winning.Days 291.00 389.00 305.00
211.00 355.00
Losing.Days 270.00 307.00 272.00
202.00 291.00
Avg.Day.PL 3.01 8.66 -1.25
2.60 5.06
Med.Day.PL 7.24 18.15 11.98
3.59 9.82
Largest.Winner 532.71 409.39 497.44
532.50 576.04
Largest.Loser -377.39 -446.88 -494.46
-631.42 -442.08
Gross.Profits 21279.66 36728.98 33683.15 16124.85
26384.16
Gross.Losses -19593.73 -30702.77 -34404.77 -15050.95
-23113.53
Std.Dev.Daily.PL 100.15 125.48 149.29
112.73 102.81
Percent.Positive 51.87 55.89 52.86
51.09 54.95
Percent.Negative 48.13 44.11 47.14
48.91 45.05
Profit.Factor 1.09 1.20 0.98
1.07 1.14
Avg.Win.Day 73.13 94.42 110.44
76.42 74.32
Med.Win.Day 50.91 80.16 93.17
50.84 64.46
Avg.Losing.Day -72.57 -100.01 -126.49
-74.51 -79.43
Med.Losing.Day -57.64 -71.25 -96.00
-47.78 -55.28
Avg.Daily.PL 3.01 8.66 -1.25
2.60 5.06
Med.Daily.PL 7.24 18.15 11.98
3.59 9.82
Std.Dev.Daily.PL.1 100.15 125.48 149.29
112.73 102.81
Ann.Sharpe 0.48 1.10 -0.13
0.37 0.78
Max.Drawdown -2020.60 -2343.85 -5364.07 -1497.18
-1480.30
Profit.To.Max.Draw 0.83 2.57 -0.13
0.72 2.21
Avg.WinLoss.Ratio 1.01 0.94 0.87
1.03 0.94
Med.WinLoss.Ratio 0.88 1.13 0.97
1.06 1.17
Max.Equity 3278.94 6034.85 3638.56
2209.75 4344.89
Min.Equity -1033.35 -234.71 -1725.52
-353.34 0.00
End.Equity 1685.94 6026.21 -721.62
1073.90 3270.62

XLK XLP XLU


XLV XLY
Total.Net.Profit 2786.08 1691.84 2071.68
329.36 1596.47
Total.Days 608.00 693.00 745.00
430.00 538.00
Winning.Days 339.00 378.00 407.00
214.00 283.00
Losing.Days 269.00 315.00 338.00
216.00 255.00
Avg.Day.PL 4.58 2.44 2.78
0.77 2.97
Med.Day.PL 14.76 8.42 11.72
-3.08 9.24
Largest.Winner 370.61 231.60 314.64
274.83 542.64
Largest.Loser -434.61 -664.12 -425.69
-281.88 -410.21
Gross.Profits 27166.46 18243.42 29482.80 12726.07
21293.42
Gross.Losses -24380.38 -16551.58 -27411.12 -12396.71
-19696.96
Std.Dev.Daily.PL 111.27 67.51 101.03
75.55 103.78
Percent.Positive 55.76 54.55 54.63
49.77 52.60
Percent.Negative 44.24 45.45 45.37
50.23 47.40
Profit.Factor 1.11 1.10 1.08
1.03 1.08
Avg.Win.Day 80.14 48.26 72.44
59.47 75.24
Med.Win.Day 59.85 41.83 59.86
46.78 59.84
Avg.Losing.Day -90.63 -52.54 -81.10
-57.39 -77.24
Med.Losing.Day -64.53 -40.45 -55.63
-45.04 -50.75
Avg.Daily.PL 4.58 2.44 2.78
0.77 2.97
Med.Daily.PL 14.76 8.42 11.72
-3.08 9.24
Std.Dev.Daily.PL.1 111.27 67.51 101.03
75.55 103.78
Ann.Sharpe 0.65 0.57 0.44
0.16 0.45
Max.Drawdown -1984.37 -2106.40 -2360.48 -1327.16
-1540.71
Profit.To.Max.Draw 1.40 0.80 0.88
0.25 1.04
Avg.WinLoss.Ratio 0.88 0.92 0.89
1.04 0.97
Med.WinLoss.Ratio 0.93 1.03 1.08
1.04 1.18
Max.Equity 2883.68 2116.10 4325.65
653.11 2920.67
Min.Equity -739.92 -49.59 -1004.33
-1293.46 -393.05
End.Equity 2786.08 1691.84 2071.68
329.36 1596.47

This leads to the following cash Sharpe ratio:

1 #portfolio cash PL
2 portPL <- .blotter$portfolio.TVI_TF_2$summary$Net.Trading.PL
3
4 #Cash Sharpe
5 (SharpeRatio.annualized(portPL, geometric=FALSE))
1 Net.Trading.PL
2 Annualized Sharpe Ratio (Rf=0%) 0.611745

This is the resulting equity curve, compared to SPY.

1
2 instRets <- PortfReturns(account.st)
3 portfRets <- xts(rowMeans(instRets)*ncol(instRets), order.by=index(instRets))
cumPortfRets <- cumprod(1+portfRets)-1
4 firstNonZeroDay <- index(portfRets)[min(which(portfRets!=0))]
5 getSymbols("SPY", from=firstNonZeroDay, to="2010-12-31")
6 SPYrets <- diff(log(Cl(SPY)))[-1]
7 cumSPYrets <- cumprod(1+SPYrets)-1
comparison <- cbind(cumPortfRets, cumSPYrets)
8 colnames(comparison) <- c("strategy", "SPY")
9 chart.TimeSeries(comparison, legend.loc = "topleft",
10 main=paste0("Period=", period, ", Delta=",delta))
11

Here are the Sharpe based on returns, annualized returns, and max drawdown.

1 > SharpeRatio.annualized(portfRets)
[,1]
2
Annualized Sharpe Ratio (Rf=0%) 0.5891719
3 > Return.annualized(portfRets)
4 [,1]
5
Annualized Return 0.04025855
6 > maxDrawdown(portfRets)
7 [1] 0.0979138
8

Essentially, 4% annualized return for a max drawdown of nearly 10%, with a Sharpe Ratio nowhere close to
1. Definitely not the greatest strategy, but nevertheless, compared to SPY, far less volatile, when comparing
equity curves. Once again, however, keep in mind that currently, the Trend Vigor is being used as a market
mode indicator, rather than a dedicated trend follower. Keep that in the back of your mind as you look at the
value of the actual indicator over time.

1 chart.Posn(portfolio.st, "XLB")
2 tmp <- TVI(Cl(XLB), period=period, delta=delta, triggerLag=30)
3 add_TA(tmp$vigor)
4 add_TA(tmp$trigger, on=5, col="red")

To note, this is *not* the actual indicator I am using. The indicator for the strategy has triggerLag at 1that
is, the same computation, lagged a day. So I buy when the black line goes from heading downward to
heading upward, and sell vice versa. This lags the indicator by 30 days (the red line) just to illustrate the
concept for human visibility at that scale.

So, thats a walkthrough of the default settings strategy.

Now, its time to explore the interaction of delta and the period setting.

First, Im going to try setting delta to .05. In the demo, this is one of the earlier lines, and one of the earlier
lines in the blog post (scroll up to see the exact code). Here are the trade and daily statistics after running the
demo.

1 #Trade Statistics
EFA EPP EWA EWC EWG
2 Num.Txns 15.00 15.00 15.00 17.00 15.00
3 Num.Trades 8.00 8.00 8.00 9.00 8.00
4 Net.Trading.PL 8227.33 11063.30 13924.03 10733.98 9025.04
5 Avg.Trade.PL 1028.42 1382.91 1740.50 1192.66 1128.13
6 Med.Trade.PL 1019.15 887.77 1708.82 1057.51 589.32
Largest.Winner 2882.94 3910.23 4012.78 2849.73 4583.32
7 Largest.Loser -595.29 0.00 0.00 -700.52 -1555.36
Gross.Profits 9030.96 11063.30 13924.03 11563.24 10730.64
8
Gross.Losses -803.63 0.00 0.00 -829.26 -1705.60
9 Std.Dev.Trade.PL 1225.82 1230.98 1445.19 1273.92 1960.06
10 Percent.Positive 75.00 100.00 100.00 77.78 75.00
11 Percent.Negative 25.00 0.00 0.00 22.22 25.00
12 Profit.Factor 11.24 Inf Inf 13.94 6.29
13 Avg.Win.Trade 1505.16 1382.91 1740.50 1651.89 1788.44
Med.Win.Trade 1468.87 887.77 1708.82 1865.24 1383.92
14
Avg.Losing.Trade -401.82 NaN NaN -414.63 -852.80
15
Med.Losing.Trade -401.82 NA NA -414.63 -852.80
16
Avg.Daily.PL 1151.85 1511.09 1940.12 1274.24 1283.89
17 Med.Daily.PL 1300.39 1077.08 2230.28 1461.37 861.35
18 Std.Dev.Daily.PL 1269.20 1270.64 1436.92 1336.51 2062.93
19 Ann.Sharpe 14.41 18.88 21.43 15.13 9.88
20 Max.Drawdown -1973.63 -3221.65 -2703.01 -3330.82 -2252.59
Profit.To.Max.Draw 4.17 3.43 5.15 3.22 4.01
21
Avg.WinLoss.Ratio 3.75 NaN NaN 3.98 2.10
22
Med.WinLoss.Ratio 3.66 NA NA 4.50 1.62
23
Max.Equity 8783.50 11706.29 15425.82 10733.98 9377.84
24 Min.Equity -165.27 -186.62 -399.56 -272.20 -16.66
25 End.Equity 8227.33 11063.30 13924.03 10733.98 9025.04
26
27 EWH EWJ EWS EWT EWU
28 Num.Txns 17.00 15.00 17.00 23.00 15.00
Num.Trades 9.00 8.00 9.00 12.00 8.00
29 Net.Trading.PL 8607.81 3989.12 12749.63 1198.79 8737.48
30 Avg.Trade.PL 956.42 498.64 1416.63 99.90 1092.18
31 Med.Trade.PL 603.38 145.35 803.77 -126.44 717.13
32 Largest.Winner 2737.89 3119.88 4604.52 1186.44 3266.73
33 Largest.Loser 0.00 -897.44 -548.92 -1112.23 -683.09
Gross.Profits 8610.51 5284.21 13298.55 4610.06 9945.34
34 Gross.Losses -2.70 -1295.09 -548.92 -3411.26 -1207.86
35 Std.Dev.Trade.PL 1041.04 1245.20 1659.47 855.59 1509.68
36 Percent.Positive 88.89 62.50 88.89 41.67 75.00
37 Percent.Negative 11.11 37.50 11.11 58.33 25.00
Profit.Factor 3192.83 4.08 24.23 1.35 8.23
38 Avg.Win.Trade 1076.31 1056.84 1662.32 922.01 1657.56
39 Med.Win.Trade 625.45 519.93 1353.14 1032.56 1475.05
40 Avg.Losing.Trade -2.70 -431.70 -548.92 -487.32 -603.93
41 Med.Losing.Trade -2.70 -342.50 -548.92 -366.82 -603.93
42 Avg.Daily.PL 1076.31 495.60 1493.23 -30.81 1205.85
Med.Daily.PL 625.45 7.05 1163.55 -244.67 1005.50
43 Std.Dev.Daily.PL 1044.39 1344.93 1756.95 761.39 1593.25
44 Ann.Sharpe 16.36 5.85 13.49 -0.64 12.01
45 Max.Drawdown -3209.01 -2930.01 -2495.29 -5536.64 -1932.03
46 Profit.To.Max.Draw 2.68 1.36 5.11 0.22 4.52
47 Avg.WinLoss.Ratio 399.10 2.45 3.03 1.89 2.74
Med.WinLoss.Ratio 231.92 1.52 2.47 2.81 2.44
48 Max.Equity 9206.16 6227.40 12909.67 3431.84 9432.62
49 Min.Equity 0.00 -542.64 -412.24 -2104.80 -253.67
50 End.Equity 8607.81 3989.12 12749.63 1198.79 8737.48
51
52 EWY EWZ EZU IEF IGE
Num.Txns 21.00 12.00 20.00 19.00 29.00
53 Num.Trades 11.00 6.00 10.00 10.00 15.00
54 Net.Trading.PL 8265.64 24932.44 6119.14 585.45 9010.26
55 Avg.Trade.PL 751.42 4155.41 611.91 58.55 600.68
56 Med.Trade.PL 590.63 3411.21 281.39 56.80 17.71
57 Largest.Winner 3444.27 11178.58 2767.56 578.57 4768.77
Largest.Loser -1639.42 -1956.40 -1612.20 -452.40 -1044.03
58 Gross.Profits 11590.14 27007.07 9032.54 1631.70 13257.71
59 Gross.Losses -3324.50 -2074.63 -2913.40 -1046.25 -4247.45
60 Std.Dev.Trade.PL 1635.85 5142.41 1467.12 334.39 1601.62
61 Percent.Positive 54.55 66.67 50.00 50.00 53.33
Percent.Negative 45.45 33.33 50.00 50.00 46.67
62 Profit.Factor 3.49 13.02 3.10 1.56 3.12
Avg.Win.Trade 1931.69 6751.77 1806.51 326.34 1657.21
63
Med.Win.Trade 1663.75 6783.34 2240.25 283.77 1170.69
64 Avg.Losing.Trade -664.90 -1037.32 -582.68 -209.25 -606.78
65 Med.Losing.Trade -548.58 -1037.32 -380.50 -229.98 -496.26
66 Avg.Daily.PL 719.50 4155.41 611.91 43.81 582.55
67 Med.Daily.PL 207.44 3411.21 281.39 -11.57 -18.62
Std.Dev.Daily.PL 1720.73 5142.41 1467.12 351.22 1660.48
68 Ann.Sharpe 6.64 12.83 6.62 1.98 5.57
69 Max.Drawdown -4430.88 -8099.04 -2376.14 -1042.38 -3292.00
70 Profit.To.Max.Draw 1.87 3.08 2.58 0.56 2.74
71 Avg.WinLoss.Ratio 2.91 6.51 3.10 1.56 2.73
72 Med.WinLoss.Ratio 3.03 6.54 5.89 1.23 2.36
Max.Equity 9939.98 27860.83 6964.49 1297.25 10608.96
73 Min.Equity -275.58 -699.79 -119.44 -977.06 -360.99
74 End.Equity 8265.64 24932.44 6119.14 585.45 9010.26
75
76 IYR IYZ LQD RWR SHY
77 Num.Txns 18.00 23.00 20.00 18.00 17.00
Num.Trades 9.00 12.00 10.00 9.00 9.00
78 Net.Trading.PL 5152.30 1708.37 130.39 6718.45 1745.26
79 Avg.Trade.PL 572.48 142.36 13.04 746.49 193.92
80 Med.Trade.PL 563.22 -120.54 75.65 526.70 23.61
81 Largest.Winner 2918.00 3024.24 405.72 3621.48 1408.27
82 Largest.Loser -866.08 -719.83 -437.61 -525.69 -38.96
Gross.Profits 6578.80 4526.67 1234.36 7766.42 1838.06
83 Gross.Losses -1426.50 -2818.30 -1103.97 -1047.98 -92.81
84 Std.Dev.Trade.PL 1116.84 1009.69 279.74 1259.65 461.97
85 Percent.Positive 55.56 33.33 60.00 66.67 66.67
86 Percent.Negative 44.44 66.67 40.00 33.33 33.33
87 Profit.Factor 4.61 1.61 1.12 7.41 19.81
Avg.Win.Trade 1315.76 1131.67 205.73 1294.40 306.34
88 Med.Win.Trade 1065.80 607.86 193.42 935.99 94.33
89 Avg.Losing.Trade -356.62 -352.29 -275.99 -349.33 -30.94
90 Med.Losing.Trade -207.69 -356.49 -272.49 -422.60 -37.39
91 Avg.Daily.PL 572.48 83.84 13.04 746.49 206.09
Med.Daily.PL 563.22 -193.76 75.65 526.70 19.61
92 Std.Dev.Daily.PL 1116.84 1037.40 279.74 1259.65 492.32
93 Ann.Sharpe 8.14 1.28 0.74 9.41 6.65
94 Max.Drawdown -2630.67 -1861.72 -936.63 -2352.97 -256.48
95 Profit.To.Max.Draw 1.96 0.92 0.14 2.86 6.80
96 Avg.WinLoss.Ratio 3.69 3.21 0.75 3.71 9.90
Med.WinLoss.Ratio 5.13 1.71 0.71 2.21 2.52
97 Max.Equity 6254.05 2468.70 536.06 7751.61 1786.95
98 Min.Equity 0.00 -1795.37 -899.01 0.00 -89.54
99 End.Equity 5152.30 1708.37 130.39 6718.45 1745.26
100
101 TLT XLB XLE XLF XLI
Num.Txns 24.00 21.00 27.00 16.00 15.00
102
Num.Trades 12.00 11.00 14.00 8.00 8.00
103 Net.Trading.PL 2066.64 4949.22 12832.20 3832.14 4152.85
104 Avg.Trade.PL 172.22 449.93 916.59 479.02 519.11
105 Med.Trade.PL 64.51 299.25 29.49 177.45 432.70
106 Largest.Winner 1516.76 2465.37 10722.60 2492.20 2076.85
Largest.Loser -799.95 -1213.35 -1470.10 -1011.16 -780.27
107 Gross.Profits 3385.01 8451.54 16601.75 5130.47 5213.68
108 Gross.Losses -1318.37 -3502.32 -3769.55 -1298.33 -1060.84
109 Std.Dev.Trade.PL 571.70 1338.56 3059.14 1099.30 908.57
110 Percent.Positive 58.33 63.64 57.14 62.50 75.00
111 Percent.Negative 41.67 36.36 42.86 37.50 25.00
Profit.Factor 2.57 2.41 4.40 3.95 4.91
112 Avg.Win.Trade 483.57 1207.36 2075.22 1026.09 868.95
113 Med.Win.Trade 353.25 696.82 520.06 745.78 635.27
114 Avg.Losing.Trade -263.67 -875.58 -628.26 -432.78 -530.42
115 Med.Losing.Trade -127.47 -965.22 -502.49 -243.40 -530.42
Avg.Daily.PL 172.22 425.24 897.10 479.02 483.63
116 Med.Daily.PL 64.51 172.27 25.82 177.45 362.26
117 Std.Dev.Daily.PL 571.70 1408.32 3183.15 1099.30 975.37
Ann.Sharpe 4.78 4.79 4.47 6.92 7.87
118
Max.Drawdown -2230.38 -3263.67 -3550.72 -2353.27 -1876.74
119 Profit.To.Max.Draw 0.93 1.52 3.61 1.63 2.21
120 Avg.WinLoss.Ratio 1.83 1.38 3.30 2.37 1.64
121 Med.WinLoss.Ratio 2.77 0.72 1.03 3.06 1.20
122 Max.Equity 3450.04 6216.57 13284.80 5838.21 5031.19
Min.Equity -1261.84 -116.14 -468.28 -106.64 -134.79
123 End.Equity 2066.64 4949.22 12832.20 3832.14 4152.85
124
125 XLK XLP XLU XLV XLY
126 Num.Txns 19.00 13.00 15.00 21.00 15.00
127 Num.Trades 10.00 7.00 8.00 11.00 8.00
128 Net.Trading.PL 5676.09 3673.84 4611.03 -318.04 5316.38
Avg.Trade.PL 567.61 524.83 576.38 -28.91 664.55
129 Med.Trade.PL 437.57 170.61 273.18 12.47 254.12
130 Largest.Winner 3770.88 1614.82 3011.64 619.76 3835.14
131 Largest.Loser -698.78 -248.32 -966.49 -679.66 -601.28
132 Gross.Profits 7910.97 3943.62 5906.06 1676.74 6737.00
Gross.Losses -2234.88 -269.78 -1295.04 -1994.78 -1420.62
133 Std.Dev.Trade.PL 1370.91 704.46 1281.22 417.22 1496.94
134 Percent.Positive 60.00 71.43 75.00 54.55 62.50
135 Percent.Negative 40.00 28.57 25.00 45.45 37.50
136 Profit.Factor 3.54 14.62 4.56 0.84 4.74
137 Avg.Win.Trade 1318.49 788.72 984.34 279.46 1347.40
Med.Win.Trade 787.39 1043.70 426.32 208.37 600.59
138 Avg.Losing.Trade -558.72 -134.89 -647.52 -398.96 -473.54
139 Med.Losing.Trade -581.97 -134.89 -647.52 -424.36 -497.16
140 Avg.Daily.PL 600.09 583.87 596.95 -48.94 692.34
141 Med.Daily.PL 599.90 551.34 126.12 -65.24 38.23
142 Std.Dev.Daily.PL 1449.98 752.49 1382.45 434.18 1614.65
Ann.Sharpe 6.57 12.32 6.85 -1.79 6.81
143 Max.Drawdown -2163.21 -945.00 -2389.00 -1574.99 -2265.49
144 Profit.To.Max.Draw 2.62 3.89 1.93 -0.20 2.35
145 Avg.WinLoss.Ratio 2.36 5.85 1.52 0.70 2.85
146 Med.WinLoss.Ratio 1.35 7.74 0.66 0.49 1.21
Max.Equity 6522.36 3705.07 5776.84 731.12 7076.43
147 Min.Equity -206.72 -315.77 -772.21 -1189.32 -55.79
148 End.Equity 5676.09 3673.84 4611.03 -318.04 5316.38
149
150
151 #Daily Statistics
152 EFA EPP EWA EWC EWG
153 Total.Net.Profit 8227.33 11063.30 13924.03 10733.98 9025.04
Total.Days 1007.00 1161.00 1171.00 1131.00 1006.00
154 Winning.Days 554.00 639.00 661.00 635.00 558.00
155 Losing.Days 453.00 522.00 510.00 496.00 448.00
156 Avg.Day.PL 8.17 9.53 11.89 9.49 8.97
157 Med.Day.PL 12.93 13.50 21.99 24.36 19.33
Largest.Winner 408.21 705.97 644.19 517.86 510.65
158
Largest.Loser -446.90 -653.65 -726.30 -640.19 -578.28
159 Gross.Profits 48673.31 74367.84 84153.20 67767.25 62690.85
160 Gross.Losses -40445.98 -63304.54 -70229.17 -57033.27 -53665.80
161 Std.Dev.Daily.PL 116.11 164.25 178.88 143.87 150.39
162 Percent.Positive 55.01 55.04 56.45 56.15 55.47
Percent.Negative 44.99 44.96 43.55 43.85 44.53
163 Profit.Factor 1.20 1.17 1.20 1.19 1.17
164 Avg.Win.Day 87.86 116.38 127.31 106.72 112.35
165 Med.Win.Day 72.86 87.42 100.11 86.51 89.18
166 Avg.Losing.Day -89.28 -121.27 -137.70 -114.99 -119.79
167 Med.Losing.Day -66.22 -80.24 -95.53 -82.40 -89.92
Avg.Daily.PL 8.17 9.53 11.89 9.49 8.97
168 Med.Daily.PL 12.93 13.50 21.99 24.36 19.33
169 Std.Dev.Daily.PL.1 116.11 164.25 178.88 143.87 150.39
170 Ann.Sharpe 1.12 0.92 1.06 1.05 0.95
171 Max.Drawdown -1973.63 -3221.65 -2703.01 -3330.82 -2252.59
Profit.To.Max.Draw 4.17 3.43 5.15 3.22 4.01
172 Avg.WinLoss.Ratio 0.98 0.96 0.92 0.93 0.94
Med.WinLoss.Ratio 1.10 1.09 1.05 1.05 0.99
173
Max.Equity 8783.50 11706.29 15425.82 10733.98 9377.84
174 Min.Equity -165.27 -186.62 -399.56 -272.20 -16.66
175 End.Equity 8227.33 11063.30 13924.03 10733.98 9025.04
176
177 EWH EWJ EWS EWT EWU
178 Total.Net.Profit 8607.81 3989.12 12749.63 1198.79 8737.48
Total.Days 1012.00 726.00 1146.00 851.00 1014.00
179 Winning.Days 531.00 379.00 639.00 438.00 554.00
180 Losing.Days 481.00 347.00 507.00 413.00 460.00
181 Avg.Day.PL 8.51 5.49 11.13 1.41 8.62
182 Med.Day.PL 12.53 13.79 21.28 8.92 15.16
183 Largest.Winner 753.74 517.40 785.37 880.75 462.83
Largest.Loser -902.02 -782.59 -974.26 -1417.30 -590.98
184 Gross.Profits 72436.39 43880.76 82366.04 58541.90 54123.90
185 Gross.Losses -63828.58 -39891.64 -69616.41 -57343.10 -45386.42
186 Std.Dev.Daily.PL 182.08 149.18 181.55 183.18 128.25
187 Percent.Positive 52.47 52.20 55.76 51.47 54.64
Percent.Negative 47.53 47.80 44.24 48.53 45.36
188 Profit.Factor 1.13 1.10 1.18 1.02 1.19
189 Avg.Win.Day 136.42 115.78 128.90 133.66 97.70
190 Med.Win.Day 104.08 94.55 91.27 108.07 80.81
191 Avg.Losing.Day -132.70 -114.96 -137.31 -138.85 -98.67
192 Med.Losing.Day -95.34 -85.90 -104.28 -99.70 -72.84
Avg.Daily.PL 8.51 5.49 11.13 1.41 8.62
193 Med.Daily.PL 12.53 13.79 21.28 8.92 15.16
194 Std.Dev.Daily.PL.1 182.08 149.18 181.55 183.18 128.25
195 Ann.Sharpe 0.74 0.58 0.97 0.12 1.07
196 Max.Drawdown -3209.01 -2930.01 -2495.29 -5536.64 -1932.03
197 Profit.To.Max.Draw 2.68 1.36 5.11 0.22 4.52
Avg.WinLoss.Ratio 1.03 1.01 0.94 0.96 0.99
198 Med.WinLoss.Ratio 1.09 1.10 0.88 1.08 1.11
199 Max.Equity 9206.16 6227.40 12909.67 3431.84 9432.62
200 Min.Equity 0.00 -542.64 -412.24 -2104.80 -253.67
201 End.Equity 8607.81 3989.12 12749.63 1198.79 8737.48
202
EWY EWZ EZU IEF IGE
203 Total.Net.Profit 8265.64 24932.44 6119.14 585.45 9010.26
204 Total.Days 1115.00 1271.00 980.00 874.00 1212.00
205 Winning.Days 599.00 709.00 539.00 438.00 670.00
206 Losing.Days 516.00 562.00 441.00 436.00 542.00
207 Avg.Day.PL 7.41 19.62 6.24 0.67 7.43
Med.Day.PL 18.37 37.21 14.74 0.78 20.63
208 Largest.Winner 833.96 1516.20 511.25 359.14 456.89
209 Largest.Loser -757.96 -1676.65 -743.07 -195.28 -600.22
210 Gross.Profits 96772.35 173737.17 52301.23 17413.21 79833.45
211 Gross.Losses -88506.71 -148804.74 -46182.09 -16827.76 -70823.19
Std.Dev.Daily.PL 218.24 347.76 134.07 52.43 159.01
212
Percent.Positive 53.72 55.78 55.00 50.11 55.28
213 Percent.Negative 46.28 44.22 45.00 49.89 44.72
214 Profit.Factor 1.09 1.17 1.13 1.03 1.13
215 Avg.Win.Day 161.56 245.05 97.03 39.76 119.15
216 Med.Win.Day 131.89 190.69 76.26 32.13 100.58
Avg.Losing.Day -171.52 -264.78 -104.72 -38.60 -130.67
217 Med.Losing.Day -118.99 -181.70 -73.90 -29.23 -103.79
218 Avg.Daily.PL 7.41 19.62 6.24 0.67 7.43
219 Med.Daily.PL 18.37 37.21 14.74 0.78 20.63
220 Std.Dev.Daily.PL.1 218.24 347.76 134.07 52.43 159.01
221 Ann.Sharpe 0.54 0.90 0.74 0.20 0.74
Max.Drawdown -4430.88 -8099.04 -2376.14 -1042.38 -3292.00
222 Profit.To.Max.Draw 1.87 3.08 2.58 0.56 2.74
223 Avg.WinLoss.Ratio 0.94 0.93 0.93 1.03 0.91
224 Med.WinLoss.Ratio 1.11 1.05 1.03 1.10 0.97
225 Max.Equity 9939.98 27860.83 6964.49 1297.25 10608.96
Min.Equity -275.58 -699.79 -119.44 -977.06 -360.99
226 End.Equity 8265.64 24932.44 6119.14 585.45 9010.26
227
228 IYR IYZ LQD RWR SHY
Total.Net.Profit 5152.30 1708.37 130.39 6718.45 1745.26
229
Total.Days 981.00 948.00 770.00 992.00 1345.00
230 Winning.Days 536.00 480.00 408.00 538.00 753.00
231 Losing.Days 445.00 468.00 362.00 454.00 592.00
232 Avg.Day.PL 5.25 1.80 0.17 6.77 1.30
233 Med.Day.PL 14.23 3.87 3.36 16.33 1.31
Largest.Winner 670.92 455.49 211.30 697.50 47.38
234 Largest.Loser -589.08 -439.41 -274.58 -604.38 -57.51
235 Gross.Profits 53330.41 36851.16 12914.84 56782.80 6920.89
236 Gross.Losses -48178.11 -35142.78 -12784.45 -50064.35 -5175.63
237 Std.Dev.Daily.PL 139.95 100.60 44.38 146.67 11.97
238 Percent.Positive 54.64 50.63 52.99 54.23 55.99
Percent.Negative 45.36 49.37 47.01 45.77 44.01
239 Profit.Factor 1.11 1.05 1.01 1.13 1.34
240 Avg.Win.Day 99.50 76.77 31.65 105.54 9.19
241 Med.Win.Day 81.52 60.01 24.89 84.35 7.19
242 Avg.Losing.Day -108.27 -75.09 -35.32 -110.27 -8.74
Med.Losing.Day -76.06 -53.60 -27.51 -81.40 -6.81
243 Avg.Daily.PL 5.25 1.80 0.17 6.77 1.30
244 Med.Daily.PL 14.23 3.87 3.36 16.33 1.31
245 Std.Dev.Daily.PL.1 139.95 100.60 44.38 146.67 11.97
246 Ann.Sharpe 0.60 0.28 0.06 0.73 1.72
247 Max.Drawdown -2630.67 -1861.72 -936.63 -2352.97 -256.48
Profit.To.Max.Draw 1.96 0.92 0.14 2.86 6.80
248 Avg.WinLoss.Ratio 0.92 1.02 0.90 0.96 1.05
249 Med.WinLoss.Ratio 1.07 1.12 0.90 1.04 1.06
250 Max.Equity 6254.05 2468.70 536.06 7751.61 1786.95
251 Min.Equity 0.00 -1795.37 -899.01 0.00 -89.54
252 End.Equity 5152.30 1708.37 130.39 6718.45 1745.26
253
TLT XLB XLE XLF XLI
254 Total.Net.Profit 2066.64 4949.22 12832.20 3832.14 4152.85
255 Total.Days 755.00 1039.00 1154.00 738.00 1001.00
256 Winning.Days 390.00 569.00 630.00 386.00 544.00
257 Losing.Days 365.00 470.00 524.00 352.00 457.00
Avg.Day.PL 2.74 4.76 11.12 5.19 4.15
258 Med.Day.PL 4.68 16.84 23.19 6.77 9.43
259 Largest.Winner 546.86 543.49 649.18 521.32 567.57
260 Largest.Loser -387.41 -561.19 -898.57 -695.88 -461.98
261 Gross.Profits 29206.43 60629.30 91312.60 34177.43 41796.72
262 Gross.Losses -27139.79 -55680.08 -78480.40 -30345.29 -37643.87
Std.Dev.Daily.PL 102.19 145.68 196.01 128.37 105.23
263 Percent.Positive 51.66 54.76 54.59 52.30 54.35
264 Percent.Negative 48.34 45.24 45.41 47.70 45.65
265 Profit.Factor 1.08 1.09 1.16 1.13 1.11
266 Avg.Win.Day 74.89 106.55 144.94 88.54 76.83
Med.Win.Day 52.20 90.91 112.15 61.85 62.90
267
Avg.Losing.Day -74.36 -118.47 -149.77 -86.21 -82.37
268 Med.Losing.Day -59.22 -87.40 -108.63 -54.35 -59.78
269 Avg.Daily.PL 2.74 4.76 11.12 5.19 4.15
270 Med.Daily.PL 4.68 16.84 23.19 6.77 9.43
271 Std.Dev.Daily.PL.1 102.19 145.68 196.01 128.37 105.23
Ann.Sharpe 0.43 0.52 0.90 0.64 0.63
272 Max.Drawdown -2230.38 -3263.67 -3550.72 -2353.27 -1876.74
273 Profit.To.Max.Draw 0.93 1.52 3.61 1.63 2.21
274 Avg.WinLoss.Ratio 1.01 0.90 0.97 1.03 0.93
275 Med.WinLoss.Ratio 0.88 1.04 1.03 1.14 1.05
276 Max.Equity 3450.04 6216.57 13284.80 5838.21 5031.19
Min.Equity -1261.84 -116.14 -468.28 -106.64 -134.79
277 End.Equity 2066.64 4949.22 12832.20 3832.14 4152.85
278
279 XLK XLP XLU XLV XLY
280 Total.Net.Profit 5676.09 3673.84 4611.03 -318.04 5316.38
281 Total.Days 964.00 999.00 1024.00 892.00 795.00
Winning.Days 536.00 549.00 562.00 449.00 422.00
282 Losing.Days 428.00 450.00 462.00 443.00 373.00
Avg.Day.PL 5.89 3.68 4.50 -0.36 6.69
283
Med.Day.PL 13.65 8.52 11.94 3.04 8.89
284 Largest.Winner 431.35 298.68 359.25 291.48 741.77
285 Largest.Loser -462.31 -261.14 -429.41 -319.27 -560.75
286 Gross.Profits 45283.91 28445.54 41231.21 27231.30 37590.36
287 Gross.Losses -39607.82 -24771.70 -36620.18 -27549.33 -32273.98
Std.Dev.Daily.PL 117.38 67.41 101.36 79.97 123.15
288 Percent.Positive 55.60 54.95 54.88 50.34 53.08
289 Percent.Negative 44.40 45.05 45.12 49.66 46.92
290 Profit.Factor 1.14 1.15 1.13 0.99 1.16
291 Avg.Win.Day 84.48 51.81 73.37 60.65 89.08
292 Med.Win.Day 60.65 42.81 59.91 50.84 67.06
Avg.Losing.Day -92.54 -55.05 -79.26 -62.19 -86.53
293 Med.Losing.Day -64.97 -44.88 -54.05 -49.00 -56.79
294 Avg.Daily.PL 5.89 3.68 4.50 -0.36 6.69
295 Med.Daily.PL 13.65 8.52 11.94 3.04 8.89
296 Std.Dev.Daily.PL.1 117.38 67.41 101.36 79.97 123.15
Ann.Sharpe 0.80 0.87 0.71 -0.07 0.86
297 Max.Drawdown -2163.21 -945.00 -2389.00 -1574.99 -2265.49
298 Profit.To.Max.Draw 2.62 3.89 1.93 -0.20 2.35
299 Avg.WinLoss.Ratio 0.91 0.94 0.93 0.98 1.03
300 Med.WinLoss.Ratio 0.93 0.95 1.11 1.04 1.18
301 Max.Equity 6522.36 3705.07 5776.84 731.12 7076.43
Min.Equity -206.72 -315.77 -772.21 -1189.32 -55.79
302 End.Equity 5676.09 3673.84 4611.03 -318.04 5316.38
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368

The equity curve (vs. SPY)

This time, while you take on more risk, your returns are definitely betteressentially keeping pace with SPY
in its bullish phases while missing the financial crisis (as any decent trend-follower does). That stated, the
drawdowns between this strategy and SPY happen at similar times, meaning that given that there are more
equity indices than the SPY (as well as bond indices), that position sizing for the strategy can be improved
for diversification.

Here are the three portfolio statistics:

1
> SharpeRatio.annualized(portfRets)
2 [,1]
3 Annualized Sharpe Ratio (Rf=0%) 0.7914488
4 > Return.annualized(portfRets)
5 [,1]
Annualized Return 0.08098812
6
> maxDrawdown(portfRets)
7 [1] 0.1283513
8

Finally, heres the new indicator plot, this time with the true lagged indicator plotted.

Notice that the indicator stays at more extreme values more often.

Lets take this to the limit and set delta to zero.

Here are the trade stats:

1 EFA EPP EWA EWC EWG


Num.Txns 11.00 9.00 11.00 11.00 11.00
2 Num.Trades 6.00 5.00 6.00 6.00 6.00
3 Net.Trading.PL 9095.11 12779.16 14602.67 12673.96 11222.15
4 Avg.Trade.PL 1515.85 2555.83 2433.78 2112.33 1870.36
5 Med.Trade.PL 1820.06 2623.33 2709.23 2305.23 1861.94
6 Largest.Winner 3631.16 4615.15 5833.88 6144.25 3159.37
Largest.Loser -933.65 0.00 -590.11 -1792.36 0.00
7 Gross.Profits 10028.75 12779.16 15192.78 14466.32 11222.15
8 Gross.Losses -933.65 0.00 -590.11 -1792.36 0.00
9 Std.Dev.Trade.PL 1684.91 1513.27 2196.84 2607.66 1142.29
10 Percent.Positive 83.33 100.00 83.33 83.33 100.00
11 Percent.Negative 16.67 0.00 16.67 16.67 0.00
12 Profit.Factor 10.74 Inf 25.75 8.07 Inf
Avg.Win.Trade 2005.75 2555.83 3038.56 2893.26 1870.36
13 Med.Win.Trade 2479.23 2623.33 2780.49 2762.52 1861.94
14 Avg.Losing.Trade -933.65 NaN -590.11 -1792.36 NaN
15 Med.Losing.Trade -933.65 NA -590.11 -1792.36 NA
16 Avg.Daily.PL 1772.55 3065.78 2764.58 2357.14 2203.82
17 Med.Daily.PL 2479.23 2874.02 2780.49 2762.52 2359.07
Std.Dev.Daily.PL 1747.70 1148.77 2282.97 2837.32 892.78
18 Ann.Sharpe 16.10 42.37 19.22 13.19 39.19
19 Max.Drawdown -2804.25 -3977.43 -4487.98 -4446.67 -3101.41
20 Profit.To.Max.Draw 3.24 3.21 3.25 2.85 3.62
21 Avg.WinLoss.Ratio 2.15 NaN 5.15 1.61 NaN
22 Med.WinLoss.Ratio 2.66 NA 4.71 1.54 NA
23 Max.Equity 10373.87 14886.32 16959.46 12828.77 12321.51
Min.Equity -165.27 -186.62 -399.56 -272.20 -16.66
24
End.Equity 9095.11 12779.16 14602.67 12673.96 11222.15
25
26 EWH EWJ EWS EWT EWU
27 Num.Txns 7.00 13.00 9.00 15.00 11.00
28 Num.Trades 4.00 7.00 5.00 8.00 6.00
29 Net.Trading.PL 15840.82 5176.40 18882.47 3321.05 8340.94
Avg.Trade.PL 3960.20 739.49 3776.49 415.13 1390.16
30 Med.Trade.PL 3129.89 641.19 2657.46 125.19 1255.15
31 Largest.Winner 7545.70 3116.82 11080.06 3111.65 3892.96
32 Largest.Loser 0.00 -1200.32 -1012.71 -2126.89 -1020.86
33 Gross.Profits 15840.82 6376.72 19895.19 6644.85 9361.80
34 Gross.Losses 0.00 -1200.32 -1012.71 -3323.80 -1020.86
Std.Dev.Trade.PL 2449.69 1342.88 4478.92 1657.15 1717.55
35 Percent.Positive 100.00 85.71 80.00 62.50 83.33
36 Percent.Negative 0.00 14.29 20.00 37.50 16.67
37 Profit.Factor Inf 5.31 19.65 2.00 9.17
38 Avg.Win.Trade 3960.20 1062.79 4973.80 1328.97 1872.36
39 Med.Win.Trade 3129.89 738.02 3334.30 1366.22 1290.27
40 Avg.Losing.Trade NaN -1200.32 -1012.71 -1107.93 -1020.86
Med.Losing.Trade NA -1200.32 -1012.71 -811.78 -1020.86
41 Avg.Daily.PL 4601.83 723.59 4183.99 200.63 1601.16
42 Med.Daily.PL 3307.58 391.69 3334.30 33.08 1290.27
43 Std.Dev.Daily.PL 2555.65 1470.34 5063.65 1665.66 1831.27
44 Ann.Sharpe 28.58 7.81 13.12 1.91 13.88
Max.Drawdown -6279.36 -3186.71 -6357.43 -5074.58 -2806.72
45 Profit.To.Max.Draw 2.52 1.62 2.97 0.65 2.97
46 Avg.WinLoss.Ratio NaN 0.89 4.91 1.20 1.83
47
Med.WinLoss.Ratio NA 0.61 3.29 1.68 1.26
48 Max.Equity 16555.02 6833.58 19063.41 3473.68 9627.51
49 Min.Equity -117.59 -396.06 -412.24 -1842.71 -253.67
50 End.Equity 15840.82 5176.40 18882.47 3321.05 8340.94
51
52 EWY EWZ EZU IEF IGE
Num.Txns 11.00 9.00 9.00 17.00 9.00
53 Num.Trades 6.00 5.00 5.00 9.00 5.00
54 Net.Trading.PL 16345.10 29677.36 9371.42 835.02 14116.64
55 Avg.Trade.PL 2724.18 5935.47 1874.28 92.78 2823.33
56 Med.Trade.PL 1151.79 7224.58 1259.50 -13.70 1578.21
57 Largest.Winner 7324.66 11173.16 4689.91 934.88 11236.40
Largest.Loser -59.53 0.00 0.00 -243.00 -2370.85
58 Gross.Profits 16404.63 29677.36 9552.12 1538.80 16487.49
59 Gross.Losses -59.53 0.00 -180.70 -703.78 -2370.85
60 Std.Dev.Trade.PL 3043.54 4291.41 1838.25 365.25 5039.93
61 Percent.Positive 83.33 100.00 80.00 44.44 80.00
Percent.Negative 16.67 0.00 20.00 55.56 20.00
62
63 Profit.Factor 275.58 Inf 52.86 2.19 6.95
Avg.Win.Trade 3280.93 5935.47 2388.03 384.70 4121.87
64 Med.Win.Trade 1208.67 7224.58 1879.94 210.16 1915.33
65 Avg.Losing.Trade -59.53 NaN -180.70 -140.76 -2370.85
66 Med.Losing.Trade -59.53 NA -180.70 -206.60 -2370.85
67 Avg.Daily.PL 3072.41 7399.70 2388.03 81.43 3134.61
68 Med.Daily.PL 1208.67 7532.93 1879.94 -20.44 1836.44
69 Std.Dev.Daily.PL 3266.42 3203.41 1657.09 388.77 5763.85
Ann.Sharpe 14.93 36.67 22.88 3.32 8.63
70 Max.Drawdown -4656.74 -8660.23 -3353.89 -1345.79 -4492.64
Profit.To.Max.Draw 3.51 3.43 2.79 0.62 3.14
71
72 Avg.WinLoss.Ratio 55.12 NaN 13.22 2.73 1.74
73 Med.WinLoss.Ratio 20.30 NA 10.40 1.02 0.81
Max.Equity 16548.01 31682.83 11221.49 1756.16 14420.81
74 Min.Equity 0.00 -699.79 -119.44 -714.17 -360.99
75 End.Equity 16345.10 29677.36 9371.42 835.02 14116.64
76
77 IYR IYZ LQD RWR SHY
78 Num.Txns 11.00 13.00 15.00 9.00 9.00
Num.Trades 6.00 7.00 8.00 5.00 5.00
79 Net.Trading.PL 12860.27 5906.68 2177.09 15725.34 2126.96
80 Avg.Trade.PL 2143.38 843.81 272.14 3145.07 425.39
81 Med.Trade.PL 1549.35 -4.31 -9.55 1933.28 265.78
82 Largest.Winner 2494.86 2704.21 239.07 3664.07 1544.02
83 Largest.Loser -1003.00 -789.18 -176.30 -664.12 -28.09
Gross.Profits 13863.26 7533.20 2468.60 16389.46 2155.05
84 Gross.Losses -1003.00 -1626.52 -291.51 -664.12 -28.09
85 Std.Dev.Trade.PL 2977.41 2061.62 767.56 3956.03 639.74
86 Percent.Positive 83.33 42.86 37.50 80.00 80.00
87 Percent.Negative 16.67 57.14 62.50 20.00 20.00
88 Profit.Factor 13.82 4.63 8.47 24.68 76.71
Avg.Win.Trade 2772.65 2511.07 822.87 4097.37 538.76
89 Med.Win.Trade 1859.25 2704.21 239.07 2798.67 277.14
90 Avg.Losing.Trade -1003.00 -406.63 -58.30 -664.12 -28.09
91 Med.Losing.Trade -1003.00 -416.51 -36.93 -664.12 -28.09
92 Avg.Daily.PL 1031.33 200.00 4.06 1518.44 459.61
Med.Daily.PL 1239.44 -143.55 -15.28 1536.90 161.27
93 Std.Dev.Daily.PL 1344.03 1272.26 128.95 1796.50 733.41
94 Ann.Sharpe 12.18 2.50 0.50 13.42 9.95
95 Max.Drawdown -4545.72 -3655.24 -1126.20 -4720.58 -258.24
96 Profit.To.Max.Draw 2.83 1.62 1.93 3.33 8.24
97 Avg.WinLoss.Ratio 2.76 6.18 14.11 6.17 19.18
Med.WinLoss.Ratio 1.85 6.49 6.47 4.21 9.86
98 Max.Equity 13193.50 5906.68 2600.28 16148.05 2169.34
99 Min.Equity 0.00 -1458.57 -750.84 0.00 -62.71
100 End.Equity 12860.27 5906.68 2177.09 15725.34 2126.96
101
102 TLT XLB XLE XLF XLI
Num.Txns 16.00 13.00 9.00 11.00 13.00
103
Num.Trades 8.00 7.00 5.00 6.00 7.00
104 Net.Trading.PL -1042.28 8143.08 16350.23 6938.82 8270.94
105 Avg.Trade.PL -130.28 1163.30 3270.05 1156.47 1181.56
106 Med.Trade.PL -190.63 1181.00 1463.69 1327.34 915.45
107 Largest.Winner 442.59 2651.96 12793.77 2912.28 3541.70
Largest.Loser -816.24 -920.78 -2248.45 -681.58 -1047.09
108 Gross.Profits 1090.18 9063.85 18598.68 7620.40 9318.03
109 Gross.Losses -2132.46 -920.78 -2248.45 -681.58 -1047.09
110 Std.Dev.Trade.PL 463.66 1253.96 5680.01 1285.82 1537.81
111 Percent.Positive 37.50 85.71 80.00 83.33 85.71
112 Percent.Negative 62.50 14.29 20.00 16.67 14.29
Profit.Factor 0.51 9.84 8.27 11.18 8.90
113 Avg.Win.Trade 363.39 1510.64 4649.67 1524.08 1553.00
114 Med.Win.Trade 326.19 1375.19 2343.25 1551.96 1241.86
115 Avg.Losing.Trade -426.49 -920.78 -2248.45 -681.58 -1047.09
116 Med.Losing.Trade -297.11 -920.78 -2248.45 -681.58 -1047.09
Avg.Daily.PL -130.28 1160.35 3721.63 1167.22 1225.92
117
Med.Daily.PL -190.63 1106.96 2170.61 1551.96 1032.03
118 Std.Dev.Daily.PL 463.66 1373.62 6454.23 1437.28 1679.67
119 Ann.Sharpe -4.46 13.41 9.15 12.89 11.59
120 Max.Drawdown -3334.35 -2518.13 -4156.71 -2212.82 -2700.70
121 Profit.To.Max.Draw -0.31 3.23 3.93 3.14 3.06
Avg.WinLoss.Ratio 0.85 1.64 2.07 2.24 1.48
122 Med.WinLoss.Ratio 1.10 1.49 1.04 2.28 1.19
123 Max.Equity 1995.24 9004.95 17110.53 7130.66 9488.70
124 Min.Equity -1736.55 -116.14 -468.28 -106.64 -134.79
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
End.Equity -1042.28 8143.08 16350.23 6938.82 8270.94
140
141 XLK XLP XLU XLV XLY
142 Num.Txns 13.00 13.00 11.00 17.00 15.00
143 Num.Trades 7.00 7.00 6.00 9.00 8.00
144 Net.Trading.PL 3773.49 5237.29 7443.30 -2400.55 2813.65
Avg.Trade.PL 539.07 748.18 1240.55 -266.73 351.71
145 Med.Trade.PL 11.43 320.54 164.75 -237.80 -130.81
146 Largest.Winner 3116.75 2419.39 6111.02 933.17 2821.36
147 Largest.Loser -871.76 -965.46 -1390.74 -2162.93 -572.05
148 Gross.Profits 5172.39 6202.75 9530.05 1757.14 4713.91
149 Gross.Losses -1398.90 -965.46 -2086.75 -4157.69 -1900.26
Std.Dev.Trade.PL 1392.56 1220.14 2826.50 889.12 1191.92
150 Percent.Positive 57.14 85.71 50.00 44.44 37.50
151 Percent.Negative 42.86 14.29 50.00 55.56 62.50
152 Profit.Factor 3.70 6.42 4.57 0.42 2.48
153 Avg.Win.Trade 1293.10 1033.79 3176.68 439.28 1571.30
Med.Win.Trade 1022.11 725.83 3054.43 341.19 1288.17
154
Avg.Losing.Trade -466.30 -965.46 -695.58 -831.54 -380.05
155 Med.Losing.Trade -475.97 -965.46 -660.91 -565.29 -508.62
156 Avg.Daily.PL 568.92 819.46 1415.74 -317.77 315.61
157 Med.Daily.PL -19.87 616.89 -35.09 -319.04 -225.91
158 Std.Dev.Daily.PL 1523.02 1320.53 3123.49 936.31 1282.69
Ann.Sharpe 5.93 9.85 7.20 -5.39 3.91
159 Max.Drawdown -3680.30 -2095.40 -3243.95 -3650.41 -3721.65
160 Profit.To.Max.Draw 1.03 2.50 2.29 -0.66 0.76
161 Avg.WinLoss.Ratio 2.77 1.07 4.57 0.53 4.13
162 Med.WinLoss.Ratio 2.15 0.75 4.62 0.60 2.53
163 Max.Equity 4245.23 5269.06 10132.95 318.90 4439.62
Min.Equity -776.77 -244.67 -772.21 -3331.51 -1497.63
164 End.Equity 3773.49 5237.29 7443.30 -2400.55 2813.65
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
At this point, profit factors become obscene, and even the aggregate profit factor (sum of all gross profits
divided by the negative sum of all gross losses) clocks in above 9, with the average percentage correct being
above 70% (mean of the percent positive). In reality, this turns Trend Vigor into an up-or-down classifier (to
use some machine-learning terminology), with no-in betweens, as youll see in a moment.

Here are the daily stats.

1 EFA EPP EWA EWC EWG


Total.Net.Profit 9095.11 12779.16 14602.67 12673.96 11222.15
2
Total.Days 1322.00 1414.00 1412.00 1492.00 1252.00
3 Winning.Days 725.00 773.00 784.00 829.00 697.00
4 Losing.Days 597.00 641.00 628.00 663.00 555.00
5 Avg.Day.PL 6.88 9.04 10.34 8.49 8.96
6 Med.Day.PL 13.62 14.90 21.27 20.66 19.16
Largest.Winner 568.38 880.27 1041.16 567.09 528.85
7 Largest.Loser -576.56 -862.67 -975.68 -631.38 -864.63
8 Gross.Profits 71000.29 97398.68 111477.67 96460.68 80358.74
9 Gross.Losses -61905.18 -84619.52 -96875.01 -83786.73 -69136.60
10 Std.Dev.Daily.PL 134.58 178.50 201.37 157.55 158.11
11 Percent.Positive 54.84 54.67 55.52 55.56 55.67
Percent.Negative 45.16 45.33 44.48 44.44 44.33
12 Profit.Factor 1.15 1.15 1.15 1.15 1.16
13 Avg.Win.Day 97.93 126.00 142.19 116.36 115.29
14 Med.Win.Day 79.54 95.29 109.27 93.87 91.68
15 Avg.Losing.Day -103.69 -132.01 -154.26 -126.38 -124.57
Med.Losing.Day -72.20 -84.37 -109.70 -93.87 -91.16
16 Avg.Daily.PL 6.88 9.04 10.34 8.49 8.96
17 Med.Daily.PL 13.62 14.90 21.27 20.66 19.16
18 Std.Dev.Daily.PL.1 134.58 178.50 201.37 157.55 158.11
19 Ann.Sharpe 0.81 0.80 0.82 0.86 0.90
20 Max.Drawdown -2804.25 -3977.43 -4487.98 -4446.67 -3101.41
Profit.To.Max.Draw 3.24 3.21 3.25 2.85 3.62
21 Avg.WinLoss.Ratio 0.94 0.95 0.92 0.92 0.93
22 Med.WinLoss.Ratio 1.10 1.13 1.00 1.00 1.01
23 Max.Equity 10373.87 14886.32 16959.46 12828.77 12321.51
24 Min.Equity -165.27 -186.62 -399.56 -272.20 -16.66
25 End.Equity 9095.11 12779.16 14602.67 12673.96 11222.15
26
EWH EWJ EWS EWT
27 Total.Net.Profit 15840.82 5176.40 18882.47 3321.05
28 Total.Days 1447.00 1100.00 1510.00 1250.00
29 Winning.Days 762.00 578.00 835.00 639.00
30 Losing.Days 685.00 522.00 675.00 611.00
Avg.Day.PL 10.95 4.71 12.50 2.66
31 Med.Day.PL 13.07 14.51 26.15 8.46
32 Largest.Winner 1319.35 559.95 1304.43 1170.33
33 Largest.Loser -1338.75 -846.93 -1618.16 -1445.34
34 Gross.Profits 123714.47 65127.12 133821.56 93059.51
35 Gross.Losses -107873.66 -59950.72 -114939.08 -89738.46
Std.Dev.Daily.PL 235.97 147.88 241.58 198.13
36 Percent.Positive 52.66 52.55 55.30 51.12
37 Percent.Negative 47.34 47.45 44.70 48.88
38 Profit.Factor 1.15 1.09 1.16 1.04
39 Avg.Win.Day 162.35 112.68 160.27 145.63
Med.Win.Day 111.04 94.31 112.39 114.48
40
Avg.Losing.Day -157.48 -114.85 -170.28 -146.87
41 Med.Losing.Day -101.79 -85.77 -113.32 -109.38
42 Avg.Daily.PL 10.95 4.71 12.50 2.66
43 Med.Daily.PL 13.07 14.51 26.15 8.46
44 Std.Dev.Daily.PL.1 235.97 147.88 241.58 198.13
Ann.Sharpe 0.74 0.51 0.82 0.21
45 Max.Drawdown -6279.36 -3186.71 -6357.43 -5074.58
46 Profit.To.Max.Draw 2.52 1.62 2.97 0.65
47 Avg.WinLoss.Ratio 1.03 0.98 0.94 0.99
48 Med.WinLoss.Ratio 1.09 1.10 0.99 1.05
Max.Equity 16555.02 6833.58 19063.41 3473.68
49 Min.Equity -117.59 -396.06 -412.24 -1842.71
End.Equity 15840.82 5176.40 18882.47 3321.05
50
51
EWU EWY EWZ EZU
52 Total.Net.Profit 8340.94 16345.10 29677.36 9371.42
53 Total.Days 1327.00 1329.00 1456.00 1282.00
54 Winning.Days 718.00 726.00 809.00 703.00
55 Losing.Days 609.00 603.00 647.00 579.00
Avg.Day.PL 6.29 12.30 20.38 7.31
56 Med.Day.PL 15.37 26.80 38.84 15.88
57 Largest.Winner 591.81 930.95 1552.63 653.02
58 Largest.Loser -626.26 -921.64 -1664.19 -837.62
59 Gross.Profits 73312.40 131699.63 211601.85 78062.97
60 Gross.Losses -64971.45 -115354.53 -181924.49 -68691.55
Std.Dev.Daily.PL 139.76 245.04 368.97 155.45
61 Percent.Positive 54.11 54.63 55.56 54.84
62 Percent.Negative 45.89 45.37 44.44 45.16
63 Profit.Factor 1.13 1.14 1.16 1.14
64 Avg.Win.Day 102.11 181.40 261.56 111.04
Med.Win.Day 80.81 149.33 208.05 84.24
65 Avg.Losing.Day -106.69 -191.30 -281.18 -118.64
66 Med.Losing.Day -74.99 -134.62 -203.45 -78.91
67 Avg.Daily.PL 6.29 12.30 20.38 7.31
68 Med.Daily.PL 15.37 26.80 38.84 15.88
69 Std.Dev.Daily.PL.1 139.76 245.04 368.97 155.45
Ann.Sharpe 0.71 0.80 0.88 0.75
70 Max.Drawdown -2806.72 -4656.74 -8660.23 -3353.89
71 Profit.To.Max.Draw 2.97 3.51 3.43 2.79
72 Avg.WinLoss.Ratio 0.96 0.95 0.93 0.94
73 Med.WinLoss.Ratio 1.08 1.11 1.02 1.07
74 Max.Equity 9627.51 16548.01 31682.83 11221.49
Min.Equity -253.67 0.00 -699.79 -119.44
75 End.Equity 8340.94 16345.10 29677.36 9371.42
76
77 IEF IGE IYR IYZ LQD
78 Total.Net.Profit 835.02 14116.64 12860.27 5906.68 2177.09
79 Total.Days 1300.00 1557.00 1358.00 1352.00 1353.00
Winning.Days 658.00 847.00 738.00 701.00 724.00
80 Losing.Days 642.00 710.00 620.00 651.00 629.00
81 Avg.Day.PL 0.64 9.07 9.47 4.37 1.61
82 Med.Day.PL 1.17 22.95 13.29 6.22 4.38
83 Largest.Winner 365.18 848.16 1014.33 478.75 200.55
84 Largest.Loser -199.68 -1047.33 -840.63 -560.06 -260.62
Gross.Profits 24532.29 132479.70 90821.52 62514.78 23695.57
85 Gross.Losses -23697.27 -118363.07 -77961.26 -56608.11 -21518.48
86 Std.Dev.Daily.PL 49.69 213.61 175.83 118.94 44.01
87 Percent.Positive 50.62 54.40 54.34 51.85 53.51
88 Percent.Negative 49.38 45.60 45.66 48.15 46.49
Profit.Factor 1.04 1.12 1.16 1.10 1.10
89
Avg.Win.Day 37.28 156.41 123.06 89.18 32.73
90 Med.Win.Day 28.82 124.52 88.98 69.57 26.67
91 Avg.Losing.Day -36.91 -166.71 -125.74 -86.96 -34.21
92 Med.Losing.Day -28.18 -125.16 -84.29 -62.95 -26.77
93 Avg.Daily.PL 0.64 9.07 9.47 4.37 1.61
Med.Daily.PL 1.17 22.95 13.29 6.22 4.38
94 Std.Dev.Daily.PL.1 49.69 213.61 175.83 118.94 44.01
95 Ann.Sharpe 0.21 0.67 0.85 0.58 0.58
96 Max.Drawdown -1345.79 -4492.64 -4545.72 -3655.24 -1126.20
97 Profit.To.Max.Draw 0.62 3.14 2.83 1.62 1.93
98 Avg.WinLoss.Ratio 1.01 0.94 0.98 1.03 0.96
Med.WinLoss.Ratio 1.02 0.99 1.06 1.11 1.00
99 Max.Equity 1756.16 14420.81 13193.50 5906.68 2600.28
100 Min.Equity -714.17 -360.99 0.00 -1458.57 -750.84
101 End.Equity 835.02 14116.64 12860.27 5906.68 2177.09
102
103 RWR SHY TLT XLB XLE
Total.Net.Profit 15725.34 2126.96 -1042.28 8143.08 16350.23
104 Total.Days 1373.00 1617.00 1152.00 1324.00 1551.00
Winning.Days 744.00 904.00 569.00 720.00 852.00
105
Losing.Days 629.00 713.00 583.00 604.00 699.00
106 Avg.Day.PL 11.45 1.32 -0.90 6.15 10.54
107 Med.Day.PL 14.97 1.31 -1.15 15.83 24.94
108 Largest.Winner 1126.73 57.15 532.71 715.64 1037.19
109 Largest.Loser -976.30 -67.00 -377.39 -582.22 -1019.83
Gross.Profits 100846.82 8420.38 38752.96 84332.47 147238.93
110 Gross.Losses -85121.48 -6293.43 -39795.24 -76189.40 -130888.71
111 Std.Dev.Daily.PL 193.61 12.14 92.65 159.83 242.37
112 Percent.Positive 54.19 55.91 49.39 54.38 54.93
113 Percent.Negative 45.81 44.09 50.61 45.62 45.07
114 Profit.Factor 1.18 1.34 0.97 1.11 1.12
Avg.Win.Day 135.55 9.31 68.11 117.13 172.82
115 Med.Win.Day 95.73 7.26 50.05 99.01 132.61
116 Avg.Losing.Day -135.33 -8.83 -68.26 -126.14 -187.25
117 Med.Losing.Day -91.57 -6.86 -50.02 -90.01 -132.46
118 Avg.Daily.PL 11.45 1.32 -0.90 6.15 10.54
Med.Daily.PL 14.97 1.31 -1.15 15.83 24.94
119 Std.Dev.Daily.PL.1 193.61 12.14 92.65 159.83 242.37
120 Ann.Sharpe 0.94 1.72 -0.16 0.61 0.69
121 Max.Drawdown -4720.58 -258.24 -3334.35 -2518.13 -4156.71
122 Profit.To.Max.Draw 3.33 8.24 -0.31 3.23 3.93
123 Avg.WinLoss.Ratio 1.00 1.06 1.00 0.93 0.92
Med.WinLoss.Ratio 1.05 1.06 1.00 1.10 1.00
124 Max.Equity 16148.05 2169.34 1995.24 9004.95 17110.53
125 Min.Equity 0.00 -62.71 -1736.55 -116.14 -468.28
126 End.Equity 15725.34 2126.96 -1042.28 8143.08 16350.23
127
128 XLF XLI XLK XLP XLU
129 Total.Net.Profit 6938.82 8270.94 3773.49 5237.29 7443.30
Total.Days 1168.00 1320.00 1227.00 1429.00 1459.00
130 Winning.Days 623.00 722.00 670.00 780.00 805.00
131 Losing.Days 545.00 598.00 557.00 649.00 654.00
132 Avg.Day.PL 5.94 6.27 3.08 3.67 5.10
133 Med.Day.PL 10.20 11.53 13.24 8.69 13.99
Largest.Winner 584.93 747.16 691.12 415.09 393.51
134 Largest.Loser -650.83 -608.16 -526.35 -566.03 -475.47
135 Gross.Profits 57073.77 64421.38 60132.26 46969.42 62856.16
136 Gross.Losses -50134.96 -56150.44 -56358.77 -41732.13 -55412.87
137 Std.Dev.Daily.PL 129.53 123.59 127.43 83.31 108.03
138 Percent.Positive 53.34 54.70 54.60 54.58 55.17
Percent.Negative 46.66 45.30 45.40 45.42 44.83
139 Profit.Factor 1.14 1.15 1.07 1.13 1.13
140 Avg.Win.Day 91.61 89.23 89.75 60.22 78.08
141 Med.Win.Day 64.79 72.02 65.43 47.42 63.25
142 Avg.Losing.Day -91.99 -93.90 -101.18 -64.30 -84.73
Med.Losing.Day -59.41 -67.06 -71.16 -47.83 -59.11
143
Avg.Daily.PL 5.94 6.27 3.08 3.67 5.10
144 Med.Daily.PL 10.20 11.53 13.24 8.69 13.99
145 Std.Dev.Daily.PL.1 129.53 123.59 127.43 83.31 108.03
146 Ann.Sharpe 0.73 0.80 0.38 0.70 0.75
147 Max.Drawdown -2212.82 -2700.70 -3680.30 -2095.40 -3243.95
Profit.To.Max.Draw 3.14 3.06 1.03 2.50 2.29
148 Avg.WinLoss.Ratio 1.00 0.95 0.89 0.94 0.92
149 Med.WinLoss.Ratio 1.09 1.07 0.92 0.99 1.07
150 Max.Equity 7130.66 9488.70 4245.23 5269.06 10132.95
151 Min.Equity -106.64 -134.79 -776.77 -244.67 -772.21
152 End.Equity 6938.82 8270.94 3773.49 5237.29 7443.30
153
XLV XLY
154 Total.Net.Profit -2400.55 2813.65
155 Total.Days 1114.00 1123.00
156 Winning.Days 560.00 588.00
157 Losing.Days 554.00 535.00
Avg.Day.PL -2.15 2.51
158 Med.Day.PL 3.02 8.24
159 Largest.Winner 883.88 693.65
Largest.Loser -820.10 -524.37
160
Gross.Profits 35341.85 50246.96
161 Gross.Losses -37742.40 -47433.31
162 Std.Dev.Daily.PL 93.29 119.81
163 Percent.Positive 50.27 52.36
164 Percent.Negative 49.73 47.64
Profit.Factor 0.94 1.06
165 Avg.Win.Day 63.11 85.45
166 Med.Win.Day 51.38 63.20
167 Avg.Losing.Day -68.13 -88.66
168 Med.Losing.Day -49.88 -65.09
169 Avg.Daily.PL -2.15 2.51
Med.Daily.PL 3.02 8.24
170 Std.Dev.Daily.PL.1 93.29 119.81
171 Ann.Sharpe -0.37 0.33
172 Max.Drawdown -3650.41 -3721.65
173 Profit.To.Max.Draw -0.66 0.76
Avg.WinLoss.Ratio 0.93 0.96
174 Med.WinLoss.Ratio 1.03 0.97
175 Max.Equity 318.90 4439.62
176 Min.Equity -3331.51 -1497.63
177 End.Equity -2400.55 2813.65
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216

Once again, portfolio comparisons:

Basically, this variant seemingly maximizes market exposure. Here are the three relevant statistics:

1
> SharpeRatio.annualized(portfRets)
2 [,1]
3 Annualized Sharpe Ratio (Rf=0%) 0.7911671
4 > Return.annualized(portfRets)
5 [,1]
Annualized Return 0.1111565
6 > maxDrawdown(portfRets)
7 [1] 0.2038124
8

And finally, an equity curve demonstrating the indicator at its reasonable limit (that is, zeroat the other end
of the spectrum, when I used a delta of .4, there was only one trade on one of the instruments, and it was a
bad trade, so thats definitely not an interesting case).
As you can see, as the delta parameter becomes smaller and smaller, the sensitivity to a trend increases. At
the limit, it essentially becomes akin to an either-or classifier. So basically, for those with the statistics
backgrounds (and if youve understood everything thus far, you have one), then the confusion matrix
becomes go long in a trend, go long without a trend, dont go long but miss a trend, stay out of the
market in which theres no trend, and this variant essentially leans towards the idea of I have a slight
hunch theres a trend. Oh well. Thats enough! Time to buy! And so long as so much as even a hunch
persists, the strategy will stay long.

Interestingly enough, as judging by the percentage correct and the trade statistics, the ability of the Trend
Vigor indicator to correctly predict seems to be served by the statistics. That, or it could just be that in quite
a few seemingly separate cases, I got lucky with my parameters (always a possibility).

One *last* variant to look at, with this evidence in hand, is whether the Trend Vigor, with its tendency to
buy (or not buy) at a whim, yet getting these correct, is whether or not it would work on a shorter time-
frame.

Lets set the period from 100 to, say, 20. That is, a period of 20, and a delta of 0.

As you may guess, this changes the characteristics of the strategy in terms of what trade statistics
considerably. It sacrifices the win-over-the-long-haul philosophy in favor of a style more akin to spray-and-
pray, rat-ta-tat-tat, or twitch trading.

Here are the trade stats:

1 EFA EPP EWA EWC EWG


Num.Txns 63.00 63.00 57.00 67.00 59.00
2
Num.Trades 32.00 32.00 29.00 34.00 30.00
3 Net.Trading.PL 10328.66 11706.48 14951.72 10930.59 11660.57
4 Avg.Trade.PL 322.77 365.83 515.58 321.49 388.69
5 Med.Trade.PL 105.46 118.05 228.71 1.33 -12.68
6 Largest.Winner 2279.85 2396.63 3471.56 2690.74 2758.24
Largest.Loser -1263.24 -988.61 -924.28 -983.47 -1871.14
7 Gross.Profits 14668.25 15556.53 19711.78 17893.46 17887.77
8 Gross.Losses -4339.59 -3850.04 -4760.05 -6962.87 -6227.20
9 Std.Dev.Trade.PL 777.48 845.22 1144.47 958.73 1098.44
10 Percent.Positive 65.62 59.38 58.62 50.00 43.33
11 Percent.Negative 34.38 40.62 41.38 50.00 56.67
Profit.Factor 3.38 4.04 4.14 2.57 2.87
12 Avg.Win.Trade 698.49 818.76 1159.52 1052.56 1375.98
Med.Win.Trade 537.00 477.74 406.41 1147.88 1344.79
13
Avg.Losing.Trade -394.51 -296.16 -396.67 -409.58 -366.31
14 Med.Losing.Trade -344.54 -156.95 -443.07 -348.37 -298.35
15 Avg.Daily.PL 328.05 372.03 521.65 289.41 403.80
16 Med.Daily.PL 101.91 110.59 226.95 -41.34 -11.20
17 Std.Dev.Daily.PL 789.75 858.45 1165.00 954.88 1114.71
Ann.Sharpe 6.59 6.88 7.11 4.81 5.75
18 Max.Drawdown -3211.45 -2427.49 -2405.94 -3523.79 -4453.04
19 Profit.To.Max.Draw 3.22 4.82 6.21 3.10 2.62
20 Avg.WinLoss.Ratio 1.77 2.76 2.92 2.57 3.76
21 Med.WinLoss.Ratio 1.56 3.04 0.92 3.29 4.51
22 Max.Equity 10842.33 13002.93 16586.93 12975.13 12865.77
Min.Equity -16.31 -109.20 0.00 -403.80 -163.53
23 End.Equity 10328.66 11706.48 14951.72 10930.59 11660.57
24
25 EWH EWJ EWS EWT EWU
26 Num.Txns 57.00 69.00 53.00 61.00 55.00
27 Num.Trades 29.00 34.00 27.00 31.00 27.00
Net.Trading.PL 12897.27 4660.14 14727.03 7944.62 7348.04
28 Avg.Trade.PL 444.73 137.06 545.45 256.28 272.15
29 Med.Trade.PL 181.76 -25.35 448.00 -65.56 73.74
30 Largest.Winner 3627.23 1400.58 3929.35 2827.61 2861.20
31 Largest.Loser -985.69 -785.43 -959.90 -1435.07 -1208.44
32 Gross.Profits 16866.14 9250.53 18536.96 15689.70 12192.51
Gross.Losses -3968.87 -4590.39 -3809.93 -7745.07 -4844.48
33 Std.Dev.Trade.PL 1017.17 550.76 1137.96 1044.37 915.22
34 Percent.Positive 68.97 47.06 70.37 48.39 59.26
35 Percent.Negative 31.03 52.94 29.63 51.61 40.74
36 Profit.Factor 4.25 2.02 4.87 2.03 2.52
37 Avg.Win.Trade 843.31 578.16 975.63 1045.98 762.03
Med.Win.Trade 492.64 405.30 531.92 707.58 373.84
38 Avg.Losing.Trade -440.99 -255.02 -476.24 -484.07 -440.41
39 Med.Losing.Trade -498.05 -188.85 -566.37 -367.15 -355.87
40 Avg.Daily.PL 462.31 104.67 560.53 191.39 279.48
41 Med.Daily.PL 186.54 -28.59 459.00 -70.68 50.79
Std.Dev.Daily.PL 1031.33 525.38 1157.74 996.64 932.54
42 Ann.Sharpe 7.12 3.16 7.69 3.05 4.76
43 Max.Drawdown -3217.65 -4387.88 -3405.18 -4227.76 -2937.97
44 Profit.To.Max.Draw 4.01 1.06 4.32 1.88 2.50
45 Avg.WinLoss.Ratio 1.91 2.27 2.05 2.16 1.73
46 Med.WinLoss.Ratio 0.99 2.15 0.94 1.93 1.05
Max.Equity 13521.46 6000.56 15436.93 9038.22 8680.76
47 Min.Equity -42.01 -224.21 -1025.47 -1277.92 -464.92
48 End.Equity 12897.27 4660.14 14727.03 7944.62 7348.04
49
50 EWY EWZ EZU IEF IGE
51 Num.Txns 63.00 65.00 57.00 62.00 67.00
Num.Trades 32.00 33.00 29.00 31.00 34.00
52
Net.Trading.PL 12546.44 24852.10 11517.70 4753.61 9332.27
53 Avg.Trade.PL 392.08 753.09 397.16 153.34 274.48
54 Med.Trade.PL 65.75 462.80 62.94 97.07 25.89
55 Largest.Winner 3227.55 4129.19 2673.10 938.96 1874.11
56 Largest.Loser -1138.25 -1397.89 -1504.99 -349.00 -939.08
Gross.Profits 19138.92 32892.49 16773.02 5715.50 14964.70
57 Gross.Losses -6592.48 -8040.39 -5255.32 -961.89 -5632.43
58 Std.Dev.Trade.PL 1139.40 1521.21 1012.85 273.84 787.90
59 Percent.Positive 53.12 57.58 55.17 70.97 52.94
60 Percent.Negative 46.88 42.42 44.83 29.03 47.06
61 Profit.Factor 2.90 4.09 3.19 5.94 2.66
Avg.Win.Trade 1125.82 1731.18 1048.31 259.80 831.37
62 Med.Win.Trade 665.93 1333.10 835.84 190.61 821.62
63 Avg.Losing.Trade -439.50 -574.31 -404.26 -106.88 -352.03
64 Med.Losing.Trade -303.33 -562.67 -296.63 -80.24 -264.51
65 Avg.Daily.PL 388.31 762.17 408.36 153.34 206.26
Med.Daily.PL 13.15 470.00 62.27 97.07 24.11
66 Std.Dev.Daily.PL 1158.03 1544.64 1029.61 273.84 690.66
67 Ann.Sharpe 5.32 7.83 6.30 8.89 4.74
Max.Drawdown -4645.24 -3257.05 -3413.71 -578.24 -2724.91
68
Profit.To.Max.Draw 2.70 7.63 3.37 8.22 3.42
69 Avg.WinLoss.Ratio 2.56 3.01 2.59 2.43 2.36
70 Med.WinLoss.Ratio 2.20 2.37 2.82 2.38 3.11
71 Max.Equity 12546.44 26158.50 13292.18 4906.20 9504.76
72 Min.Equity -682.05 0.00 0.00 -33.44 -422.88
End.Equity 12546.44 24852.10 11517.70 4753.61 9332.27
73
74 IYR IYZ LQD RWR SHY
75 Num.Txns 57.00 67.00 60.00 57.00 54.00
76 Num.Trades 29.00 34.00 30.00 29.00 25.00
77 Net.Trading.PL 11784.87 3862.91 5120.54 12724.61 2122.23
78 Avg.Trade.PL 406.37 113.62 170.68 438.78 84.89
Med.Trade.PL 185.62 -57.11 39.73 125.87 16.55
79 Largest.Winner 3974.51 1380.22 1515.52 3092.87 808.92
80 Largest.Loser -785.87 -1172.77 -737.21 -849.73 -70.04
81 Gross.Profits 16606.09 10171.73 6591.01 17523.83 2332.06
82 Gross.Losses -4821.22 -6308.82 -1470.47 -4799.22 -209.83
Std.Dev.Trade.PL 1145.72 616.42 417.69 1022.20 183.23
83 Percent.Positive 62.07 44.12 66.67 55.17 64.00
84 Percent.Negative 37.93 55.88 33.33 44.83 36.00
85 Profit.Factor 3.44 1.61 4.48 3.65 11.11
86 Avg.Win.Trade 922.56 678.12 329.55 1095.24 145.75
87 Med.Win.Trade 297.43 652.59 134.84 906.46 75.00
Avg.Losing.Trade -438.29 -332.04 -147.05 -369.17 -23.31
88 Med.Losing.Trade -349.87 -275.45 -82.17 -355.79 -21.51
89 Avg.Daily.PL 410.73 81.37 170.68 443.64 84.89
90 Med.Daily.PL 171.77 -57.61 39.73 106.12 16.55
91 Std.Dev.Daily.PL 1166.50 596.14 417.69 1040.62 183.23
92 Ann.Sharpe 5.59 2.17 6.49 6.77 7.35
Max.Drawdown -3274.47 -3375.87 -1372.68 -2818.87 -155.30
93 Profit.To.Max.Draw 3.60 1.14 3.73 4.51 13.67
94 Avg.WinLoss.Ratio 2.10 2.04 2.24 2.97 6.25
95 Med.WinLoss.Ratio 0.85 2.37 1.64 2.55 3.49
96 Max.Equity 14392.21 5329.35 5186.13 14807.38 2164.16
Min.Equity -279.58 -317.86 -49.93 -157.88 -4.04
97 End.Equity 11784.87 3862.91 5120.54 12724.61 2122.23
98
99 TLT XLB XLE XLF XLI
100 Num.Txns 66.00 69.00 75.00 67.00 61.00
101 Num.Trades 33.00 35.00 38.00 34.00 31.00
102 Net.Trading.PL 3413.99 5977.21 6441.87 5609.93 8660.57
Avg.Trade.PL 103.45 170.78 169.52 165.00 279.37
103 Med.Trade.PL -3.63 -83.75 -9.57 -51.46 153.63
104 Largest.Winner 1565.81 1617.61 1866.44 2722.10 1877.40
105 Largest.Loser -557.57 -609.79 -1481.92 -1198.56 -665.85
106 Gross.Profits 7060.83 12273.84 14304.04 11466.12 12686.72
Gross.Losses -3646.84 -6296.63 -7862.18 -5856.19 -4026.15
107
Std.Dev.Trade.PL 460.12 672.56 815.91 776.04 679.43
108 Percent.Positive 48.48 45.71 47.37 47.06 54.84
109 Percent.Negative 51.52 54.29 52.63 52.94 45.16
110 Profit.Factor 1.94 1.95 1.82 1.96 3.15
111 Avg.Win.Trade 441.30 767.11 794.67 716.63 746.28
Med.Win.Trade 334.21 774.71 567.38 389.75 531.89
112 Avg.Losing.Trade -214.52 -331.40 -393.11 -325.34 -287.58
113 Med.Losing.Trade -251.27 -334.69 -362.33 -215.27 -286.47
114 Avg.Daily.PL 103.45 119.78 103.25 166.56 237.50
115 Med.Daily.PL -3.63 -96.78 -14.83 -59.69 130.21
116 Std.Dev.Daily.PL 460.12 610.13 716.01 788.01 649.09
Ann.Sharpe 3.57 3.12 2.29 3.36 5.81
117 Max.Drawdown -2817.81 -2503.48 -4987.44 -4930.20 -1956.37
118 Profit.To.Max.Draw 1.21 2.39 1.29 1.14 4.43
119 Avg.WinLoss.Ratio 2.06 2.31 2.02 2.20 2.60
120 Med.WinLoss.Ratio 1.33 2.31 1.57 1.81 1.86
Max.Equity 5371.15 6455.14 8728.55 7579.35 8667.19
121 Min.Equity -158.45 -490.54 -246.66 -531.75 -420.93
122 End.Equity 3413.99 5977.21 6441.87 5609.93 8660.57
123
XLK XLP XLU XLV XLY
124
Num.Txns 65.00 73.00 57.00 71.00 59.00
125 Num.Trades 33.00 37.00 28.00 36.00 30.00
126 Net.Trading.PL 4961.98 4662.87 10652.74 2240.98 10791.01
127 Avg.Trade.PL 150.36 126.02 380.45 62.25 359.70
128 Med.Trade.PL 27.70 -3.74 239.19 20.12 47.17
Largest.Winner 1665.69 1210.01 2127.10 1071.64 2201.18
129 Largest.Loser -848.60 -375.31 -1027.85 -1019.87 -526.48
130 Gross.Profits 10911.42 7698.10 13356.14 6743.69 14198.58
131 Gross.Losses -5949.44 -3035.22 -2703.40 -4502.72 -3407.57
132 Std.Dev.Trade.PL 644.75 385.79 697.17 424.35 812.76
133 Percent.Positive 51.52 45.95 75.00 55.56 53.33
Percent.Negative 48.48 54.05 25.00 44.44 46.67
134 Profit.Factor 1.83 2.54 4.94 1.50 4.17
135 Avg.Win.Trade 641.85 452.83 636.01 337.18 887.41
136 Med.Win.Trade 596.95 439.53 567.87 268.84 769.48
137 Avg.Losing.Trade -371.84 -151.76 -386.20 -281.42 -243.40
Med.Losing.Trade -332.32 -132.19 -351.24 -198.33 -201.01
138 Avg.Daily.PL 153.44 126.43 392.89 63.18 318.03
139 Med.Daily.PL -4.08 -3.95 244.66 15.94 16.97
140 Std.Dev.Daily.PL 654.82 391.25 707.28 430.50 793.86
141 Ann.Sharpe 3.72 5.13 8.82 2.33 6.36
142 Max.Drawdown -3122.38 -1207.25 -1975.52 -1692.71 -2096.56
Profit.To.Max.Draw 1.59 3.86 5.39 1.32 5.15
143 Avg.WinLoss.Ratio 1.73 2.98 1.65 1.20 3.65
144 Med.WinLoss.Ratio 1.80 3.33 1.62 1.36 3.83
145 Max.Equity 5806.42 4786.14 10838.46 3229.36 10908.43
146 Min.Equity -744.34 -230.94 0.00 -26.15 -187.64
147 End.Equity 4961.98 4662.87 10652.74 2240.98 10791.01
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

Some aggregate trade stats (that I implemented as I was writing this post, so forgive the fact that they
werent in previous outputs):

1
2 > mean(tStats$Percent.Positive)
[1] 55.921
3 > (aggPF <- sum(tStats$Gross.Profits)/-sum(tStats$Gross.Losses))
4 [1] 2.889328
5 > (aggCorrect <- mean(tStats$Percent.Positive))
6 [1] 55.921
> (numTrades <- sum(tStats$Num.Trades))
7
[1] 946
8 > (meanAvgWLR <- mean(tStats$Avg.WinLoss.Ratio))
9 [1] 2.495
10

In other words, over nearly a thousand relatively short-term momentum trades (can you say whipsaw?),
the strategy still gets it right more than half the time, and the trades it *does* get right, on average, it gets
them right by a ratio of 2.5 to 1. Of course, this backtest doesnt take transaction costs into account, and
when dealing with these shorter-term strategies, if youre a retail investor out to try and rub two pennies
together and youre getting taken for a ride on the order of $10 per buy or sell order from ETrade, youll
have to look at the average trade P&L. (Also, if youre a retail investor, your bigger obstacle would be the
$3,000,000 to be able to even trade something like this.)

Again, the daily statistics:

1 EFA EPP EWA EWC EWG


Total.Net.Profit 10328.66 11706.48 14951.72 10930.59 11660.57
2
Total.Days 1316.00 1323.00 1303.00 1297.00 1281.00
3 Winning.Days 713.00 722.00 730.00 729.00 719.00
4 Losing.Days 603.00 601.00 573.00 568.00 562.00
5 Avg.Day.PL 7.85 8.85 11.47 8.43 9.10
6 Med.Day.PL 10.61 12.80 17.88 19.87 19.80
Largest.Winner 496.25 718.51 694.25 563.65 582.80
7 Largest.Loser -479.06 -702.36 -817.83 -738.35 -582.80
8 Gross.Profits 62165.44 75323.28 85846.23 74892.07 77119.80
9 Gross.Losses -51836.78 -63616.80 -70894.51 -63961.48 -65459.22
10 Std.Dev.Daily.PL 116.04 145.52 164.08 144.76 147.76
11 Percent.Positive 54.18 54.57 56.02 56.21 56.13
Percent.Negative 45.82 45.43 43.98 43.79 43.87
12 Profit.Factor 1.20 1.18 1.21 1.17 1.18
13 Avg.Win.Day 87.19 104.33 117.60 102.73 107.26
14 Med.Win.Day 69.61 82.93 96.06 83.06 87.10
15 Avg.Losing.Day -85.96 -105.85 -123.73 -112.61 -116.48
Med.Losing.Day -64.01 -70.20 -88.59 -77.41 -80.38
16 Avg.Daily.PL 7.85 8.85 11.47 8.43 9.10
17 Med.Daily.PL 10.61 12.80 17.88 19.87 19.80
18 Std.Dev.Daily.PL.1 116.04 145.52 164.08 144.76 147.76
19 Ann.Sharpe 1.07 0.97 1.11 0.92 0.98
20 Max.Drawdown -3211.45 -2427.49 -2405.94 -3523.79 -4453.04
Profit.To.Max.Draw 3.22 4.82 6.21 3.10 2.62
21 Avg.WinLoss.Ratio 1.01 0.99 0.95 0.91 0.92
22 Med.WinLoss.Ratio 1.09 1.18 1.08 1.07 1.08
23 Max.Equity 10842.33 13002.93 16586.93 12975.13 12865.77
24 Min.Equity -16.31 -109.20 0.00 -403.80 -163.53
25 End.Equity 10328.66 11706.48 14951.72 10930.59 11660.57
26
EWH EWJ EWS EWT EWU
27 Total.Net.Profit 12897.27 4660.14 14727.03 7944.62 7348.04
28 Total.Days 1246.00 1108.00 1302.00 1173.00 1250.00
Winning.Days 667.00 568.00 726.00 608.00 670.00
29
Losing.Days 579.00 540.00 576.00 565.00 580.00
30 Avg.Day.PL 10.35 4.21 11.31 6.77 5.88
31 Med.Day.PL 14.00 9.37 22.80 8.93 12.28
32 Largest.Winner 780.02 553.05 1036.49 1451.05 536.21
33 Largest.Loser -927.10 -562.11 -1149.10 -1250.21 -573.84
Gross.Profits 79332.19 58476.51 86625.31 84432.94 64333.36
34 Gross.Losses -66434.93 -53816.37 -71898.28 -76488.32 -56985.33
35 Std.Dev.Daily.PL 160.07 132.14 166.55 190.61 131.32
36 Percent.Positive 53.53 51.26 55.76 51.83 53.60
37 Percent.Negative 46.47 48.74 44.24 48.17 46.40
38 Profit.Factor 1.19 1.09 1.20 1.10 1.13
Avg.Win.Day 118.94 102.95 119.32 138.87 96.02
39 Med.Win.Day 90.55 81.48 91.21 106.86 72.21
40 Avg.Losing.Day -114.74 -99.66 -124.82 -135.38 -98.25
41 Med.Losing.Day -82.06 -78.95 -93.30 -98.23 -69.18
42 Avg.Daily.PL 10.35 4.21 11.31 6.77 5.88
Med.Daily.PL 14.00 9.37 22.80 8.93 12.28
43 Std.Dev.Daily.PL.1 160.07 132.14 166.55 190.61 131.32
44 Ann.Sharpe 1.03 0.51 1.08 0.56 0.71
45 Max.Drawdown -3217.65 -4387.88 -3405.18 -4227.76 -2937.97
46 Profit.To.Max.Draw 4.01 1.06 4.32 1.88 2.50
47 Avg.WinLoss.Ratio 1.04 1.03 0.96 1.03 0.98
Med.WinLoss.Ratio 1.10 1.03 0.98 1.09 1.04
48 Max.Equity 13521.46 6000.56 15436.93 9038.22 8680.76
49 Min.Equity -42.01 -224.21 -1025.47 -1277.92 -464.92
50 End.Equity 12897.27 4660.14 14727.03 7944.62 7348.04
51
52 EWY EWZ EZU IEF IGE
53 Total.Net.Profit 12546.44 24852.10 11517.70 4753.61 9332.27
Total.Days 1245.00 1368.00 1288.00 1220.00 1288.00
54 Winning.Days 687.00 770.00 702.00 647.00 710.00
55 Losing.Days 558.00 598.00 586.00 573.00 578.00
56 Avg.Day.PL 10.08 18.17 8.94 3.90 7.25
57 Med.Day.PL 21.94 37.02 16.02 3.66 18.41
Largest.Winner 738.74 1037.10 599.94 341.03 559.04
58 Largest.Loser -808.23 -1146.86 -609.07 -193.92 -623.74
59 Gross.Profits 97414.83 136096.17 71253.39 24136.54 81842.78
60 Gross.Losses -84868.38 -111244.08 -59735.69 -19382.93 -72510.51
61 Std.Dev.Daily.PL 195.32 238.67 138.16 47.45 157.77
62 Percent.Positive 55.18 56.29 54.50 53.03 55.12
Percent.Negative 44.82 43.71 45.50 46.97 44.88
63 Profit.Factor 1.15 1.22 1.19 1.25 1.13
64 Avg.Win.Day 141.80 176.75 101.50 37.31 115.27
65 Med.Win.Day 110.49 141.00 79.01 29.85 94.60
66 Avg.Losing.Day -152.09 -186.03 -101.94 -33.83 -125.45
Med.Losing.Day -109.42 -134.77 -70.49 -26.24 -95.78
67
Avg.Daily.PL 10.08 18.17 8.94 3.90 7.25
68 Med.Daily.PL 21.94 37.02 16.02 3.66 18.41
69 Std.Dev.Daily.PL.1 195.32 238.67 138.16 47.45 157.77
70 Ann.Sharpe 0.82 1.21 1.03 1.30 0.73
71 Max.Drawdown -4645.24 -3257.05 -3413.71 -578.24 -2724.91
Profit.To.Max.Draw 2.70 7.63 3.37 8.22 3.42
72 Avg.WinLoss.Ratio 0.93 0.95 1.00 1.10 0.92
73 Med.WinLoss.Ratio 1.01 1.05 1.12 1.14 0.99
74 Max.Equity 12546.44 26158.50 13292.18 4906.20 9504.76
75 Min.Equity -682.05 0.00 0.00 -33.44 -422.88
76 End.Equity 12546.44 24852.10 11517.70 4753.61 9332.27
77
IYR IYZ LQD RWR SHY
78 Total.Net.Profit 11784.87 3862.91 5120.54 12724.61 2122.23
79 Total.Days 1312.00 1213.00 1290.00 1324.00 1403.00
80 Winning.Days 711.00 641.00 720.00 713.00 796.00
81 Losing.Days 601.00 572.00 570.00 611.00 607.00
Avg.Day.PL 8.98 3.18 3.97 9.61 1.51
82 Med.Day.PL 13.12 8.69 4.71 9.40 2.15
83 Largest.Winner 1266.62 499.01 267.59 1410.02 71.37
Largest.Loser -1344.56 -517.73 -623.17 -1305.30 -65.40
84
Gross.Profits 85524.01 52701.88 23905.68 89163.11 7220.54
85 Gross.Losses -73739.14 -48838.97 -18785.14 -76438.50 -5098.31
86 Std.Dev.Daily.PL 187.62 114.92 47.09 196.38 11.86
87 Percent.Positive 54.19 52.84 55.81 53.85 56.74
88 Percent.Negative 45.81 47.16 44.19 46.15 43.26
Profit.Factor 1.16 1.08 1.27 1.17 1.42
89 Avg.Win.Day 120.29 82.22 33.20 125.05 9.07
90 Med.Win.Day 83.38 57.42 25.92 83.55 6.47
91 Avg.Losing.Day -122.69 -85.38 -32.96 -125.10 -8.40
92 Med.Losing.Day -75.71 -60.20 -23.53 -77.73 -6.33
93 Avg.Daily.PL 8.98 3.18 3.97 9.61 1.51
Med.Daily.PL 13.12 8.69 4.71 9.40 2.15
94 Std.Dev.Daily.PL.1 187.62 114.92 47.09 196.38 11.86
95 Ann.Sharpe 0.76 0.44 1.34 0.78 2.02
96 Max.Drawdown -3274.47 -3375.87 -1372.68 -2818.87 -155.30
97 Profit.To.Max.Draw 3.60 1.14 3.73 4.51 13.67
Avg.WinLoss.Ratio 0.98 0.96 1.01 1.00 1.08
98 Med.WinLoss.Ratio 1.10 0.95 1.10 1.07 1.02
99 Max.Equity 14392.21 5329.35 5186.13 14807.38 2164.16
100 Min.Equity -279.58 -317.86 -49.93 -157.88 -4.04
101 End.Equity 11784.87 3862.91 5120.54 12724.61 2122.23
102
103 TLT XLB XLE XLF XLI
Total.Net.Profit 3413.99 5977.21 6441.87 5609.93 8660.57
104 Total.Days 1177.00 1262.00 1306.00 1153.00 1285.00
105 Winning.Days 613.00 680.00 702.00 607.00 711.00
106 Losing.Days 564.00 582.00 604.00 546.00 574.00
107 Avg.Day.PL 2.90 4.74 4.93 4.87 6.74
108 Med.Day.PL 5.66 11.89 12.61 8.42 10.49
Largest.Winner 528.00 669.10 951.16 1615.41 609.93
109 Largest.Loser -331.64 -696.80 -1194.78 -1400.78 -478.61
110 Gross.Profits 37930.87 69474.84 85294.45 66345.27 57592.48
111 Gross.Losses -34516.87 -63497.63 -78852.59 -60735.35 -48931.91
112 Std.Dev.Daily.PL 84.71 141.74 170.38 182.33 116.56
Percent.Positive 52.08 53.88 53.75 52.65 55.33
113 Percent.Negative 47.92 46.12 46.25 47.35 44.67
114 Profit.Factor 1.10 1.09 1.08 1.09 1.18
115 Avg.Win.Day 61.88 102.17 121.50 109.30 81.00
116 Med.Win.Day 46.15 84.21 97.96 67.92 59.72
117 Avg.Losing.Day -61.20 -109.10 -130.55 -111.24 -85.25
Med.Losing.Day -43.92 -78.65 -101.67 -64.90 -59.16
118 Avg.Daily.PL 2.90 4.74 4.93 4.87 6.74
119 Med.Daily.PL 5.66 11.89 12.61 8.42 10.49
120 Std.Dev.Daily.PL.1 84.71 141.74 170.38 182.33 116.56
121 Ann.Sharpe 0.54 0.53 0.46 0.42 0.92
Max.Drawdown -2817.81 -2503.48 -4987.44 -4930.20 -1956.37
122
Profit.To.Max.Draw 1.21 2.39 1.29 1.14 4.43
123 Avg.WinLoss.Ratio 1.01 0.94 0.93 0.98 0.95
124 Med.WinLoss.Ratio 1.05 1.07 0.96 1.05 1.01
125 Max.Equity 5371.15 6455.14 8728.55 7579.35 8667.19
126 Min.Equity -158.45 -490.54 -246.66 -531.75 -420.93
End.Equity 3413.99 5977.21 6441.87 5609.93 8660.57
127
128 XLK XLP XLU XLV XLY
129 Total.Net.Profit 4961.98 4662.87 10652.74 2240.98 10791.01
130 Total.Days 1216.00 1284.00 1388.00 1178.00 1234.00
131 Winning.Days 674.00 705.00 770.00 617.00 653.00
132 Losing.Days 542.00 579.00 618.00 561.00 581.00
Avg.Day.PL 4.08 3.63 7.67 1.90 8.74
133 Med.Day.PL 15.35 8.51 13.15 3.87 9.07
134 Largest.Winner 443.80 642.73 945.06 339.99 1098.25
135 Largest.Loser -440.72 -380.30 -721.42 -479.49 -477.11
136 Gross.Profits 56694.07 38477.60 57865.62 39848.98 61218.76
Gross.Losses -51732.09 -33814.73 -47212.88 -37608.01 -50427.75
137 Std.Dev.Daily.PL 119.48 74.90 104.74 87.22 130.20
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154 Percent.Positive 55.43 54.91 55.48 52.38 52.92
155 Percent.Negative 44.57 45.09 44.52 47.62 47.08
156 Profit.Factor 1.10 1.14 1.23 1.06 1.21
157 Avg.Win.Day 84.12 54.58 75.15 64.59 93.75
158 Med.Win.Day 62.97 42.12 61.26 51.22 67.20
Avg.Losing.Day -95.45 -58.40 -76.40 -67.04 -86.79
159 Med.Losing.Day -65.34 -45.63 -53.32 -49.44 -59.22
160 Avg.Daily.PL 4.08 3.63 7.67 1.90 8.74
161 Med.Daily.PL 15.35 8.51 13.15 3.87 9.07
162 Std.Dev.Daily.PL.1 119.48 74.90 104.74 87.22 130.20
Ann.Sharpe 0.54 0.77 1.16 0.35 1.07
163
Max.Drawdown -3122.38 -1207.25 -1975.52 -1692.71 -2096.56
164 Profit.To.Max.Draw 1.59 3.86 5.39 1.32 5.15
165 Avg.WinLoss.Ratio 0.88 0.93 0.98 0.96 1.08
166 Med.WinLoss.Ratio 0.96 0.92 1.15 1.04 1.13
167 Max.Equity 5806.42 4786.14 10838.46 3229.36 10908.43
Min.Equity -744.34 -230.94 0.00 -26.15 -187.64
168 End.Equity 4961.98 4662.87 10652.74 2240.98 10791.01
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

A lot of the cash Sharpe ratios (now in the *daily* statistics, not the trade statistics) are nearing 1. Not
exactly spectacular, by any stretch of the imagination, when considering a short-term trading strategy before
commissions/slippage, but definitely nothing to scoff at. Something I notice just by eyeballing the statistics
is that there definitely seems to be an edge in the percentage of days positive. Of course, I wont rule out the
fact that all of this may simply be the fact that many of these securities are equity indices, and thus, may
have a slightly inherent long bias in them.
Lets move onto the portfolio equity curve.

Looking at this equity curve, the first thing to note is that its strikingly similar to the SPY equity curve up
until the crisis, and the drawdowns happen at about the same exact times. Maybe this means that all of my
global equity ETFs that I chose for the data were correlated because at the end of the day, aside from the few
fixed income ETFs available before 2003, that theyre still separate slices of the equities asset class, or that
my volatility (and returns?) are mainly driven by the 9 XL sectors. Whats also worth noting is that the
strategy attempted to go dumpster diving, to put it kindlythat is, still try to find those positive-momentum
trades in the depths of the financial crisis. While it certainly seemed to try, in this case, the best move would
have been to do nothing at all. However, when the market rebounded, the strategy quickly made up its losses
(and then some).

For the final time in this post, the three portfolio statistics:

1
> SharpeRatio.annualized(portfRets)
2 [,1]
3 Annualized Sharpe Ratio (Rf=0%) 0.9692246
4 > Return.annualized(portfRets)
5 [,1]
Annualized Return 0.1113647
6 > maxDrawdown(portfRets)
7 [1] 0.1801516
8

In other words, an 11% return, at a maximum drawdown of 18%. I am of course, still not pleased with the
last two numbers, since a maximum drawdown larger than the annualized return means that its quite
possible to simply have a down year. However, the idea of an 18% drawdown while seemingly keeping pace
with an S&P 500 (with a simplistic asset allocation and order-sizing strategy, no less) in its good years is
nothing to scoff at. (In my last job, I was responsible for developing the analytics package in terms of
portfolio management. Suffice to say that there are a lot more ways to slice up performance.)

Finally, just for fun, heres the equity curve and the indicator of XLB for this two-parameter (three if you
count trigger lag, and four if you count the threshold setting) configuration:
In other words, for those that prefer the lots and lots of little ones to the long-term trend-following
alternative, there you go.

Interesting to note, comparing the few portfolio equity curves Ive shown in this post, overall, the
performances look somewhat similar regardless of the philosophywhether a very long-term trend-following
approach, or a more short-term orientation. The difference shows up in the trade statistics, but as they say
about roads leading to Romein my opinion, this probably counts as a vote for the robustness of the
strategy.

Now, to conclude this exploration, here are some things I can take away from it:

By adjusting the period and delta parameters, its possible to take what was originally a market mode filter
and:

A) keep it as a double-purpose trend follower and market mode indicator


B) turn it into a long-term trend indicator
C) turn it into a short(er) term momentum trader.

Paradoxically (at least according to the basic risk/reward blabber found in typical academic finance), it
seems that by lowering delta and having a willingness to take on more risk in the form of greater market
exposure, one actually achieves a better annualized Sharpe Ratio than with the default, more risk-averse,
setting.

Next time, Ill look at more intelligent risk-weighting schemes.

Thanks for reading.

A positive batting average trend follower?


Introducing Trend Vigor.
Posted on May 25, 2014 Posted in Dr. John Ehlers, ETFs, QuantStrat, R, Trading 5 Comments
Since this is the first post on this blog, a quick start up for those who may be reading this who dont have my
exact technical background: this blog will mostly use R, and backtesting will be done in the quantstrat
package.

For those of you who follow me from a non-technical background, send me a message, and Ill help you get
started. For those simply not acquainted with the quantstrat package, this is the link to the definitive,
comprehensive guide on quantstrat.

http://www.rinfinance.com/agenda/2013/workshop/Humme+Peterson.pdf

To motivate this post, consider some common wisdom about both mean-reverting and trend-following
strategies. Mean reverting strategies often sport a high percentage of positive trades, but the few negative
trades can hammer the equity curve. On the other side of the equation, trend-following strategies run on a
philosophy of let your winners run and cut your losers, resulting in many small losses and a few wins that
make up for them. However, what if there were an indicator that behaved like the best of both worlds? That
is, capitalize on trends, while cutting out a good portion of whipsaws?

The Trend Vigor Indicator, or TVI as I call it in my DSTrading package, available on my github (see my
about page for the link), created by Dr. John Ehlers (whom I thank for providing the completed code),
attempts to do just that. Heres a link to the original presentation (code incomplete):

http://www.mesasoftware.com/Seminars/Trend%20Modes%20and%20Cycle%20Modes.pdf

As Dr. Ehlers says on the fifth slide, correctly identifying market mode means a great deal. Something I
noticed is that the plot for the trend vigor index seems to be very smooth in general, so when the trend vigor
rises, it generally doesnt whipsaw around very much about any particular quantity (at least at the daily
resolution), so there may be a strategy to take advantage of this possible property.

Heres the corresponding function from the DSTrading package, which I will use in the following demo.
There may also be a trend vigor calculation with one of Dr. Ehlerss adaptive period computation algorithms
built in. In any case, the way it works is this: it takes in a time series, and two parameters: a period, which is
identical to the n parameter in indicators such as SMA and so on, and a delta, which is a trigonometric
parameter to adjust the computation of the bandpass filter (I am not overly familiar with the rationale behind
signal processing, so Ill leave the commentary on the finer points of this parameter to someone more
experienced in this field).

TVI then outputs a time series of a 0-centered trend vigor indicator, along with a pair of oscillators (signal
and lead), which I may touch on in the future.

1 "TVI" <- function(x, period = 20, delta = 0.2, triggerLag = 1, ...) {


if (period != 0) {
2
# static, length-1 period
3 beta <- cos(2 * pi/period)
4 gamma <- 1/cos(4 * pi * delta/period)
5 alpha <- gamma - sqrt(gamma * gamma - 1)
6 BP <- 0.5 * (1 - alpha) * (x - lag(x, 2))
BP[1] <- BP[2] <- 0
7 BP <- filter(BP, c(beta * (1 + alpha), -1 * alpha), method = "recursive")
8 BP <- xts(BP, order.by = index(x))
9 signal <- BP - lag(BP, round(period/2))
10 lead <- 1.4 * (BP - lag(BP, round(period/4)))
11
12 BP2 <- BP * BP
LBP2 <- lag(BP2, round(period/4))
13 power <- runSum(BP2, period) + runSum(LBP2, period)
14 RMS <- sqrt(power/period)
15 PtoP <- 2 * sqrt(2) * RMS
16
17
18
19
20 a1 <- exp(-sqrt(2) * pi/period)
21 b1 <- 2 * a1 * cos(sqrt(2) * pi/period)
22 coef2 <- b1
coef3 <- -a1 * a1
23
coef1 <- 1 - coef2 - coef3
24 trend <- coef1 * (x - lag(x, period))
25 trend[is.na(trend)] <- 0
26 trend <- filter(trend, c(coef2, coef3), method = "recursive")
27 trend <- xts(trend, order.by = index(x))
vigor <- trend/PtoP
28 vigor[vigor > 2] <- 2
29 vigor[vigor < -2] <- -2
30 trigger <- lag(vigor, triggerLag)
31 out <- cbind(vigor, signal, lead, trigger)
32 colnames(out) <- c("vigor", "signal", "lead", "trigger")
return(out)
33 } else {
34 stop("Dynamic period computation not implemented yet.")
35 # TODO -- DYNAMIC PERIOD TREND VIGOR
36 }
37 }
38
39
40

So in order to test this indicator, I wrote a quantstrat demo to test its momentum properties. First, we will
fetch the data, which consists of some ETFs that have been trading since before 2003. This is the data file I
will source for this demo (called demoData.R), along with many others.

1 require(DSTrading)
2 require(quantstrat)
3 options(width=80)
4 source("demoData.R") #contains all of the data-related boilerplate.

Here are the exact contents of demoData.R

1 options("getSymbols.warning4.0"=FALSE)
2 rm(list=ls(.blotter), envir=.blotter)
initDate='1990-12-31'
3
4 currency('USD')
5 Sys.setenv(TZ="UTC")
6
7 symbols <- c("XLB", #SPDR Materials sector
8 "XLE", #SPDR Energy sector
"XLF", #SPDR Financial sector
9 "XLP", #SPDR Consumer staples sector
1 "XLI", #SPDR Industrial sector
0 "XLU", #SPDR Utilities sector
11 "XLV", #SPDR Healthcare sector
1 "XLK", #SPDR Tech sector
"XLY", #SPDR Consumer discretionary sector
2 "RWR", #SPDR Dow Jones REIT ETF
1
3 "EWJ", #iShares Japan
1 "EWG", #iShares Germany
4 "EWU", #iShares UK
"EWC", #iShares Canada
1
"EWY", #iShares South Korea
5 "EWA", #iShares Australia
"EWH", #iShares Hong Kong
1
"EWS", #iShares Singapore
6 "IYZ", #iShares U.S. Telecom
1 "EZU", #iShares MSCI EMU ETF
7 "IYR", #iShares U.S. Real Estate
1 "EWT", #iShares Taiwan
"EWZ", #iShares Brazil
8 "EFA", #iShares EAFE
1 "IGE", #iShares North American Natural Resources
9 "EPP", #iShares Pacific Ex Japan
2 "LQD", #iShares Investment Grade Corporate Bonds
0 "SHY", #iShares 1-3 year TBonds
"IEF", #iShares 3-7 year TBonds
2 "TLT" #iShares 20+ year Bonds
1 )
2
2 #SPDR ETFs first, iShares ETFs afterwards
2 if(!"XLB" %in% ls()) {
suppressMessages(getSymbols(symbols, from="2003-01-01", to="2010-12-31",
3 src="yahoo", adjust=TRUE))
2 }
4
2 stock(symbols, currency="USD", multiplier=1)
5
2
6
2
7
2
8
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
4
0
4
1
4
2
4
3
4
4
4
5
4
6

The reason Im using these symbols is fairly simple: theyre representative of a fairly broad aspect of both
the U.S. economy and other developed economies abroad (E.G. Japan, Germany), and contain a fair amount
of staple ETFs (SPDR sectors, EFA, internationals, etc.).

Lets begin the demo. The strategy will be simplethe indicator will be the trend vigor calculation, and the
strategy will go long on the next open when the trend vigor crosses above 1, sell the next open when it
crosses below 1.4, and will stop out on the next open when the trend vigor crosses under 1 if it never crossed
1.4 within the duration of the position.

The general syntax of indicators, signals, and rules in quantstrat (for the uninitiated) is fairly
straightforward:

add.indicator/add.signal/add.rule is a function which takes in the name of the strategy as the first argument
(which I always use strategy.st for), a name of an R function in the name argument, the arguments to the
function as the argument to arguments (that is, arguments=list(x=quote(Cl(mktdata)), period=100, delta=0.2)
is the argument to the TVI function which is the value for the name argument in the add.indicator function),
and finally, a label. While the labels may seem like so much window dressing, they are critical in terms of
linking indicators to signals, signals to rules, and everything to any optimization/robustness testing you may
deecide to do. Do not forget them.

While I kept Dr. Ehlerss default period setting, I found that the strategy works best starting at 60 days for
the period, and has a solid performance until the mid-hundreds, at which point it generates too few trades per
instrument to really be able to look at any individual statistics.

Heres the strategy.

1 #To rerun the strategy, re-run everything from this line down.
2
3 strategy.st <- portfolio.st <- account.st <- "TVItrendFollowingLong"
rm.strat(portfolio.st)
4 rm.strat(strategy.st)
5 initPortf(portfolio.st, symbols=symbols, initDate=initDate, currency='USD')
6 initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
7 initOrders(portfolio.st, initDate=initDate)
strategy(strategy.st, store=TRUE)
8
9 #indicator
1
0 add.indicator(strategy.st, name="TVI", arguments=list(x=quote(Cl(mktdata)),
11period=100, delta=0.2), label="TVI")
1
2 #signals
1
3 add.signal(strategy.st, name="sigThreshold",
arguments=list(threshold=1, column="vigor.TVI", relationship="gte",
1 cross=TRUE),
4 label="longEntry")
1
5 add.signal(strategy.st, name="sigThreshold",
1 arguments=list(threshold=1.4, column="vigor.TVI", relationship="lt",
cross=TRUE),
6
label="longExit")
1
7 add.signal(strategy.st, name="sigThreshold",
1 arguments=list(threshold=1, column="vigor.TVI", relationship="lt",
8 cross=TRUE),
1 label="wrongExit")
9
#rules
2
0 add.rule(strategy.st, name="ruleSignal",
2 arguments=list(sigcol="longEntry", sigval=TRUE, orderqty=100,
1 ordertype="market", orderside="long", replace=FALSE,
2 prefer="Open"),
2 type="enter", path.dep=TRUE)
2
add.rule(strategy.st, name="ruleSignal",
3 arguments=list(sigcol="longExit", sigval=TRUE, orderqty="all",
2 ordertype="market", orderside="long", replace=FALSE,
4 prefer="Open"),
2 type="exit", path.dep=TRUE)
5
add.rule(strategy.st, name="ruleSignal",
2 arguments=list(sigcol="wrongExit", sigval=TRUE, orderqty="all",
6 ordertype="market", orderside="long", replace=FALSE,
2 prefer="Open"),
7 type="exit", path.dep=TRUE)
2
8
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
4
0
4
1
4
2
4
3
4
4

The strategy is then run with the applyStrategy call. I set verbose to FALSE for the purpose of not displaying
the order log in this blog post, but by default, quantstrat will start printing out trades at this point. Printing
out trades serves two purposes (in my experience): first off, you know your strategy is actually doing
something, and secondly, even if it is, the attentive eye will also see if the strategy is not behaving intuitively
(that is, is it loading up more lots when you thought it should only be trading 1 lot at a time? This happens
often with strategies that crisscross above and below a threshold, such as with simple RSI strategies.)

1
2 #apply strategy
3
t1 <- Sys.time()
4 out <- applyStrategy(strategy=strategy.st,portfolios=portfolio.st, verbose=FALSE)
5 t2 <- Sys.time()
6 print(t2-t1)
7
8 #tradeStats
9
10 updatePortf(portfolio.st)
dateRange <- time(getPortfolio(portfolio.st)$summary)[-1]
11 updateAcct(portfolio.st,dateRange)
12 updateEndEq(account.st)
13

The last four lines are some more accounting boilerplate that are necessary for the following analytics.

Here are the trade statistics:

1tStats <- tradeStats(Portfolios = portfolio.st, use = "trades", inclZeroDays = FALSE)


2print(data.frame(t(tStats[, -c(1:2)])))

Heres the output:

1 EFA EPP EWA EWC EWG EWH


Num.Txns 11.000 11.000 11.000 13.0000 11.000 15.000
2
Num.Trades 6.000 6.000 6.000 7.0000 6.000 8.000
3 Net.Trading.PL 2565.775 1969.314 1286.254 467.3296 814.737 606.872
4 Avg.Trade.PL 427.629 328.219 214.376 66.7614 135.789 75.859
5 Med.Trade.PL 406.141 187.906 133.158 134.4598 32.897 98.591
6 Largest.Winner 848.301 907.877 599.901 349.9296 591.163 180.214
Largest.Loser 0.000 -124.794 -95.424 -256.5205 -59.893 -95.641
7 Gross.Profits 2565.775 2163.065 1393.249 992.6210 942.630 703.020
8 Gross.Losses 0.000 -193.750 -106.995 -525.2914 -127.893 -96.148
9 Std.Dev.Trade.PL 353.537 461.074 285.169 239.4493 257.994 92.620
10 Percent.Positive 100.000 66.667 66.667 57.1429 66.667 75.000
11 Percent.Negative 0.000 33.333 33.333 42.8571 33.333 25.000
12 Profit.Factor Inf 11.164 13.022 1.8897 7.370 7.312
Avg.Win.Trade 427.629 540.766 348.312 248.1553 235.658 117.170
13 Med.Win.Trade 406.141 584.662 330.518 254.1158 175.014 109.259
14 Avg.Losing.Trade NaN -96.875 -53.498 -175.0971 -63.947 -48.074
15 Med.Losing.Trade NA -96.875 -53.498 -143.9421 -63.947 -48.074
16 Avg.Daily.PL 494.769 407.654 230.788 42.4390 176.547 86.768
17 Med.Daily.PL 571.279 289.949 134.004 4.8155 64.354 105.539
18 Std.Dev.Daily.PL 349.896 467.346 315.644 252.6538 265.974 94.326
19 Ann.Sharpe 22.447 13.847 11.607 2.6665 10.537 14.603
Max.Drawdown -1035.238 -817.160 -519.809 -765.6489 -442.170 -529.427
20 Profit.To.Max.Draw 2.478 2.410 2.474 0.6104 1.843 1.146
21 Avg.WinLoss.Ratio NaN 5.582 6.511 1.4172 3.685 2.437
22 Med.WinLoss.Ratio NA 6.035 6.178 1.7654 2.737 2.273
23 Max.Equity 3154.421 2386.521 1330.685 536.1786 1115.907 947.518
24 Min.Equity -1.416 -5.738 0.000 -229.4703 -10.326 -7.227
End.Equity 2565.775 1969.314 1286.254 467.3296 814.737 606.872
25
26 EWJ EWS EWT EWU EWY EWZ
27 Num.Txns 15.0000 15.0000 13.00000 15.000 13.0000 13.000
28 Num.Trades 8.0000 8.0000 7.00000 8.000 7.0000 7.000
29 Net.Trading.PL 126.0921 527.5159 352.38231 496.885 3903.4781 5650.267
Avg.Trade.PL 15.7615 65.9395 50.34033 62.111 557.6397 807.181
30 Med.Trade.PL -4.8031 48.6563 15.20059 53.201 507.7895 425.888
31 Largest.Winner 211.4631 287.4863 181.33002 170.439 1911.0697 3090.026
32 Largest.Loser -109.4557 -183.5601 -98.93976 -26.825 -645.4187 -762.177
33 Gross.Profits 369.6269 746.4612 536.96182 572.167 4548.8968 6431.642
34 Gross.Losses -243.5348 -218.9453 -184.57951 -75.282 -645.4187 -781.375
Std.Dev.Trade.PL 105.5657 156.0082 121.48260 84.271 766.8694 1323.564
35 Percent.Positive 37.5000 75.0000 57.14286 62.500 85.7143 71.429
36 Percent.Negative 62.5000 25.0000 42.85714 37.500 14.2857 28.571
37 Profit.Factor 1.5178 3.4094 2.90911 7.600 7.0480 8.231
38 Avg.Win.Trade 123.2090 124.4102 134.24045 114.433 758.1495 1286.328
Med.Win.Trade 99.0951 70.0932 170.21560 138.704 522.5712 533.596
39
Avg.Losing.Trade -48.7070 -109.4727 -61.52650 -25.094 -645.4187 -390.687
40 Med.Losing.Trade -29.1036 -109.4727 -70.52540 -25.206 -645.4187 -390.687
41 Avg.Daily.PL 9.5748 69.4619 32.17724 74.305 585.8121 944.911
42 Med.Daily.PL -5.6972 56.0302 0.04312 63.148 522.5712 479.742
43 Std.Dev.Daily.PL 112.4465 168.1641 122.22309 83.050 836.0858 1393.859
Ann.Sharpe 1.3517 6.5571 4.17923 14.203 11.1226 10.761
44 Max.Drawdown -355.7105 -255.8450 -466.69819 -307.027 -1576.6419 -1600.155
45 Profit.To.Max.Draw 0.3545 2.0619 0.75505 1.618 2.4758 3.531
46 Avg.WinLoss.Ratio 2.5296 1.1365 2.18183 4.560 1.1747 3.292
47 Med.WinLoss.Ratio 3.4049 0.6403 2.41354 5.503 0.8097 1.366
48 Max.Equity 422.7339 547.8001 369.07717 650.692 4695.6618 6644.273
Min.Equity 0.0000 -27.7323 -97.62103 -29.595 -106.6402 -58.404
49 End.Equity 126.0921 527.5159 352.38231 496.885 3903.4781 5650.267
50
51 EZU IEF IGE IYR IYZ LQD
52 Num.Txns 13.000 16.0000 13.00 11.000 19.0000 12.0000
53 Num.Trades 7.000 8.0000 7.00 6.000 10.0000 6.0000
Net.Trading.PL 1182.003 727.7658 -3.733e+01 1925.684 174.6551 -83.6846
54 Avg.Trade.PL 168.858 90.9707 -5.333e+00 320.947 17.4655 -13.9474
55 Med.Trade.PL 116.812 60.5784 1.500e+02 310.430 -36.2849 -43.9321
56 Largest.Winner 706.295 356.5054 6.172e+02 807.768 447.8273 257.6271
57 Largest.Loser -21.553 -224.7938 -1.047e+03 -294.785 -158.5646 -278.1925
58 Gross.Profits 1256.372 1093.0415 1.342e+03 2220.469 707.1572 447.8795
Gross.Losses -74.369 -365.2757 -1.380e+03 -294.785 -532.5021 -531.5641
59 Std.Dev.Trade.PL 255.791 211.5468 5.380e+02 367.789 179.1449 206.1184
60 Percent.Positive 71.429 75.0000 5.714e+01 83.333 40.0000 33.3333
61 Percent.Negative 28.571 25.0000 4.286e+01 16.667 60.0000 66.6667
62 Profit.Factor 16.894 2.9924 9.729e-01 7.533 1.3280 0.8426
63 Avg.Win.Trade 251.274 182.1736 3.356e+02 444.094 176.7893 223.9397
Med.Win.Trade 126.562 168.8602 2.875e+02 328.352 113.7095 223.9397
64 Avg.Losing.Trade -37.184 -182.6379 -4.598e+02 -294.785 -88.7504 -132.8910
65 Med.Losing.Trade -37.184 -182.6379 -1.881e+02 -294.785 -82.9667 -121.9668
66 Avg.Daily.PL 205.803 90.9707 -6.897e+01 336.975 1.5594 -13.9474
67 Med.Daily.PL 121.687 60.5784 2.740e+00 328.352 -39.9546 -43.9321
Std.Dev.Daily.PL 258.938 211.5468 5.598e+02 408.851 182.3684 206.1184
68 Ann.Sharpe 12.617 6.8265 -1.956e+00 13.084 0.1357 -1.0742
69 Max.Drawdown -756.388 -753.7337 -1.189e+03 -977.604 -415.3754 -648.4695
70 Profit.To.Max.Draw 1.563 0.9655 -3.139e-02 1.970 0.4205 -0.1290
71 Avg.WinLoss.Ratio 6.758 0.9975 7.297e-01 1.507 1.9920 1.6851
72 Med.WinLoss.Ratio 3.404 0.9246 1.529e+00 1.114 1.3705 1.8361
Max.Equity 1650.980 1400.1652 4.661e+02 1932.684 332.9343 251.3202
73 Min.Equity -27.256 -321.9691 -7.230e+02 -190.088 -335.9970 -397.1493
74 End.Equity 1182.003 727.7658 -3.733e+01 1925.684 174.6551 -83.6846
75
76 RWR SHY TLT XLB XLE XLF
77 Num.Txns 11.000 13.000 14.0000 15.000 17.0000 12.000
78 Num.Trades 6.000 7.000 7.0000 8.000 9.0000 6.000
Net.Trading.PL 1995.629 1142.519 1442.2875 980.284 -456.6602 323.884
79 Avg.Trade.PL 332.605 163.217 206.0411 122.536 -50.7400 53.981
80 Med.Trade.PL 335.682 61.755 269.8718 113.830 -152.9856 100.260
81 Largest.Winner 773.739 901.261 809.9610 661.063 1136.1168 223.785
82 Largest.Loser -292.223 -41.231 -484.5142 -323.312 -1360.1798 -189.485
Gross.Profits 2287.852 1183.751 1926.8017 1620.063 2243.5774 575.037
83 Gross.Losses -292.223 -41.231 -484.5142 -639.779 -2700.2376 -251.153
84 Std.Dev.Trade.PL 379.963 330.145 388.5266 334.521 723.7411 153.249
85 Percent.Positive 83.333 85.714 85.7143 62.500 44.4444 66.667
86 Percent.Negative 16.667 14.286 14.2857 37.500 55.5556 33.333
87 Profit.Factor 7.829 28.710 3.9768 2.532 0.8309 2.290
Avg.Win.Trade 457.570 197.292 321.1336 324.013 560.8943 143.759
88 Med.Win.Trade 359.312 63.647 295.1517 357.324 484.7987 142.446
89 Avg.Losing.Trade -292.223 -41.231 -484.5142 -213.260 -540.0475 -125.577
90 Med.Losing.Trade -292.223 -41.231 -484.5142 -229.386 -339.2491 -125.577
91 Avg.Daily.PL 327.263 179.497 206.0411 88.994 -130.5507 53.981
92 Med.Daily.PL
Std.Dev.Daily.PL
312.051
424.560
39.657
358.565
269.8718
388.5266
49.687
346.489
-198.6073
730.1456
100.260
153.249
93 Ann.Sharpe 12.237 7.947 8.4185 4.077 -2.8384 5.592
94 Max.Drawdown -1078.974 -176.880 -1935.3483 -782.001 -2802.9605 -286.089
95 Profit.To.Max.Draw 1.850 6.459 0.7452 1.254 -0.1629 1.132
96 Avg.WinLoss.Ratio 1.566 4.785 0.6628 1.519 1.0386 1.145
Med.WinLoss.Ratio 1.230 1.544 0.6092 1.558 1.4290 1.134
97 Max.Equity 2007.629 1177.262 3079.6926 983.284 1605.9939 591.275
98 Min.Equity -387.039 -63.396 -660.0092 -43.384 -1196.9666 -75.179
99 End.Equity 1995.629 1142.519 1442.2875 980.284 -456.6602 323.884
100
101 XLI XLK XLP XLU XLV XLY
102 Num.Txns 11.000 13.000 11.0000 13.000 15.00000 9.000
Num.Trades 6.000 7.000 6.0000 7.000 8.00000 5.000
103 Net.Trading.PL 1711.104 803.342 323.3662 1004.075 30.93792 1211.524
104 Avg.Trade.PL 285.184 114.763 53.8944 143.439 3.86724 242.305
105 Med.Trade.PL 326.887 105.678 65.8982 7.115 -9.87414 147.312
106 Largest.Winner 519.577 438.553 356.5055 681.636 288.56124 761.154
107 Largest.Loser
Gross.Profits
0.000
1711.104
-107.612 -210.7667 -295.709 -187.12589
972.832 591.8219 1349.316 466.45591
-82.008
1293.532
108 Gross.Losses 0.000 -169.490 -268.4557 -345.241 -435.51798 -82.008
109 Std.Dev.Trade.PL 194.940 190.582 188.6608 346.799 146.85429 330.468
110 Percent.Positive 100.000 57.143 66.6667 57.143 50.00000 80.000
111 Percent.Negative 0.000 42.857 33.3333 42.857 50.00000 20.000
112 Profit.Factor Inf 5.740 2.2045 3.908 1.07104 15.773
Avg.Win.Trade 285.184 243.208 147.9555 337.329 116.61398 323.383
113 Med.Win.Trade 326.887 214.301 96.6660 330.282 68.64046 247.765
114 Avg.Losing.Trade NaN -56.497 -134.2278 -115.080 -108.87950 -82.008
115 Med.Losing.Trade NA -34.689 -134.2278 -27.216 -94.01504 -82.008
116 Avg.Daily.PL 317.385 116.277 46.7108 171.065 -5.57699 293.669
117 Med.Daily.PL 405.014 81.035 41.9843 60.238 -60.36201 247.765
118 Std.Dev.Daily.PL 199.312 208.726 210.0097 371.366 155.97459 357.804
119 Ann.Sharpe 25.279 8.843 3.5308 7.312 -0.56760 13.029
Max.Drawdown -359.821 -431.415 -309.4029 -577.717 -418.76748 -496.847
120 Profit.To.Max.Draw 4.755 1.862 1.0451 1.738 0.07388 2.438
121 Avg.WinLoss.Ratio NaN 4.305 1.1023 2.931 1.07104 3.943
122 Med.WinLoss.Ratio NA 6.178 0.7202 12.135 0.73010 3.021
123 Max.Equity 1713.104 852.989 332.3662 1332.267 174.64061 1464.480
124 Min.Equity 0.000 -124.148 -177.2952 -105.827 -399.20704 -100.523
125 End.Equity 1711.104 803.342 323.3662 1004.075 30.93792 1211.524
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149

Looking at the statistics on a per-trade basis on a 100-share trade size, the majority of configurations come
away with a clear profit. While I did not set any transaction costs/slippage, as this strategy is a long to
medium term horizon strategy, I wouldnt worry too much over it. The statistics that impress me are the
percentage correct and the profit factor. Looking at EWJ, even when the percentage correct is less than 50%,
the strategy still manages to eke out a profit (profit factor 1.5). A few instruments lose), but on a whole, for
an indicator thats supposed to be a mere filter, this isnt a particularly bad start.

For those wondering about the annualized Sharpe Ratio as it is calculated with trade statistics, this is my
interpretation of it: if you aggregated every single trades profit and loss into one day apiece, averaged them,
and divided by the standard error, which is the standard deviation divided by the square root of 252 (trading
days in a year).

Here are the daily statistics:

1 dStats <- dailyStats(Portfolios = portfolio.st, use = "Equity")


2 rownames(dStats) <- gsub("\\.DailyEndEq", "", rownames(dStats))
print(data.frame(t(dStats[, -1])))
3 EFA EPP EWA EWC EWG EWH
4 Total.Days 886.00 669.00 636.00 566.00 675.00 842.00
5 Winning.Days 490.00 370.00 359.00 300.00 370.00 442.00
6 Losing.Days 396.00 299.00 277.00 266.00 305.00 400.00
Avg.Day.PL 2.90 2.94 2.02 0.83 1.21 0.72
7 Med.Day.PL 5.96 5.06 4.63 2.26 1.81 1.65
8 Largest.Winner 196.41 164.03 123.88 113.03 99.29 120.60
9 Largest.Loser -275.87 -234.28 -135.60 -126.79 -117.34 -122.37
10 Gross.Profits 19050.85 13211.44 8517.36 6635.32 7027.38 7348.06
11 Gross.Losses -16485.08 -11242.12 -7231.10 -6167.99 -6212.64 -6741.19
Std.Dev.Daily.PL 54.62 50.83 34.68 30.69 27.08 24.61
12 Percent.Positive 55.30 55.31 56.45 53.00 54.81 52.49
13 Percent.Negative 44.70 44.69 43.55 47.00 45.19 47.51
14 Profit.Factor 1.16 1.18 1.18 1.08 1.13 1.09
15 Avg.Win.Day 38.88 35.71 23.73 22.12 18.99 16.62
16 Med.Win.Day
Avg.Losing.Day
30.35
-41.63
26.11
-37.60
17.14
-26.11
16.54
-23.19
14.44
-20.37
11.84
-16.85
17 Med.Losing.Day -28.57 -23.21 -15.90 -15.08 -13.21 -11.00
18 Avg.Daily.PL 2.90 2.94 2.02 0.83 1.21 0.72
19 Med.Daily.PL 5.96 5.06 4.63 2.26 1.81 1.65
20 Std.Dev.Daily.PL.1 54.62 50.83 34.68 30.69 27.08 24.61
Ann.Sharpe 0.84 0.92 0.93 0.43 0.71 0.46
21 Max.Drawdown -1035.24 -817.16 -519.81 -765.65 -442.17 -529.43
22 Profit.To.Max.Draw 2.48 2.41 2.47 0.61 1.84 1.15
23 Avg.WinLoss.Ratio 0.93 0.95 0.91 0.95 0.93 0.99
Med.WinLoss.Ratio 1.06 1.12 1.08 1.10 1.09 1.08
24
Max.Equity 3154.42 2386.52 1330.69 536.18 1115.91 947.52
25 Min.Equity -1.42 -5.74 0.00 -229.47 -10.33 -7.23
26 End.Equity 2565.77 1969.31 1286.25 467.33 814.74 606.87
27
28 EWJ EWS EWT EWU EWY EWZ
29 Total.Days 569.00 970.00 597.00 763.00 989.00 1075.00
Winning.Days 298.00 536.00 316.00 410.00 546.00 605.00
30 Losing.Days 271.00 434.00 281.00 353.00 443.00 470.00
31 Avg.Day.PL 0.22 0.54 0.59 0.65 3.95 5.26
32 Med.Day.PL 1.87 1.61 1.67 1.68 9.35 7.49
33 Largest.Winner 44.31 67.76 72.61 67.65 389.70 563.64
34 Largest.Loser -57.97 -84.06 -116.84 -98.01 -354.19 -623.29
Gross.Profits 3238.75 4779.24 4216.67 5613.57 30944.68 38572.35
35 Gross.Losses -3112.66 -4251.73 -3864.29 -5116.69 -27041.21 -32922.08
36 Std.Dev.Daily.PL 14.18 13.75 18.17 18.65 82.68 102.52
37 Percent.Positive 52.37 55.26 52.93 53.74 55.21 56.28
38 Percent.Negative 47.63 44.74 47.07 46.26 44.79 43.72
Profit.Factor 1.04 1.12 1.09 1.10 1.14 1.17
39 Avg.Win.Day 10.87 8.92 13.34 13.69 56.68 63.76
40 Med.Win.Day 8.64 6.00 11.02 11.24 40.88 36.97
41 Avg.Losing.Day -11.49 -9.80 -13.75 -14.49 -61.04 -70.05
42 Med.Losing.Day -8.87 -6.43 -10.08 -10.41 -40.22 -40.02
43 Avg.Daily.PL 0.22 0.54 0.59 0.65 3.95 5.26
Med.Daily.PL 1.87 1.61 1.67 1.68 9.35 7.49
44 Std.Dev.Daily.PL.1 14.18 13.75 18.17 18.65 82.68 102.52
45 Ann.Sharpe 0.25 0.63 0.52 0.55 0.76 0.81
46 Max.Drawdown -355.71 -255.84 -466.70 -307.03 -1576.64 -1600.16
47 Profit.To.Max.Draw 0.35 2.06 0.76 1.62 2.48 3.53
48 Avg.WinLoss.Ratio 0.95 0.91 0.97 0.94 0.93 0.91
Med.WinLoss.Ratio 0.97 0.93 1.09 1.08 1.02 0.92
49 Max.Equity 422.73 547.80 369.08 650.69 4695.66 6644.27
50 Min.Equity 0.00 -27.73 -97.62 -29.59 -106.64 -58.40
51 End.Equity 126.09 527.52 352.38 496.89 3903.48 5650.27
52
53 EZU IEF IGE IYR IYZ LQD
Total.Days 661.00 670.00 510.00 582.00 715.00 561.00
54 Winning.Days 366.00 339.00 272.00 307.00 362.00 290.00
55 Losing.Days 295.00 331.00 238.00 275.00 353.00 271.00
56 Avg.Day.PL 1.79 1.09 -0.07 3.31 0.24 -0.15
57 Med.Day.PL 4.40 0.88 3.76 6.55 0.86 1.63
58 Largest.Winner 173.19 171.24 215.52 235.32 70.10 109.77
Largest.Loser -269.85 -159.58 -227.11 -251.01 -102.91 -125.10
59 Gross.Profits 12212.18 10589.20 10077.87 15816.00 5627.62 7328.19
60 Gross.Losses -11030.18 -9861.44 -10115.20 -13890.32 -5452.96 -7411.88
61 Std.Dev.Daily.PL 48.55 41.28 53.89 65.85 20.72 34.60
62 Percent.Positive 55.37 50.60 53.33 52.75 50.63 51.69
Percent.Negative 44.63 49.40 46.67 47.25 49.37 48.31
63
Profit.Factor 1.11 1.07 1.00 1.14 1.03 0.99
64 Avg.Win.Day 33.37 31.24 37.05 51.52 15.55 25.27
65 Med.Win.Day 26.82 23.78 31.78 44.00 12.42 19.64
66 Avg.Losing.Day -37.39 -29.79 -42.50 -50.51 -15.45 -27.35
67 Med.Losing.Day -24.40 -22.30 -30.05 -38.11 -11.24 -21.70
Avg.Daily.PL 1.79 1.09 -0.07 3.31 0.24 -0.15
68 Med.Daily.PL 4.40 0.88 3.76 6.55 0.86 1.63
69 Std.Dev.Daily.PL.1 48.55 41.28 53.89 65.85 20.72 34.60
70 Ann.Sharpe 0.58 0.42 -0.02 0.80 0.19 -0.07
71 Max.Drawdown -756.39 -753.73 -1189.16 -977.60 -415.38 -648.47
72 Profit.To.Max.Draw 1.56 0.97 -0.03 1.97 0.42 -0.13
Avg.WinLoss.Ratio 0.89 1.05 0.87 1.02 1.01 0.92
73 Med.WinLoss.Ratio 1.10 1.07 1.06 1.15 1.10 0.90
74 Max.Equity 1650.98 1400.17 466.12 1932.68 332.93 251.32
75 Min.Equity -27.26 -321.97 -723.05 -190.09 -336.00 -397.15
76 End.Equity 1182.00 727.77 -37.33 1925.68 174.66 -83.68
77
RWR SHY TLT XLB XLE XLF
78 Total.Days 574.00 1190.00 614.00 780.00 727.00 471.00
Winning.Days 309.00 668.00 321.00 429.00 398.00 246.00
79
Losing.Days 265.00 522.00 293.00 351.00 329.00 225.00
80 Avg.Day.PL 3.48 0.96 2.35 1.26 -0.63 0.69
81 Med.Day.PL 5.92 1.00 6.03 4.30 8.25 1.82
82 Largest.Winner 269.45 32.68 471.43 129.97 416.59 83.33
83 Largest.Loser -293.03 -43.49 -333.98 -162.54 -350.68 -156.62
Gross.Profits 17031.46 4452.86 19634.89 11099.37 22312.96 4470.08
84 Gross.Losses -15035.83 -3310.34 -18192.61 -10119.09 -22769.62 -4146.20
85 Std.Dev.Daily.PL 72.55 8.62 86.91 36.57 88.11 24.85
86 Percent.Positive 53.83 56.13 52.28 55.00 54.75 52.23
87 Percent.Negative 46.17 43.87 47.72 45.00 45.25 47.77
88 Profit.Factor 1.13 1.35 1.08 1.10 0.98 1.08
Avg.Win.Day 55.12 6.67 61.17 25.87 56.06 18.17
89 Med.Win.Day 45.43 5.03 40.71 21.69 39.10 13.76
90 Avg.Losing.Day -56.74 -6.34 -62.09 -28.83 -69.21 -18.43
91 Med.Losing.Day -45.55 -4.93 -45.35 -19.65 -46.93 -12.94
92 Avg.Daily.PL 3.48 0.96 2.35 1.26 -0.63 0.69
Med.Daily.PL 5.92 1.00 6.03 4.30 8.25 1.82
93 Std.Dev.Daily.PL.1 72.55 8.62 86.91 36.57 88.11 24.85
94 Ann.Sharpe 0.76 1.77 0.43 0.55 -0.11 0.44
95 Max.Drawdown -1078.97 -176.88 -1935.35 -782.00 -2802.96 -286.09
96 Profit.To.Max.Draw 1.85 6.46 0.75 1.25 -0.16 1.13
97 Avg.WinLoss.Ratio 0.97 1.05 0.99 0.90 0.81 0.99
Med.WinLoss.Ratio 1.00 1.02 0.90 1.10 0.83 1.06
98 Max.Equity 2007.63 1177.26 3079.69 983.28 1605.99 591.27
99 Min.Equity -387.04 -63.40 -660.01 -43.38 -1196.97 -75.18
100 End.Equity 1995.63 1142.52 1442.29 980.28 -456.66 323.88
101
102 XLI XLK XLP XLU XLV XLY
103 Total.Days 703.00 806.00 453.00 845.00 632.00 641.00
Winning.Days 396.00 452.00 247.00 469.00 316.00 348.00
104 Losing.Days 307.00 354.00 206.00 376.00 316.00 293.00
105 Avg.Day.PL 2.43 1.00 0.71 1.19 0.05 1.89
106 Med.Day.PL 3.53 2.90 1.91 2.71 0.01 2.96
107 Largest.Winner 117.17 98.93 76.23 91.19 78.78 165.94
Largest.Loser -105.71 -93.48 -67.43 -144.31 -97.34 -127.92
108 Gross.Profits 7981.67 7157.63 2899.29 8376.04 5328.55 7759.21
109 Gross.Losses -6270.56 -6354.29 -2575.92 -7371.96 -5297.62 -6547.68
110 Std.Dev.Daily.PL 26.72 22.19 15.94 25.64 21.81 30.39
111 Percent.Positive 56.33 56.08 54.53 55.50 50.00 54.29
112 Percent.Negative 43.67 43.92 45.47 44.50 50.00 45.71
Profit.Factor 1.27 1.13 1.13 1.14 1.01 1.19
113 Avg.Win.Day 20.16 15.84 11.74 17.86 16.86 22.30
114 Med.Win.Day 16.69 12.37 9.31 14.55 14.23 18.28
115 Avg.Losing.Day -20.43 -17.95 -12.50 -19.61 -16.76 -22.35
116 Med.Losing.Day -15.22 -12.58 -9.61 -12.72 -13.16 -15.99
Avg.Daily.PL 2.43 1.00 0.71 1.19 0.05 1.89
117
Med.Daily.PL 3.53 2.90 1.91 2.71 0.01 2.96
118 Std.Dev.Daily.PL.1 26.72 22.19 15.94 25.64 21.81 30.39
119 Ann.Sharpe 1.45 0.71 0.71 0.74 0.04 0.99
120 Max.Drawdown -359.82 -431.41 -309.40 -577.72 -418.77 -496.85
121 Profit.To.Max.Draw 4.76 1.86 1.05 1.74 0.07 2.44
Avg.WinLoss.Ratio 0.99 0.88 0.94 0.91 1.01 1.00
122 Med.WinLoss.Ratio 1.10 0.98 0.97 1.14 1.08 1.14
123 Max.Equity 1713.10 852.99 332.37 1332.27 174.64 1464.48
124 Min.Equity 0.00 -124.15 -177.30 -105.83 -399.21 -100.52
125 End.Equity 1711.10 803.34 323.37 1004.07 30.94 1211.52
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

Looking at the daily statistics, while the statistics arent exactly spectacular on the daily time frame, keep in
mind that these configurations are ones that hold for very long periods of time, and thus are subject to the
usual sloshings of the individual securities over a long period of time. The thing to see here is that this
indicator does a good job of creating an edge in most instruments.

Continuinglets look at the equity curve of XLB.

1 tmp <- TVI(Cl(XLB), period = 100)


2 add_TA(tmp$vigor)
Something to note is that the exits I programmed arent exactly the best, and suffer from the same
weaknesses as the usual trend followersnamely, that unsophisticated trend-following strategies tend to
give back their profts as the trend they were following winds down. However, looking at the plot of the
indicator at the bottom, and given how it does not seem to be something very prone to whipsaws, a potential
trading strategy going forward may be to do something Dr. Ehlers has done in another one of his
presentations, and create signals on the relationship of the signal compared to its 1-day lagged version.

Finally, out of a tagential interest, lets look at some portfolio statistics. Note that this probably makes the
least sense out of anything presented here since there is no intelligent asset allocation scheme at work here.

1 portPL <- .blotter$portfolio.TVItrendFollowingLong$summary$Net.Trading.PL


2 (SharpeRatio.annualized(portPL, geometric=FALSE))
3
4 Net.Trading.PL
5 Annualized Sharpe Ratio (Rf=0%) 0.623
6
plot(cumsum(portPL)["2003::"])
7

From a returns perspective, this doesnt make too much sense, as theres no initial equity, but it exists to just
get a perspective of the strategys performance at a portfolio level. Overall, it seems the system is profitable,
but drawdowns come quickly, meaning that as a strategy in and of itself, Trend Vigor is definitely worth
looking at. That stated, its original use was as a filter, and odds are, there exist indicators that are probably
more dedicated to trend following such as the FRAMA, ichimoku, and so on.

So, overall, this blog post has shown a few things:

1) It is possible to create a trend-following strategy with a win percentage greater than that of 50%.

2) While the trend vigor indicator is a filter, it may be possible to put a dedicated trend-following filter on
top of it (such as the FRAMAmore on that in the future), to possibly get even better results.
3) This is (definitely) not a complete trading system. The exit logic definitely leaves something to be desired
(for instance, if the trend vigor reaches its maximum (2)which seems to be every time, waiting for it to
drop under 1.4 is definitely suboptimal), and it seems more improvements can be made.

Furthermore, there is more to investigate in the study of this indicator:

1) In this case, given the smoothness of the trend vigor, is it possible to be more aggressive with it? For
instance, although it avoided the financial crisis completely, it did not re-enter the market until late 2009,
missing a chunk of the trend, and furthermore, it also managed to give back most of those profits (but not
all). Can this be rectified?

2) How does the strategy perform on the short end?

3) What can be done to keep strategies built on this indicator from giving back open equity?

While I myself have more indicators to write about, I also feel that input from readers may be worth testing
as well.

You might also like