In my previous post I introduced the main concept I use to simulate the portfolio of strategies. In this post I will illustrate the mechanics of this approach.We will use a simple portfolio of 3 strategies that are described in this blog: WTAA, MEOM and DVI strategies. We will use Amibroker 5 steps to get to the result.
1. Run individual strategy in Backtester
The basic idea is to run each individual strategy in AB and store the strategy return array for use in the second iteration. If you are familiar with AB this should be straight forward. After a backtest, the strategy return gets automatically stored in the ~~~Equity – ticker in Group253. This ticker will be overwritten after each backtest, however this will be fixed with step 2.
When running a strategy, it is important to apply money management as if you were trading the strategy standalone (i.e. with % of equity or fixed fraction or … mm scheme). I also make it a habit to define a variable in the formula code that identifies the name of strategy, e.g:
2. Use custom backtest logic to generate individual strategy Equity curve
To avoid that the individual strategy return array is overwritten during the next backtest, I have written some Custom Backtest Code that copies the ~~~Equity ticker to a new ticker with a custom name. This code is applied at the end of the backtest run and creates a new ticker with a name ~~ Systemname. (note that systemname is a variable assigned in the strategy formula code used under step 1. The code for the CBT file can be downloaded at the end of the post.
e= Foreign( "~~~Equity", "C" ); AddToComposite(e/1000,"~~"+SystemName,"X",atcFlagDefaults | atcFlagEnableInPortfolio | atcFlagEnableInBacktest);
3. Repeat 1&2 for all systems of interest
Please make sure when doing this to use the right watchlist for each strategy and to ensure all strategies are run for the same period.
4. Add individual return arrays to watchlist
In the symbol list in Amibroker identify all newly created return arrays. Through my coding rules I can find them easily – the names of the symbols all start with double tildes: ~~… Add the return arrays of the strategies you want to include to a watchlist.
I have name one “Portfolio of Strategies” as shown below:
5. Run meta-strategy in Backtester on watchlist
The last step involves the 2nd iteration. It is basically a backtest using a very simple backtest buy & hold strategy in the 3 strategy return arrays as they are stored in the watchlist. Here is the formula for the portfolio strategy when applying it to the portfolio of the 3 strategies as mentioned before.
SystemName="sD_ETF_PortfolioOfSystems"; _CashPercentage=0;_MaxScaleIn=4; _Cashticker ="SHY"; _Cashticker2 = "VIX"; #include<Boiler Plate.afl> #include<Additional Functions.afl> #include<OutputStatistics.afl> pos=3; Size=25000; SetOption("InitialEquity",size*pos); SetOption("AccountMargin",100); SetPositionSize(100/pos,spsPercentOfEquity); SetOption("MaxOpenPositions", pos ); //SetOption("interestrate",2.4); Buy = True; Sell= False; Short =0; Cover =0;
The Example / First Results
In the example I have used the 3 strategies as described in this blog. In the portfolio system described in step 5 I allocate 25000$ to each of the three strategies and simulate a “buy & hold” in each of the strategies. No rebalancing or any other fancy logic is applied. The results are shown below in 2 pictures. The first shows the normalised equity curves for the individual strategies and the portfolio. The second picture shows the equity curve, the monthly/yearly returns as well as the rolling 3yr Ann Sharpe ratio for the portfolio.
Finally I you can use this link to download the Custom Backtest file. It has a .docx extension (due to WordPress inability to upload .txt or .afl files). So you have to rename it to .afl and store it in the \include folder. The file contains some instructions at the top of the file (read the note).