CommencerCommencer gratuitement

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:

  1. An initialization date for your backtest.
  2. The start of your data.
  3. 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.

Cet exercice fait partie du cours

Financial Trading in R

Afficher le cours

Instructions

  • Use the library() command to load the quantstrat package.
  • Set initdate as January 1, 1999, from as January 1, 2003, and to as December 31, 2015.
  • Set a timezone of "UTC" using Sys.setenv().
  • Set a currency of "USD" using currency().

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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(___)
Modifier et exécuter le code