• Australian (ASX) Stock Market Forum

Hello and welcome to Aussie Stock Forums!

To gain full access you must register. Registration is free and takes only a few seconds to complete.

Already a member? Log in here.

Multi system analysis - Amibroker

Discussion in 'Trading Strategies/Systems' started by Warr87, May 3, 2020.

  1. Warr87

    Warr87

    Posts:
    352
    Likes Received:
    656
    Joined:
    Jun 28, 2019
    I wanted to see how my systems would perform if I were to run them at the same time and see if I would be better off to do so. And I thought I would share this with others as well.

    First: there is a tutorial here, https://decodingmarkets.com/combine-equity-curves-in-amibroker/ . Please note that the majority of what I am showing came from that tutorial but I am showing you what I had to do differently.


    • Open up Formula Editor for one of the systems you would like to compare. In there add the following CBT (custom backtest)
    Code:
    // The code for AmiBroker 5.50 and above
    // YOUR TRADING SYSTEM HERE
    // ....
    SetCustomBacktestProc("");
    if( Status("action") == actionPortfolio )
    {
    bo = GetBacktesterObject();
    bo.Backtest();
    AddToComposite( bo.EquityArray, "~~~SYSTEM_NAME", "X", atcFlagDeleteValues | atcFlagEnableInPortfolio ;
    }
    • Do the above step for all the systems you would like to compare
    • The equity for your system will now be saved as "~~~SYSTEM_NAME" and can be seen in the ticker symbol area.
    • Create a new formula in Formula Editor with the following (this is to give us the data to copy into an excel sheet or export as a CSV):
    Code:
    Filter=1;
    AddColumn(O,"Open");
    AddColumn(H,"High");
    AddColumn(L,"Low");
    AddColumn(C,"Close");
    AddColumn(V,"Volume",1.0);
    AddColumn(OI,"Open Interest",1.0);
    • Go to a new analysis window, run the code above on your systems ticker.
    upload_2020-5-3_18-3-55.png

    • You can see that my ticker ~~~MAP_1_6 is selected, which is for my MAP system, v1.6. I also have selected in the settings Weekly. This will give you the weekly values for the system.
    • From here you can either CTL + A, and paste into excel, or you can "Export as HTML/CSV".
    • Repeat the above for all of the systems you want to compare. I just did 2, but you can do more.
    • I kept all my systems with the same amount of starting equity. Now that you have the data in excel you can run your metrics: individual gains, combined gains, maxDD for the same, and then you can put these into charts.

    Hope that helps some people who are contemplating running multiple systems.
     
  2. Lone Wolf

    Lone Wolf

    Posts:
    436
    Likes Received:
    146
    Joined:
    Dec 4, 2008
    You said in your other thread that you couldn't get the buy and hold section of the tutorial to work. I just went through the tutorial. Everything works as described with one exception. I had two systems. When I did the buy and hold bit with a limit of two positions max, it only bought one. If I set it to three or higher it worked fine.

    It's because I had position size set to 50% of the initial account size. I also had $20 commissions. So after it spent 50% of the account plus $20 on the first position, there was no longer enough cash to buy the second position. If you turn off commissions it works fine with two positions max.
     
    qldfrog, sptrawler and Skate like this.
  3. Warr87

    Warr87

    Posts:
    352
    Likes Received:
    656
    Joined:
    Jun 28, 2019
    still not working for me. Adjusted like you suggest and it's still only taking 1 position unfortunately.
     
  4. Lone Wolf

    Lone Wolf

    Posts:
    436
    Likes Received:
    146
    Joined:
    Dec 4, 2008
    There aren't too many things that could be preventing it from taking the second position. Do you have enough starting capital? If you backtested your systems with $100,000 starting capital then you will need $100,000 for each position you want to enter. (ie. $200,000 to take two positions). Try adding up your ticker starting values and make sure you have more than that available
     
  5. Warr87

    Warr87

    Posts:
    352
    Likes Received:
    656
    Joined:
    Jun 28, 2019
    I kept on fiddling with it for while. Not sure what I did, but it kind of works. I don't know why it is so damn hard to just do a buy/hold run in AB for me lol.
     
    Lone Wolf likes this.
  6. Warr87

    Warr87

    Posts:
    352
    Likes Received:
    656
    Joined:
    Jun 28, 2019
    @Lone Wolf , if I can get it to work consistently and easier than that would be great.

    For the moment it is quicker for me to copy/paste into excel and calculate everything in there. It's a shame. It's likely something small (its always operator error).
     
    qldfrog likes this.
  7. Warr87

    Warr87

    Posts:
    352
    Likes Received:
    656
    Joined:
    Jun 28, 2019
    I found an easier way.

    The following code worked for me using this multi-system test where the equity is saved as a seperate ticker:

    Code:
    maxpos = 4; // maximum number of open positions
    SetOption("InitialEquity", 400000 ); // set initial equity = 100K per position, as each system was backtested using 100k starting equity.
    SetOption( "MaxOpenPositions", maxpos );
    SetPositionSize( 1, spsShares ); //
     
    Buy = 1;
    Sell = 0; 
    Change the maxpos based on how many customer tickers you have in your watchlist in AB. In my case, I have 4. Therefore, I have also set 100k x 4 for starting equity since in my backtest each system started with 100k.
     
    qldfrog and Lone Wolf like this.
  8. Lone Wolf

    Lone Wolf

    Posts:
    436
    Likes Received:
    146
    Joined:
    Dec 4, 2008
    That works. I was using spsPercentOfEquity and just changing the starting equity to be the sum of all tickers.

    If you wanted it to be even easier you could try this. Just use the parameters to select the number of systems you want to test and the starting capital you used for those tests.

    Code:
    maxPos = Param("Number of Equity Tickers", 2, 1, 10, 1);
    initialEquity = maxPos * Param("Ticker Starting Equity", 100000, 10000, 500000, 10000);
    SetOption("InitialEquity", initialEquity);
    SetOption( "MaxOpenPositions", maxPos);
    SetPositionSize( 1, spsShares );
    
    upload_2020-5-4_18-58-39.png
     
    Warr87, qldfrog and Skate like this.
  9. Warr87

    Warr87

    Posts:
    352
    Likes Received:
    656
    Joined:
    Jun 28, 2019
    I tried percent of equity but it just wasn't working. Then I noticed when it bought it would buy 1 share, so I figured I would switch to the code I posted.

    I will give your code above a go soon.

    What I wish you could do with AB, as I know you can do it in python with quant engines, and that is to optimise the portfolio of systems—that is, how much allocation to give to each system to reach optimal returns.
     
  10. Lone Wolf

    Lone Wolf

    Posts:
    436
    Likes Received:
    146
    Joined:
    Dec 4, 2008
    That's far beyond me. Although it sounds achievable if it's only capital allocation you want to optimize.

    But what about optimizing all your system settings with the wider portfolio of systems in mind? It's possible that the best settings for a system when used as part of a group would be different from the settings you'd use if you ran the system in isolation.
     
    Warr87 likes this.
  11. Warr87

    Warr87

    Posts:
    352
    Likes Received:
    656
    Joined:
    Jun 28, 2019
    Yes, it would be capital allocation. For example, if you look at Clenow's books he goes through the optimal allocation to strategies (40% futures, 60% equities).

    That is a good point. That may be getting close to over optimizing though. There is also the wider question with multiple systems, if all systems have a signal for a stock do you let all systems buy the same? Deconflicting this in system design would be a good idea, if its possible. Another solution would be to simply have different universe of stocks.
     
Loading...

Share This Page