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.