Using add.rule() to implement an entry rule
Excellent! You've mastered every element of the rule building process in quantstrat. While thus far you've added rules step-by-step, now it's time to put it all together and see how well you've been able to absorb the material in this chapter.
The opposite of an exit rule is an enter rule. On enter rules, orderqty cannot be set to "all" because there is no initial position on which to act. In this exercise, you will implement an enter rule that references the longentry signal in your strategy and will buy one share of an asset.
Diese Übung ist Teil des Kurses
Financial Trading in R
Anleitung zur Übung
- Specify the arguments in
add.rule()to implement your new enter rule. - Your rule should be triggered when the
longentrysignal is equal toTRUE. - Your rule should buy
1share of an asset as a"market"order. - Your rule side should be
longand replace should beFALSE. - Your rule should buy on the next day's
Openafter observing a signal.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Create an entry rule of 1 share when all conditions line up to enter into a position
add.rule(strategy.st, name = "ruleSignal",
# Use the longentry column as the sigcol
arguments=list(sigcol = "___",
# Set sigval to TRUE
sigval = ___,
# Set orderqty to 1
orderqty = ___,
# Use a market type of order
ordertype = "___",
# Take the long orderside
orderside = "___",
# Do not replace other signals
replace = ___,
# Buy at the next day's opening price
prefer = "___"),
# This is an enter type rule, not an exit
type = "___")