Running your strategy
Congratulations on creating a strategy in quantstrat! To review, your strategy uses three separate indicators and five separate signals. The strategy requires both the threshold of the DVO_2_126 indicator to be under 20 and the SMA50 to be greater than the SMA200. The strategy sells when the DVO_2_126 crosses above 80, or the SMA50 crosses under the SMA200.
For this strategy to work properly, you specified five separate signals:
sigComparisonforSMA50being greater thanSMA200;sigThresholdwithcrossset toFALSEforDVO_2_126less than 20;sigFormulato tie them together and setcrosstoTRUE;sigCrossoverwithSMA50less thanSMA200; andsigThresholdwithcrossset toTRUEforDVO_2_126greater than 80.
The strategy invests $100,000 (your initeq) into each trade, and may have some small dollar cost averaging if the DVO_2_126 oscillates around 20 (though the effect is mostly negligible compared to the initial allocation).
In this final chapter, you will learn how to view the actual results of your portfolio. But first, in order to generate the results, you need to run your strategy and fill in some more boilerplate code to make sure quantstrat records everything. The code in this exercise is code you will have to copy and paste in the future.
Diese Übung ist Teil des Kurses
Financial Trading in R
Anleitung zur Übung
- Use applyStrategy() to apply your strategy (
strategy.st) to your portfolio (portfolio.st). Save this to the objectout. - Run necessary functions to record the results of your strategy, including
updatePortf()and setting thedaterangeas well asupdateAcct()andupdateEndEq(). - Based on this information, see if you can find the date of the last trade.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Use applyStrategy() to apply your strategy. Save this to out
out <- applyStrategy(strategy = ___, portfolios = ___)
# Update your portfolio (portfolio.st)
updatePortf(___)
daterange <- time(getPortfolio(___)$summary)[-1]
# Update your account (account.st)
updateAcct(___, daterange)
updateEndEq(___)