# Chapter 8 Quanstrat

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,
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
4. Rule: buy or sell? quantity?
5. Evaluation of results.

Before we start, let us make sure that we have installed the following four standard packages:

1. quantmod,
2. PerformanceAnalytics,
3. FinancialInstrument, and
4. foreach.

If your R does not have them, please run the following code:

install.packages("quantmod")
install.packages("FinancialInstrument")
install.packages("PerformanceAnalytics")
install.packages("foreach")

FinancialInstrument allows you to specify your assets class (e.g., stock, derivatives, currency) and foreach is a package that allow fast computation (i.e., parallel computation).