David Varadi's RSI(2) alternative

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:

  1. Varadi’s RSI(2) Alternative: The DV(2)
  2. RSI(2) vs. DV(2)
  3. Last Couple of Notes on DV(2)

Here’s the R code:

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)  
}

RSI(2) Evaluation

This post continues the series of investigating the RSI(2) strategy. The first post replicated this simple RSI(2) strategy from the MarketSci Blog using R. The second post showed how to replicate the strategy that scales in/out of RSI(2).

If you like the RSI(2), be sure to check out David Varadi’s RSI(2) alternative!

This post will use the PerformanceAnalytics package to evaluate the rules that scale in/out of positions. I’ve also provided a simple function that provides some summary statistics. There is a lot of code, so I put it at the end of the post.

Packages featured with Inference for R

quantmod, TTR, and xts were (not so) recently featured on the Inference for R Blog. Inference for R is a Integrated Development Environment (IDE) designed specifically for R.

The post gives an example of how to easily perform advanced financial stock analysis using Inference in Excel.

I appreciate how they’re making R more accessible to a general audience, even though I like a command line interface and my preferred development environment is vim. :-)

R/Finance 2009 Presentations Online

Posted to the R-SIG-Finance mailing list today:

For those who missed it, the slides for the R/Finance 2009 tutorials
and presentations are now available on RinFinance.com

http://www.RinFinance.com/presentations

We want to thank everyone who traveled to Chicago to make this happen. With nearly 200 attendees, coming from 8 countries and 20+ states in the US, the conference exceeded all of our expectations. A very big thank you to our presenters for taking the time to join us, UIC’s International Center for Futures and Derivatives for hosting the event, and our sponsors REvolution Computing and Microsoft for their support.

RSI(2) with Position Sizing

Though it’s more than two weeks later, here’s the second post in the series that will demonstrate how to build, test, and implement a trading strategy with R. You can find the first post here.

The first post replicated this simple RSI(2) strategy from the MarketSci Blog. This second post will demonstrate how to replicate this strategy that scales in/out of RSI(2).

A couple notes before moving to the code:

  1. The rsi2pos() function isn’t necessary, but it provides an example of how to define a function. Plus, it enables us to test several ideas with much greater speed and flexibility.

R/Finance 2009 Overview

The first international R/Finance 2009 conference in Chicago, IL was a huge success! David Smith from REvolution Computing has written a great summary of the entire event. I’ll take the lazy route and point you to his blog post. :)

The first international conference dedicated to the use of R in the finance industry, R/Finance 2009, was a great success. With over 150 attendees (my poor estimation skills notwithstanding), sold-out tutorials, and an outstanding lineup of invited and contributing speakers from around the world, this event really demonstrated the importance of R in the world of financial analysis.

opentick is no more

After a year of “we plan to accept new subscribers shortly”, opentick has shut its doors completely. As of March 20th, the opentick service is no longer available.

From opentick.com:

3/16/2009

To opentick subscribers, friends, supporters, contributors and the rest of the community…

It has been quite a journey for opentick, and for those of you who have been with us for the ride we cannot thank you enough for the support, contributions and guidance you have given us over the course of the last 5 years. We could not have come as far as we have without you.

Testing RSI(2) with R, First Steps

This is the first of a series of posts that will demonstrate how to build, test, and implement a trading strategy using my favorite FOSS, R. I chose the RSI(2) strategy because it has gotten considerable attention on trading blogs over the past 6 months.

In particular, I will be replicating and extending some of the results from Michael Stokes’ excellent MarketSci Blog. This post will focus on replicating this simple RSI(2) strategy.

TTR_0.2 on CRAN

I am happy to announce a long-overdue update to the TTR package (version 0.2) is now on CRAN.

This update represents a major milestone, as TTR useRs are no longer restricted to using matrix objects. TTR 0.2 uses xts internally, so all major time series classes are now supported.

NEW FEATURES:

  • Added the zig zag indicator: ZigZag()
  • Added volatility estimators/indicators: volatility(), with the following calculations
    • Close-to-Close
    • Garman Klass
    • Parkinson
    • Rogers Satchell
  • Added Money Flow Index: MFI()
  • Added Donchian channel: DonchianChannel()

CHANGES: