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 stringname
, a vector forsymbols
used in the backtest, an initialization dateinitDate
, and acurrency
. - The account initialization call
initAcct()
is identical to the portfolio initialization call except it takes an account stringname
instead of a new portfolio name, an existingportfolios
name, and an initial equityinitEq
. - The orders initialization
initOrders()
needs a portfolio stringportfolio
and an initialization dateinitDate
. - The strategy initialization
strategy()
needs aname
of this new strategy and must havestore
set toTRUE
.
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
Exercise instructions
- Use
initPortf()
to initialize the portfolio calledportfolio.st
with"SPY"
,initdate
, and"USD"
as the arguments. - Use
initAcct()
to initialize the account calledaccount.st
withportfolio.st
,initdate
,"USD"
, andiniteq
as the arguments. - Use
initOrders()
to initialize orders calledportfolio.st
andinitdate
as the arguments. - Use
strategy()
to store a strategy calledstrategy.st
withstore = 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 = ___)