1. Analyzing your strategy
Welcome to chapter 6. This is the final chapter in the course.
2. Our strategy
To review, you've put together a strategy that uses several indicators and all of the signal functions in quantstrat. To review, the strategy buys when both of these conditions first occur: the 50-day simple moving average is above the 200-day simple moving average, and the dvo, an oscillating type indicator, is under 20. It then sells when the dvo crosses above 80, or the 50-day simple moving average crosses under the 200-day simple moving average.
3. Run your strategy
This chapter is about analyzing the results of your strategy.
In order to run your strategy and obtain results, you first need to call the applyStrategy function, and then update your portfolio and account, in that order. This code displays how to do just this. Here's a bit of an explanation: after you apply your strategy, you need to call functions to update R's analytics environment. You first update your portfolio with all the transactions your strategy took. Next, you take the dates of your simulation (not the first date, which is your portfolio initialization date, back from chapter two), and update your account with the results of your portfolio. Lastly, you need to update the ending equity in your account. The arguments for these updates are the portfolio and account strings you defined back in chapter two. When updating portfolio arguments, use portfolio-dot-st, and when updating account arguments, use account-dot-st.
4. Trade statistics
Next, perhaps the most vital summary of your trading strategy is the trade statistics table. The trade statistics table includes statistics such as number of trades, the percentage of trades that were positive, the profit factor--which is how many dollars the strategy made for every dollar lost, and more. For a first-pass view of trading system performance, you should always look at the trade statistics table.
The statistics to pay attention to are: the number of trades, as this will let you know if you have a decent sample size or you might need more trades. The percent positive is an important number to see how often a trade can expect to go well. Lastly, the average and median win/loss ratios provide a very objective comparison between winning and losing trades, in terms of the size differences between the two. Its interpretation is what is the ratio between the average winner and the average loser, regardless of winning percentages. Essentially, percent positive and the value of the average win/loss ratio can be thought of as inversely proportional in many cases.
5. Characteristics of trading systems
In practice, strategies that use a moving average crossover as a primary signal (for example, buy when the 50 day moving average crosses above the 200) will often have less than half of their trades be winners, but will have winners that are larger than losers. For instance, it would not be out of the ordinary to see a trading system based on moving averages to have 40% of trades be positive, but a ratio of more than 2 to 1 for the average winner to the average loser.
On the other hand, strategies that use an oscillation signal, such as the one developed in this class, are often characterized by a high percentage of positive trades (that is, more than one in two trades make money), but an average win to loss ratio of less than one (that is, the average loser loses more money than the average winner makes).
6. Let's practice!
In the following exercises, you will answer some questions using these trade statistics.