Excel

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.

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.

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.