Understanding initialization settings - I
Define boilerplate code
Let's get started with creating our first strategy in quantstrat
. In this exercise, you will need to fill in three dates:
- An initialization date for your backtest.
- The start of your data.
- The end of your data.
The initialization date must always come before the start of the data, otherwise there will be serious errors in the output of your backtest.
You should also specify what time zone and currency you will be working with with the functions Sys.setenv() and currency()
, respectively. An example is here:
Sys.setenv(TZ = "Europe/London")
currency("EUR")
For the rest of this course, you'll use UTC (Coordinated Universal Time) and USD (United States Dollars) for your portfolio settings.
This exercise is part of the course
Financial Trading in R
Exercise instructions
- Use the
library()
command to load thequantstrat
package. - Set
initdate
as January 1, 1999,from
as January 1, 2003, andto
as December 31, 2015. - Set a timezone of
"UTC"
usingSys.setenv()
. - Set a currency of
"USD"
usingcurrency()
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Load the quantstrat package
# Create initdate, from, and to strings
initdate <- ___
from <- ___
to <- ___
# Set the timezone to UTC
Sys.setenv(___)
# Set the currency to USD
currency(___)