How to backtest a strategy in R

This is the third post in the Backtesting in Excel and R series and it will show how to backtest a simple strategy in R.  It will follow the 4 steps Damian outlined in his post on how to backtest a simple strategy in Excel.

Step 1: Get the data
The getSymbols function in quantmod makes this step easy if you can use daily data from Yahoo Finance.  There are also “methods” (not in the strict sense) to pull data from other sources (FRED, Google, Oanda, R save files, databases, etc.).  You could also use them as a template to write a custom function for a particular vendor you use.

Risk-Opportunity Analysis: Houston

I will be attending Ralph Vince’s risk-opportunity analysis workshop in Houston this weekend.  I’ll be in town Friday-Monday.  Drop me a note if you’re in the area and would like to meet for coffee / drinks.

How to backtest a strategy in Excel

(This is a guest post by Damian from Skill Analytics and ETF Prophet)

Let me start by saying that I’m not an expert in backtesting in Excel – there are a load of very smart bloggers out there that have, as I would say, “mad skillz” at working with Excel including (but not limited to) Michael Stokes over at marketsci.com, Jeff Pietch over at etfprophet.com and the folks (David and Corey) over at cssanalytics.wordpress.com. All of these guys have been gracious enough, over the years, to share with me how to do backtests – so I am indebted to them. And I want to thank Josh here at FOSS Trading as well – because he’s been kind enough to help me in learning how to use R for testing.

R/Finance 2011 Registration Open

The registration for R/Finance 2011–which will take place April 29 and 30 in Chicago–is NOW OPEN!

Building on the success of the two previous conferences in 2009 and 2010, we are expecting more than 250 attendees from around the world representing both industry and academia to join a record 30+ presentations covering all areas of finance with R.

This year we are excited to have longer tutorial sessions and an optional full-day workshop on the Thursday before the conference. In addition, we have worked hard to extend the great networking opportunities on both days with longer breaks and more hallway time between sessions.

Moving from Excel to R

This first post of the Backtesting in Excel and R series will provide some resources to help smooth the transition from the familiarity and comfort of Excel to the potentially strange and intimidating world of R.

I made my voyage from Excel to R more than 5 years ago and learned mostly by trial and error (and reading the R manuals).  Most people don’t prefer my approach of “keep at it until you figure it out”, so I don’t have a lot of personal advice to share.  My main piece of advice is that the best way to learn R is to use it, so most of the resources below focus on “how-to” do certain things in R.

Backtesting in Excel and R

This post is the introduction to a series that will illustrate how to backtest the same strategy in Excel and R.  The impetus for this series started with this tweet by Jared Woodard at Condor Options.  After Soren Macbeth introduced us, Jared suggested  backtesting a simple DVI strategy in Excel and R.

The three-post series will show you:

  1. Resources that make it easier to move from Excel to R
  2. How to test DVI in Excel
  3. How to test DVI in R

Since I know next to nothing about testing strategies in Excel, I will be writing posts 1 and 3.  Jared was kind enough to create the Excel framework for post 2, but did not have time to devote to a full post.  Thankfully, Damian Roskill has agreed to write post 2 using Jared’s Excel file.

Stack Exchange: Quantitative Finance in public beta

The Quantitative Finance Stack Exchange community entered public beta last week.  To quote the FAQ:

The Quantitative Finance Stack Exchange is intended specifically for professionals and traders working in investment banking, and academics involved in teaching and research.

Topics include pricing of securities, derivatives, options, risk modeling, quantitative techniques, and the mathematics used in quantitative finance.

Several members of the R/Finance community are active there too.  Some names you may recognize: Patrick Burns, Shane, Dirk Eddelbuettel, Jeff Ryan, and Paul Teetor.

R/Finance 2011 Call for Papers

The 2011 R/Finance conference has an updated call for papers.  Dirk Eddelbuettel announced it to the R-SIG-Finance mailing list.  I’ve reproduced his email in its entirety below.  Let me know if you plan on attending.


Subject: R/Finance 2011: Call for Papers: Now with prizes and travel money

Dear R / Finance community,

The preparations for R/Finance 2011 are progressing, and due to favourable responses from the different sponsors we contacted, we are now able to offer

Why Use R?

I use R very frequently and take for granted much that it has to offer.  I forget how R is different from similar tools, so I have trouble communicating the benefits of using R.  The goal of this post is to highlight R’s main strengths, but first… my story.

How I got started with R

I was introduced to R while I was working as a Research Analyst at the Federal Reserve Bank of St. Louis.  I wanted to do statistical analysis at home but the tools I used at work (GAUSS and SAS) were expensive, so I started doing my analysis in Excel.