Do you use R for backtesting?

Discussion in 'Automated Trading' started by pisco, Dec 25, 2013.

  1. pisco

    pisco

    Hello guys,

    I heard a lot of good things about R(for example the extense amount of packages) and want to consider it as a backtesting plattform for trading ideas.

    Therefore my questions to you are:

    Do you use R statistics?

    Whats your backtesting process, which packages are you using?

    Can you recommend some resources about "backtesting with R"?

    I appreciate your answers!
     
  2. 2rosy

    2rosy

    I use R sometimes. It has the most comprehensive stats packages that I know of. I dont use R for backtesting but there is a backtest library you can google for called quantstrat
     
  3. Yes.

    I use mostly my own code, making extensive use of the data.table package, and IDate to represent dates.

    You need to use vectors and data.tables for everything with no loops (i.e. in an Excel-like manner).

    If you use loops to iterate over days, it will be too slow and I recommend not using it.
     
  4. gmst

    gmst

    Rosy, what do you use for backtesting?
     
  5. I second this. Most of the time, if you start writing R code as,

    for(i in 1:length(vect)
    {
    ...
    }

    you're doing it wrong.
     
  6. Absolutely, but if performance is an issue for you, have a look at kdb+. I personally prefer to use q as the main backtesting/data processing engine and interface to R only when needed i.e. to run linear regressions, etc.

    In the kdb+ wiki page there are some good links for q->R and R->q interfaces.

    J.
     
  7. Craig66

    Craig66

    kdb+ is great if you have a shit ton to drop on the license.

    I use R, but it's more for visualization and rough testing, the back testing packages are a work in progress, to be kind. As far as specific packages go, I don't think most people use more than the time series & linear algebra stuff (and ggplot2).

    In general, you want your back-testing env. to be as close to your live env. as possible, having to re-code everything from R to whatever is just an error prone PITA, what is going to cost you time.
     
  8. This forum isn't the right one to be pushing kdb, I suspect if the OP knows what it is and could afford it - he wouldn't be asking basic questions about R.

    That being said, OP you never mentioned if you wanted a vectorized backtest or an event-driven one. Vectorized you don't even need a library to do it, just familiarize yourself with basic R functionality. Event-driven, I don't think is suitable for R.
     
  9. a5519

    a5519

    Unfortunately, backtesting of real-trading relevant ideas best of all can be done in an event driven environment, or by simulating such. Nevertheless, R can be used for efficient implementation of numerical calculations.
     
  10. I think that's true and false, depending on who you ask. My overall approach to research is to do data exploration and simple backtests in either R or Python.

    Once an idea seems to have good potential then build the strategy out in an event-driven system, which runs on the same codebase as my ATS.

    See the issue I find is that you'll often spend an enormous amount of time getting code up in a production language. I'd rather spend that time filtering a higher number of strategies through R/Python - won't be always stuck working on one thing.
     
    #10     Jan 17, 2014