Introduction to rules
1. Introduction to rules
Welcome to the chapter on rules in quantstrat.2. What are rules?
Rules are a way for you to specify how exactly you will create your transaction once you decide you wish to execute on a signal. That is, given that a particular signal value has generated a TRUE statement, how much are you looking to buy or sell? In terms of complexity, rules are the most involved of the three structures in quantstrat -- indicators, signals, and rules. While indicators and signals are fairly straightforward, rules have many more parts, and a great deal of customization. While most of this customization is beyond the scope of this course, eventually, you will know how to use rules in conjunction with order sizing functions, and be able to make use of market orders that can change the size of the position based on various other inputs.3. Using add.rule()
Because of the complicated structure of add-dot-rule(), you will be exposed to new arguments in each video of this chapter. First and foremost, there are two types of rules within the scope of this class: enter rules and exit rules. Enter rules are rules that are about establishing a position--namely, in this case, buying shares of an ETF. Exit rules are rules dedicated to taking your money out of an asset, and converting it back into cash, ready for re-use. In the scope of an add-dot-rule call, the rule type input will take the value of enter or exit. One key difference between rules and indicators or signals is that rules only use one catch-all function for almost all inputs. It is called ruleSignal. Most of the arguments for rules will serve as arguments to ruleSignal. Furthermore, like indicators and signals before them, rules also reference existing columns in your strategy. These existing columns are denoted by the label argument in your add-dot-signal calls. The sigcol argument is the input that quantstrat uses to find existing signal columns in your strategy. Next, ruleSignal takes in a sigval argument. This argument tells quantstrat what value within the particular signal column triggers a transaction. While this value can be something other than TRUE, it is fairly good practice to set this argument to TRUE if your signal columns are set up correctly to only return TRUE when you potentially want to enter into a transaction.4. Let's practice!
In the following exercises, you will be working with several rules with various features filled in or not filled in. Your job will be to fill in the missing pieces and build up an understanding of the various parts of rules in quantstrat.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.