Today I want to share and present an example of the flexible Stop Loss functionality that I added to the Systematic Investor Toolbox.
Here is an example using 20 and 50 day moving averages on SPY.
Additionally, you can provide any other required information.
Following is an example of integrating these stop losses into the back-tests. Please note that I only use the Buy rule from the original strategy to open the trades and to close the trades I use the stop loss logic.
Nothing exciting to report. The fixed stop loss is not triggered often and resembles the Buy and Hold. The trailing stops reduce the time strategy is in the market and also reduce returns. The trailing stop with profit target is doing a bit better.
The shaded green area indicates the times when strategy is invested. In the top chart, the strategy is long once fast moving average (red line) is above the slow moving average (blue line).
The next chart (Fixed Stop) is fully invested because market has taken off since we entered the trade and stop, which is % relative to the trade entry price, is never triggered.
The last 2 charts show the trailing stop logic. Strategy is less often invested once we enforce the aggressive profit target.
Have fun with creating your own customized stop loss functions and let me know if you run into problems.
To view the complete source code for this example, please have a look at the bt.stop.ma.cross.test() function in bt.stop.test.r at github.
However, creating a long back-test is usually problematic because most ETFs do not have a long price history. One way to alleviate the short price history is to find an appropriate proxy asset/index to extend ETF’s price history.
For example in my last post, Update: Extending Commodity time series, I showed howyou can extend the price history of commodity ETFs with Thomson Reuters / Jefferies CRB Index.
Following is an example of using these functions for commodity ETFs and Thomson Reuters / Jefferies CRB Index.
# for "TRJ/CRB Index-Total Return"
The Thomson Reuters / Jefferies CRB Index (CRB_1) looks a better fit for commodity ETFs.
The Vanguard REIT (VGSIX) Index looks as a good proxy for the Dow Jones U.S. Real Estate Index (IYR), while Dow Jones Global Real Estate Index (RWO) does behave differently.
So the next time you are faced with a task of running a long history back-test, please have a look at extending your short history assets with proxies.
Thomson Reuters / Jefferies CRB Index.
To get data, first select “TRJ/CRB Index-Total Return”, next click “See Chart”. There will be “Download to Spreadsheet” link beneath the chart.
To get data, first select “TR/J CRB Global Commodity Equity Index”, “Total Return”, check “All Dates”, next click “OK” to download the data.
There is a difference between these two series. I did not found a reason for the discrepancy, but truthfully, I did not look very hard. So I welcome any insights or feedback.
The Thomson Reuters / Jefferies CRB Index time series is better fit for the DBC and GSG etfs.
Now let’s plot the CRB index alternatives and DBC and GSG Commodity ETFs side by side to visual check the similarity.