# Sullivan, Timmerman and White 1999: TA rules, and R

11 messages
Open this post in threaded view
|
Report Content as Inappropriate

## Sullivan, Timmerman and White 1999: TA rules, and R

 [Apologies if I have sent this multiple times.  I have been struggling with SMTP sewrvers and I have not seen my message appear on the list] Friends I am trying to save myself some tedious work. I am processing a paper from  "The Journal Of Finance * Vol. LIV, No. 5   October 1999" by Sullivan,  Timmerman and  White.  "Data-Snooping, Technical Trading Rule Performance, and the Bootstrap" I am aiming to reproduce their results using the same  TA rules as they used. They describe the rules they use in English and I am in the process of trying to programme them into R.  But if some one has already done this it would save me a pile of work. It would be nice to just grab some rules from the TTR package, but because of the way STW describe the rules it is quite a lot of work to calculate what parameters to use. So I am clutching at a straw here:  If anybody could point me in a better direction than slogging through the English text and trying to match that with the TTR docs I would be grateful cheers Worik PS Here is an example of their text.  Not that it is bad, just quite a bit of work....      A. Filter Rules Filter rules are used in Alexander (1961) to assess the efficiency of stock price movements. Fama and Blume (1966) explain the standard filter rule: An x per cent filter is defined as follows: If the daily closing price of a particular security moves up at least x per cent, buy and hold the se- curity until its price moves down at least x per cent from a subsequent high, at which time simultaneously sell and go short. The short position is maintained until the daily closing price rises at least x per cent above a subsequent low at which time one covers and buys. Moves less than x per cent in either direction are ignored. (p. 227) The first item of consideration is how to define subsequent lows and highs. We will do this in two ways. As the above excerpt suggests, a subsequent high is the highest closing price achieved while holding a particular long position. Likewise, a subsequent low is the lowest closing price achieved while holding a particular short position. Alternatively, a low (high) can be defined as the most recent closing price that is less (greater) than the e previous closing prices. Next, we will expand the universe of filter rules by allowing a neutral position to be imposed. This is accomplished by liquidat- ing a long position when the price decreases y percent from the previous high, and covering a short position when the price increases y percent from the previous low. Following BLL, we also consider holding a given long or short position for a prespecified number of days, c, effectively ignoring all other signals generated during that time. -- If we amplify everything, we hear nothing. -- _______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance-- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Sullivan, Timmerman and White 1999: TA rules, and R

 Hi Worik, There are 5 types of rules: filter rules, moving averages, support and resistance, channel break-outs, and on-balance volume averages.  TTR contains what you need for moving averages, channel break-outs (DonchianChannel) and on-balance volume (OBV). I coded filter rules in another language a few years ago, so I could help you write them in R.  I don't understand how the support and resistance rules differ from the channel break-outs, but that could be due to the time of day and my lack of sleep.  Regardless, I doubt they would be difficult to code. Best, -- Joshua Ulrich  |  FOSS Trading: www.fosstrading.com On Mon, Mar 28, 2011 at 4:33 PM, Worik <[hidden email]> wrote: > [Apologies if I have sent this multiple times.  I have been struggling with > SMTP sewrvers and I have not seen my message appear on the list] > > Friends > > I am trying to save myself some tedious work. > > I am processing a paper from  "The Journal Of Finance * Vol. LIV, No. 5 >  October 1999" by Sullivan,  Timmerman and  White.  "Data-Snooping, > Technical Trading Rule Performance, and the Bootstrap" > > I am aiming to reproduce their results using the same  TA rules as they > used. > > They describe the rules they use in English and I am in the process of > trying to programme them into R.  But if some one has already done this it > would save me a pile of work. > > It would be nice to just grab some rules from the TTR package, but because > of the way STW describe the rules it is quite a lot of work to calculate > what parameters to use. > > So I am clutching at a straw here:  If anybody could point me in a better > direction than slogging through the English text and trying to match that > with the TTR docs I would be grateful > > cheers > Worik > > PS Here is an example of their text.  Not that it is bad, just quite a bit > of work.... > >    A. Filter Rules > Filter rules are used in Alexander (1961) to assess the efficiency of stock > price movements. Fama and Blume (1966) explain the standard filter rule: > An x per cent filter is defined as follows: If the daily closing price of a > particular security moves up at least x per cent, buy and hold the se- > curity until its price moves down at least x per cent from a subsequent > high, at which time simultaneously sell and go short. The short position > is maintained until the daily closing price rises at least x per cent above > a subsequent low at which time one covers and buys. Moves less than x > per cent in either direction are ignored. (p. 227) > The first item of consideration is how to define subsequent lows and highs. > We will do this in two ways. As the above excerpt suggests, a subsequent > high is the highest closing price achieved while holding a particular long > position. Likewise, a subsequent low is the lowest closing price achieved > while holding a particular short position. Alternatively, a low (high) can > be > defined as the most recent closing price that is less (greater) than the e > previous closing prices. Next, we will expand the universe of filter rules > by > allowing a neutral position to be imposed. This is accomplished by liquidat- > ing a long position when the price decreases y percent from the previous > high, and covering a short position when the price increases y percent from > the previous low. Following BLL, we also consider holding a given long or > short position for a prespecified number of days, c, effectively ignoring > all > other signals generated during that time. > > -- > If we amplify everything, we hear nothing. > -- > > _______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-sig-finance> -- Subscriber-posting only. If you want to post, subscribe first. > -- Also note that this is not the r-help list where general R questions > should go. > _______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance-- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Sullivan, Timmerman and White 1999: TA rules, and R

 In reply to this post by Worik Stanton On 03/28/2011 04:33 PM, Worik wrote: > [Apologies if I have sent this multiple times. I have been struggling > with SMTP sewrvers and I have not seen my message appear on the list] > > Friends > > I am trying to save myself some tedious work. > > I am processing a paper from "The Journal Of Finance * Vol. LIV, No. 5 > October 1999" by Sullivan, Timmerman and White. "Data-Snooping, > Technical Trading Rule Performance, and the Bootstrap" > > I am aiming to reproduce their results using the same TA rules as they > used. > > They describe the rules they use in English and I am in the process of > trying to programme them into R. But if some one has already done this > it would save me a pile of work. > > It would be nice to just grab some rules from the TTR package, but > because of the way STW describe the rules it is quite a lot of work to > calculate what parameters to use. > > So I am clutching at a straw here: If anybody could point me in a better > direction than slogging through the English text and trying to match > that with the TTR docs I would be grateful > > cheers > Worik > > PS Here is an example of their text. Not that it is bad, just quite a > bit of work.... > > A. Filter Rules > Filter rules are used in Alexander (1961) to assess the efficiency of stock > price movements. Fama and Blume (1966) explain the standard filter rule: > An x per cent filter is defined as follows: If the daily closing price of a > particular security moves up at least x per cent, buy and hold the se- > curity until its price moves down at least x per cent from a subsequent > high, at which time simultaneously sell and go short. The short position > is maintained until the daily closing price rises at least x per cent above > a subsequent low at which time one covers and buys. Moves less than x > per cent in either direction are ignored. (p. 227) > The first item of consideration is how to define subsequent lows and highs. > We will do this in two ways. As the above excerpt suggests, a subsequent > high is the highest closing price achieved while holding a particular long > position. Likewise, a subsequent low is the lowest closing price achieved > while holding a particular short position. Alternatively, a low (high) > can be defined as the most recent closing > price that is less (greater) than the e > previous closing prices. Next, we will expand the universe of filter > rules by allowing a neutral position to be imposed. > This is accomplished by liquidating a long position when > the price decreases y percent from the previous > high, and covering a short position when the price increases y percent from > the previous low. Following BLL, we also consider holding a given long or > short position for a prespecified number of days, c, effectively > ignoring all other signals generated during that time. I've read this paper, though it's been quite a while, and considered replicating parts of it.  I don't recall there being anything there that would really be taken out of TTR though.  As I recall, and as your example shows, the paper is really more concerned with pattern recognition and then having simple entry/exit signals and rules.  I would probably use quantstrat to program each signal/rule pair. Again, assuming my recollection of the paper is correct, you would not need any indicators (which is predominantly what TTR provides), but rather need to construct signal generating procedures for entry and exit.  For the example above, you'd need to convert the price series into a return series as well, and I think this is your only 'indicator' (i.e. transformation of the data required before you may generate signals). So, for example, you would use the signal generator functions sigCrossover sigThreshold, sigPeak, and maybe sigFormula to generate your entry and exit signals.  Then, rule generation for entry and exit rules proceeds as normal using ruleSignal. Regards,     - Brian -- Brian G. Peterson http://braverock.com/brian/Ph: 773-459-4973 IM: bgpbraverock _______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance-- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Sullivan, Timmerman and White 1999: TA rules, and R

Open this post in threaded view
|
Report Content as Inappropriate

## Re: Sullivan, Timmerman and White 1999: TA rules, and R

 I am just pushing ahead and coding these.  Using some TTR stuff where applicable,  but only SMA has been so far (I have  not completed the task yet).  But I am grateful for that.  Thank you TTR. >   I don't understand how the support and > resistance rules differ from the channel break-outs, but that could be > due to the time of day and my lack of sleep.  Regardless, I doubt they > would be difficult to code. Me too!  I decided to interpret it as: support & resistance: Long when P_t > max(P, t, t-n) And for channel breakout:  Long when P_t > min(P, t-1, t-n) x (1+x) And the rule is used when max(P, t-1, t-n) < min(P, t-1, t-n) x (1+n) Subtle but it does make them different. The Sullivan et. el. paper does have some serious shortcomings, not the least that there are insufficient references to proper descriptions of these rules, that I only notice as I implement them.  Such is life! > DonchianChannel, or OBV, es needed.  Channel Break-outs are also often > called pivots.  We have some code for this, and will endeavor to > document it and get it into TTR. Channel Breakouts / Pivots?  Interesting.  Have you any where I can go to look for more information? Thanks for your attention people.  This is fun! cheers Worik -- If we amplify everything, we hear nothing. -- _______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance-- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Sullivan, Timmerman and White 1999: TA rules, and R

 In reply to this post by braverock On 30/03/11 00:50, Brian G. Peterson wrote: > So, for example, you would use the signal generator functions > sigCrossover sigThreshold, sigPeak, and maybe sigFormula to generate > your entry and exit signals.  Then, rule generation for entry and exit > rules proceeds as normal using ruleSignal. I must have missed some thing.  What are ruleSignal, sigFormula etcetera? W -- If we amplify everything, we hear nothing. -- _______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance-- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Sullivan, Timmerman and White 1999: TA rules, and R

 In reply to this post by Worik Stanton Dear all, I came across this post while trying to do the same thing - I am a little new to R and would be really grateful if anyone could provide any information or an example of implementing a rule similar to the description below. Especially if you have implemented this rule that would be really helpful :-) My initial attempt at implementing the filter rules described in the paper (see description below) is along the lines of this: library(TTR) x<-0.01 # parameter price <- 10 + c(0, cumsum(runif(100, -1, 1))) # random price series change<-ROC(price,1) # daily price change signal<-ifelse(change>=x,1,0) + ifelse(change<=-x,-1,0) The above line creates a signal 1 or -1 if the price rises or falls by x% on any day, but the problem I have is that I can not see how it is possible to implement the requirement to for instance "hold the position until the price moves up x%" without a for loop and a set of complex conditions and flags. Is this the only approach or are there some built in functions or approaches using R that would make it much easier? Many thanks in anticipation, Adam      A. Filter Rules Filter rules are used in Alexander (1961) to assess the efficiency of stock price movements. Fama and Blume (1966) explain the standard filter rule: An x per cent filter is defined as follows: If the daily closing price of a particular security moves up at least x per cent, buy and hold the se- curity until its price moves down at least x per cent from a subsequent high, at which time simultaneously sell and go short. The short position is maintained until the daily closing price rises at least x per cent above a subsequent low at which time one covers and buys. Moves less than x per cent in either direction are ignored. (p. 227) The first item of consideration is how to define subsequent lows and highs. We will do this in two ways. As the above excerpt suggests, a subsequent high is the highest closing price achieved while holding a particular long position. Likewise, a subsequent low is the lowest closing price achieved while holding a particular short position. Alternatively, a low (high) can be defined as the most recent closing price that is less (greater) than the e previous closing prices. Next, we will expand the universe of filter rules by allowing a neutral position to be imposed. This is accomplished by liquidat- ing a long position when the price decreases y percent from the previous high, and covering a short position when the price increases y percent from the previous low. Following BLL, we also consider holding a given long or short position for a prespecified number of days, c, effectively ignoring all other signals generated during that time.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Sullivan, Timmerman and White 1999: TA rules, and R

 Further to the earlier example, a more complete way to implement the description of filter rules in Sullivan, Timmerman and  White 1999 (see below) might be similar to this, but it seems very slow (and possibly not correct)? library(TTR) price <- 1000 + c(0, cumsum(runif(500, -10, 10))) x<-0.01 e<-10 signal<-filter(price,x,e) filter <- function(price,x,e,...) {                 signal<-rep(0,NROW(price))         for(i in seq(e,NROW(signal))){         signal[i]<-getSignal(price[i],price[i-1],signal[i-1],x,min(price[i-e:i]),max (price[i-e:i]))         }                 signal }   getSignal<-function(price,lastPrice,lastPos, x,recentL,recentH){         # first check if a long or short position should be initiated         change<-price/lastPrice-1         if( change>=x && lastPos!= -1)                 return (1)         else if(change<=-x && lastPos!=1)                 return(-1)                 # check if position should be changed -         if(lastPos==1){                 if(price<=recentH*(1-x))  #"hold until price moves down x percent from a subsequent high"                         return(-1)                 }         else if(lastPos==-1){                 if(price>=recentL*(1+x)) #  #"short until price moves up x percent from a subsequent low"                         return(1)                 }         return(lastPos)         } Any thoughts would be much appreciated, and sorry for sending two emails about this... the first example wasn't complete. -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of AGhandar Sent: Thursday, 10 November 2011 2:24 PM To: [hidden email] Subject: Re: [R-SIG-Finance] Sullivan, Timmerman and White 1999: TA rules, and R Dear all, I came across this post while trying to do the same thing - I am a little new to R and would be really grateful if anyone could provide any information or an example of implementing a rule similar to the description below. Especially if you have implemented this rule that would be really helpful :-) My initial attempt at implementing the filter rules described in the paper (see description below) is along the lines of this: library(TTR) x<-0.01 # parameter price <- 10 + c(0, cumsum(runif(100, -1, 1))) # random price series change<-ROC(price,1) # daily price change signal<-ifelse(change>=x,1,0) + ifelse(change<=-x,-1,0) The above line creates a signal 1 or -1 if the price rises or falls by x% on any day, but the problem I have is that I can not see how it is possible to implement the requirement to for instance "hold the position until the price moves up x%" without a for loop and a set of complex conditions and flags. Is this the only approach or are there some built in functions or approaches using R that would make it much easier? Many thanks in anticipation, Adam      A. Filter Rules Filter rules are used in Alexander (1961) to assess the efficiency of stock price movements. Fama and Blume (1966) explain the standard filter rule: An x per cent filter is defined as follows: If the daily closing price of a particular security moves up at least x per cent, buy and hold the se- curity until its price moves down at least x per cent from a subsequent high, at which time simultaneously sell and go short. The short position is maintained until the daily closing price rises at least x per cent above a subsequent low at which time one covers and buys. Moves less than x per cent in either direction are ignored. (p. 227) The first item of consideration is how to define subsequent lows and highs. We will do this in two ways. As the above excerpt suggests, a subsequent high is the highest closing price achieved while holding a particular long position. Likewise, a subsequent low is the lowest closing price achieved while holding a particular short position. Alternatively, a low (high) can be defined as the most recent closing price that is less (greater) than the e previous closing prices. Next, we will expand the universe of filter rules by allowing a neutral position to be imposed. This is accomplished by liquidat- ing a long position when the price decreases y percent from the previous high, and covering a short position when the price increases y percent from the previous low. Following BLL, we also consider holding a given long or short position for a prespecified number of days, c, effectively ignoring all other signals generated during that time. -- View this message in context: http://r.789695.n4.nabble.com/Sullivan-Timmerman-and-White-1999-TA-rules-and-R-tp3413144p4022395.html Sent from the Rmetrics mailing list archive at Nabble.com. _______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance-- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. _______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance-- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Sullivan, Timmerman and White 1999: TA rules, and R

Open this post in threaded view
|
Report Content as Inappropriate