Here you will find daily news and tutorials about R, contributed by over 573 bloggers.
There are many ways to follow us - By e-mail:On Facebook: If you are an R blogger yourself you are invited to add your own R content feed to this site (Non-English R bloggers should add themselves- here)

Here’s a quick R implementation of David Varadi’s alternative to the RSI(2). Michael Stokes over at the MarketSci blog has three great posts exploring this indicator:

DV <- function(HLC, n=2, bounded=FALSE) { # “HLC” is an _xts_ object with “High”, “Low”, and “Close” # columns, in that order. # This is David Varadi’s alternative to the RSI(2). Calculations # taken from the marketsci blog — http://marketsci.wordpress.com # Author of this implementation: Joshua Ulrich

# Calculate each day’s high/low mean hlMean <- rowMeans( HLC[,-3] ) # Calculate the running Mean of the Close divided by the # high/low mean, then subtract 1. res <- runMean( HLC[,3] / hlMean, n ) – 1 # If we want the bounded DV… if(bounded) { # Set the range to calculated the bounded DV rng <- 252:NROW(res)

# Grab the index of the unbounded results, so we can convert # the bounded results back to an xts object. indx <- index(res)

# A simple percent rank function hack pctRank <- function(x,i) match(x[i], sort(coredata(x[(i-251):i]))) # Apply the percent rank function to the coredata of our results res <- sapply(rng, function(i) pctRank(res, i) / 252)

# Convert the bounded results to xts res <- xts(c(rep(NA,251),res), indx) }

# Return results return(res) }

Related

To leave a comment for the author, please follow the link and comment on their blog: FOSS Trading.