• Skip to content
  • Skip to primary sidebar
  • Skip to footer

JB MARWOOD

  • Top Posts
  • Marwood Research
  • Resources
    • Books
  • Free System
  • Blog
    • About
    • Book
    • Signals
    • Q & A
    • Tweets
You are here: Home / Amibroker / How To Combine Equity Curves In Amibroker And Improve Trading System Performance

February 3, 2017 By Joe Marwood 6 Comments

How To Combine Equity Curves In Amibroker And Improve Trading System Performance

One of the keys to successful system trading is to be able to combine different strategies together. When you are able to combine less correlated strategies, it is possible to smooth drawdown, boost win rate and therefore improve your overall risk-adjusted returns.

In Amibroker it is possible to combine equity curves together so you can see what the advantages are.

Notice that in the first paragraph above I mention ‘less correlated’ instead of ‘uncorrelated’. That’s because it is rare to find profitable strategies that are completely uncorrelated. But so long as a system has a profitable edge and is slightly uncorrelated, great things can still be achieved.

An Example Of Combining Trading Systems

As an example, consider two trading systems.

The first is a long-only stock system that follows trends. The second is a mean reversion short-only system. The table below shows the key statistics from each system on it’s own.

combining equity curves in amibroker table of results one

On the face of it, you would probably prefer to trade system 1 on it’s own since it has a higher annual return and a smaller drawdown than system 2.

However, when we combine the systems, we can see what would have happened if we had traded both systems at the same time (with equal amount of capital allocated to each).

table two results of combining equity curves

As you can see, although our annualized return has decreased slightly, we have significantly reduced our maximum drawdown.

Our CAR/MDD ratio has now advanced to 1.03 indicating that combining the two systems leads to smoother, more consistent performance. As a result, we are likely to experience fewer losing streaks as well.

combined equity curves in amibroker results

How To Combine Equity Curves In Amibroker

Now that we have seen the benefits of combining trading systems we can look at how to combine equity curves in Amibroker and there are two main options available.

Option 1 – AddToComposite Function

The simplest option is to use the Amibroker AddToComposite function to save the equity curves to a special ticker and then combine them together with another formula.

Bascially, every time Amibroker runs a back-test, it stores the equity of the trading system in a special ticker known as “~~~EQUITY”. This ticker gets re-populated every time a new back-test is run.

However, with the AddtoComposite function we can save the equity to any ticker name we like so that we can use it later on.

All you have to do is add the following code underneath your trading system rules and when you run a back-test your equity from that test will be saved to the new ticker called “~~~MY_EQUITY_COPY”.

// The code for AmiBroker 5.50 and above
// YOUR TRADING SYSTEM HERE
// ....
SetCustomBacktestProc("");
if( Status("action") == actionPortfolio )
{
bo = GetBacktesterObject();
bo.Backtest();
AddToComposite( bo.EquityArray,
"~~~MY_EQUITY_COPY", "X",
atcFlagDeleteValues | atcFlagEnableInPortfolio );
}

Here is the Amibroker page that explains it.

Once you have your equity curve saved as a symbol you can use it in various other ways and combine it with a different equity curve.

An Example

For example, I ran two trading systems, one long and one short.

For the long trading system I saved the equity using the above formula as “~MY_EQUITY_long“.

For the short trading system I saved the equity as “~MY_EQUITY_short”.

Note: I could have chosen any name I wanted here such as “SYSTEM_A” or “MY_SYSTEM”, however, using ‘~’ at the beginning makes it easier to find the ticker in the symbol list.

equity symbol names in Amibroker. how to combine equity curves

Next, I opened up the formula editor and typed in the following code:

System1 = Foreign("~my_equity_long","Close");
System2 = Foreign("~my_equity_short","Close");

Combined = (System1 + System2) / 2;

Plot(System1,"System1",colorgreen,styleline);
Plot(System2,"System2",colorred,styleline);
Plot(Combined,"Combined",colorBlack,styleline);

This formula simply adds the equity of system one to the equity of system two and then divides them by two.

Hit Apply Indicator and the formula plots all three equity curves in Amibroker as below:

How to combine equity curves in Amibroker. two trading systems combined in Amibroker
How to combine equity curves in Amibroker. System one equity curve is in green, system two is in red and the combined system is in black.

As you can see, the black combined equity curve gives a lower return than system one but a smoother ride.

Now, to see the actual statistics of this combined system, all you have to do is run a buy-and-hold backtest on the two saved tickers.

To do this, I created a new watchlist called “Combined” and I added the tickers ~MY_EQUITY_long and ~MY_EQUITY_short.

select watchlist amibroker

Then I ran a simple buy and hold back-test on the new watchlist using another simple formula:

Buy = 1;
Sell = 0;

In the backtest settings I set the number of open positions to two and I made the initial capital large enough that we can afford to buy both tickers.

Note: You may need to play around with your initial capital so that you have enough equity to buy both tickers and you will need to tick the box in the back-tester settings that disables trade size when there is no volume – because our equity tickers have no volume stored.

Disable trade size limit

Now you can run the buy and hold back-test.

Make sure to split your starting capital equally between the two tickers (or however you want to allocate it) and the results will give a good representation of what would have happened if you had traded both of your two trading systems together.

So to recap, here are the steps to take to combine equity curves in Amibroker:

  1. Use the AddToComposite formula to save each equity curve to it’s own symbol
  2. Combine the two equity curves using the formula editor and plot on a chart
  3. Add the two equity curve symbols to a new watchlist
  4. Run a buy and hold strategy on the new watchlist

Option 2 – Export To Excel

Option 1 is a nice and simple way to combine equity curves in Amibroker that works most of the time.

However, I have had some problems with this method when dealing with complicated trading strategies or when back-testing on a very large number of securities.

If you run into this problem too, there is a simple solution by exporting each equity curve to Excel. You can then combine the equity curves in Excel or re-import them back into Amibroker and then run a buy and hold system as before.

Here are the steps to take for this route:

Step 1.

The first thing you’ll need to do is run your back-test and then export your quotes to a format that Excel will be able to read.

As I understand, there is no button that will do it all for you so the best thing to do is follow the steps listed on the AB website.

Basically, all you have to do is run an exploration on the equity ticker and export the quotes. So, after a back-test, open up the formula editor again and paste the following 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);

Click Tools > Send to Auto-Analysis and you will be ready to run this formula on any ticker you like.

Select the equity curve symbol “~~~EQUITY” then Click in the ‘Apply To‘ field and choose ‘current symbol‘ and choose range: all quotations or select the date range that you require.

Now hit Explore and Amibroker will deliver all the quotes as requested in the written formula above.

exploration of quotes amibroker
The exploration produces quotes for the date range you specify

At this point you can click File > Export CSV or you can right click on the results, select all, then copy and paste them into Excel.

Once you have exported the equity quotes to Excel you can move on to the second trading system and do the same thing.

Step 2.

At this point you should have two CSV files containing system equity for two trading systems.

The first thing to do is to rename the tickers so you don’t get the two mixed up.

equity quotes in excel

Now, you can either combine the two together in Excel or you can import them both back into Amibroker (as different tickers) using the import wizard.

Then you can add the two new tickers into a new watchlist and run a buy-and-hold test on the watchlist, just like in option one. You now have a way to see the results of combining trading systems together.

import wizard

 

DON'T MISS THIS


Filed Under: Amibroker, How to, Latest Tagged With: amibroker, latest

Recommended Educational Resources:

  • Discover New Trading Systems
  • Build A Trading Robot In Excel
  • Learn About Mental Models (Free)
  • Learn Python (Free)
  • Free Historical Data
  • Free Indicators For Amibroker

Reader Interactions

Comments

  1. Tom says

    February 4, 2017 at 1:00 am

    Both options are time-consuming and still don’t give a chance for optimal using of betsize based on combined equity.
    The problem is that such option of joining the systems should be built-in without neccessity of making such combinations as described by you (thank you anyway).

    Reply
    • JB Marwood says

      February 5, 2017 at 4:25 pm

      I know what you mean. It would be nice to push a button and have it all done for us. Maybe in future versions. Option 1 is pretty quick though, once you have the formula saved.

      Reply
  2. Tom says

    February 7, 2017 at 2:12 am

    It seems Tomasz Janeczko is very reluctant to add such option to Amibroker. At least I got such impression after reading Amibroker forum.

    Reply
    • JB Marwood says

      February 10, 2017 at 10:09 pm

      Yeah, well it’s up to him I guess.

      Reply
  3. Hardik says

    March 6, 2017 at 6:53 pm

    Hii JB,

    How do you allocate different percentages to systems. For example if I want to invest 70% in System 1 and 30 % in System 2 rather than 50/50 as shown in above example.

    Thanks.
    Hardik Upadhyay.

    Reply
    • JB Marwood says

      March 7, 2017 at 2:24 pm

      There is more than one solution.
      One way, something like:
      SystemA = Foreign(“SystemA”,”C”);
      Positionsize = IIf(SystemA,-70,-30);
      Another way, run the backtests individually – $7k in system A, $3k in system B (for 10k portfolio) then combine the curves.

      Reply

Leave a Reply Cancel reply

Your email address will not be published.

Primary Sidebar

Access Marwood Research image
Joe Marwood Profile PIc

DON'T MISS THIS


Popular

roadmap to successful financial trading

Zero To Hero: 5 Steps For Financial Trading Success

The more frequently you can trade your edge, the faster you can play out your expectancy and the quicker you can recover from any drawdown.

Ten Things System Traders Don’t Tell You

best moving average test on s&p 500

Which Is The Best Moving Average? Test Results Reveal The Truth

26 Stock Market Strategies, Anomalies And Edges

positions sizing with RSI 2 on spy equity curve

Using The RSI Technical Indicator For Dynamic Position Sizing

10 things that dont work trading stocks featured image

10 Things That Don’t Work Trading Stocks

The Tycoon Barbell from The Safe Investor

How To Limit Risk And Capture Upside With A Barbell Trading Strategy

Slide 3 Books

The 100 Best Trading And Investing Books Of All Time

Financial Disclaimer

Financial trading is risky and you can lose money. JB Marwood is not a registered investment advisor and nothing on this site is to be regarded as personalised investment advice. Past performance is not indicative of future results. Data errors and mistakes do occur. Please see the full disclaimer.

Search

Recommended Resources

  • Discover New Trading Systems
  • Build A Trading Robot In Excel
  • Learn About Mental Models (Free)
  • Learn Python (Free)
  • Free Historical Data
  • Free Indicators For Amibroker

Footer

About The Author

Joe Marwood is an independent trader and investor specialising in financial market analysis and trading systems. He worked as a professional futures trader for a trading firm in London and has a passion for building mechanical trading strategies. He has been in the market since 2008 and working with Amibroker since 2011.

Joe Marwood Profile PIc

Recent Posts

  • How To Trade Double Tops – Historical Analysis
  • These 3 Charts Pose Difficult Questions For Index Investors
  • 5 Questions You Must Ask Before You Start Trading
  • Testing 3 Divergence Trading Strategies On Stocks
  • How To 10x Your Momentum Returns
  • Why Professional Traders Don’t Use Stops
  • Mastering Amibroker AFL
  • RSI Or MFI – Which One Works Best?

Search

Tags

10ideas (1) Amibroker (82) Books (14) Commodities (5) Data (1) Economy (3) Forex (14) How to (46) Ideas (20) Interest (5) Intraday (17) Investing (47) Latest (23) Legends (11) Links (27) Lists (48) Me (5) News (2) Opinion (33) Picks (74) Psychology (6) Q&A (1) Rant (1) Reviews (9) Roadmap (1) Sports (3) Stocks (137) Strategies/ Systems (140) Technical Analysis (25) Tips (3) Tools (19) Top Posts (27) Trading (21) Traps (1) Trend Following (18) Update (27)

Privacy policy | Contact | Disclaimer | All Rights reserved. JB Marwood.