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:
- naive filter rule,
- buy and hold,
- simple SMA rule,
- SMA rule with a volatility filter.
Since the coding is complicated, we first overview the structure of the code. There are five parts:
- Initialization
- Indicator: filter rule/SMA rule
- Signals: buy/sell signals
- Rule: buy or sell? quantity?
- Evaluation of results.