More rule mechanics II
1. More rule mechanics II
2. More arguments to ruleSignal
Two more ruleSignal arguments are the replace and prefer arguments.3. Structure
The replace argument is this: when quantstrat acts on a signal, should it cancel all other signals that day? If so, this argument should be set to TRUE. If not, this argument should be set to FALSE. In general, while there may be certain instances when setting replace to TRUE would be a good idea, it is generally a bad idea to leave this argument as TRUE, and it should be set to FALSE for all intents and purposes. Next, the prefer argument is useful for determining when to enter into a position at the next bar. In quantstrat, acting on a signal is not instantaneous, and the entry is delayed by one bar (unless at the microsecond level, where temporal lag has an impact). A bar is a set of four observations--the day's open, high, low, and close, which form the bar shape. A delay of one bar on daily data is a delay of one day. If you need to observe the closing price in order to form a signal, you can only buy sometime during the next day. When using OHLC data, the default operation is to buy at the close of the next day or bar. However, this means that there is a full one day delay between observing a signal and acting upon it, even though it may be prudent to act on it at the next available opportunity. For this reason, the prefer argument is useful, even with market orders.4. Let's practice!
This concludes all of the basic mechanics of rules in quantstrat. In the next exercises, you will get practice using these last two mechanics, and code your own rule from scratch. Good luck.Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.