Chapter 9 Complex trading rule

To test a complex trading rule, the R code can be too large to be manageable. Luckily, there is package quantstrat to handle this problem.

Since quantstrat is not standard package, we first learn how to install custom package.

We will illustrate the usage of the quantstrat package by showing how four different rules be applied:

  1. naive filter rule,
  2. buy and hold,
  3. simple SMA rule,
  4. SMA rule with a volatility filter.

Since the coding is complicated, we first overview the structure of the code. There are five parts:

  1. Initialization
  2. Indicator: filter rule/SMA rule
  3. Signals: buy/sell signals
  4. Rule: buy or sell? quantity?
  5. Evaluation of results.