[R-SIG-Finance] Sullivan, Timmerman and White 1999: TA rules, and R

AGhandar adam.ghandar at adelaide.edu.au
Thu Nov 10 04:54:10 CET 2011


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.



More information about the R-SIG-Finance mailing list