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 forsymbolsused 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 stringnameinstead of a new portfolio name, an existingportfoliosname, and an initial equityinitEq. - The orders initialization
initOrders()needs a portfolio stringportfolioand an initialization dateinitDate. - The strategy initialization
strategy()needs anameof this new strategy and must havestoreset 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.
Cet exercice fait partie du cours
Financial Trading in R
Instructions
- Use
initPortf()to initialize the portfolio calledportfolio.stwith"SPY",initdate, and"USD"as the arguments. - Use
initAcct()to initialize the account calledaccount.stwithportfolio.st,initdate,"USD", andiniteqas the arguments. - Use
initOrders()to initialize orders calledportfolio.standinitdateas the arguments. - Use
strategy()to store a strategy calledstrategy.stwithstore = TRUEas the arguments.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de 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 = ___)