开始使用免费开始使用

Understanding initialization settings - IV

Now that everything has been named, you must initialize the portfolio, the account, the orders, and the strategy to produce results.

  • The portfolio initialization initPortf() needs a portfolio string name, a vector for symbols used in the backtest, an initialization date initDate, and a currency.
  • The account initialization call initAcct() is identical to the portfolio initialization call except it takes an account string name instead of a new portfolio name, an existing portfolios name, and an initial equity initEq.
  • The orders initialization initOrders() needs a portfolio string portfolio and an initialization date initDate.
  • The strategy initialization strategy() needs a name of this new strategy and must have store set to TRUE.

The initdate and initeq objects that you created in previous exercises have been loaded for you, as well as the quantstrat and quantmod packages.

本练习是课程的一部分

Financial Trading in R

查看课程

练习说明

  • Use initPortf() to initialize the portfolio called portfolio.st with "SPY", initdate, and "USD" as the arguments.
  • Use initAcct() to initialize the account called account.st with portfolio.st, initdate, "USD", and initeq as the arguments.
  • Use initOrders() to initialize orders called portfolio.st and initdate as the arguments.
  • Use strategy() to store a strategy called strategy.st with store = TRUE as the arguments.

交互式实操练习

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

# Initialize the portfolio
initPortf(___, symbols = ___, initDate = ___, currency = ___)

# Initialize the account
initAcct(___, portfolios = ___, initDate = ___, currency = ___, initEq = ___)

# Initialize the orders
initOrders(___, initDate = ___)

# Store the strategy
strategy(___, store = ___)
编辑并运行代码