开始使用免费开始使用

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.

本练习是课程的一部分

Financial Trading in R

查看课程

练习说明

  • 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().

交互式实操练习

通过完成这段示例代码来试试这个练习。

# 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(___)
编辑并运行代码