Get startedGet started for free

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.

This exercise is part of the course

Financial Trading in R

View Course

Exercise instructions

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

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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 = ___)
Edit and Run Code