Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

How to do Portfolio Backtesting in Amibroker

1 min read

Portfolio Trading (Trading with Multiple Stocks/Instruments) is the next big step in a traders life once he understand that he want to reduce the volatility in his trading strategy. And Amibroker comes handly when comes to portfolio back-testing. And this tutorial explains how to do portfolio back-testing step by step.

Steps
1) Create Watchlist in Amibroker. Watchlist is basically a list of stocks you would like to monitor or test. In this example i had added NIFTY-I and BANKNIFTY-I in the watchlist. You can add your own list of symbols you are willing to test

2)Goto New Analysis->Backtester Settings -> And Set the Periodicity of your choice. In my case i set as 5min

backtesting Settings

 
3)And Select the Apply to dropdown as Filter and Select the required watchlist in the Filter Settings.

4)Now add the Backtesting Template to your AFL code to the beginning of your trading system. Sample Back-testing template shown below. Which used to take 4 lots of Nifty and 2 lots of Bank Nifty every time. The Brokerage Commission amount has to be set as per your brokerage plan. Here in this example i had taken a per leg commissions (includes brokerage, taxes, slippages) of Rs150 for 4 lots of Nifty and Rs150 for 2 lots of Bank Nifty. And here i assumed per order brokerage for deciding the per leg commisision rates.

5)Set the Margin required in the template provided below as per your brokers margin.

6)Set the Maxopenposition as per the number of symbols you are willing to backtest. As Iam backtesting Nifty and Bank Nifty Futures in my case it is 2
https://gist.github.com/bdaae28ba52c17b68372

7)goto Symbols->Information and set the Contract Specification as shown below

Parameters Nifty Bank Nifty
Round Lot Size 25 25
Margin Deposit -10 -10
Point Value 1 1

8)Now Press the Backtest Button to get the Backtesting report.

Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

What is QuantZilla?

Quantzilla is 75+ hours of code mentoring program designed for noncoders who want to learn the coding program right from designing indicators, scanners, trading...
Rajandran R
58 sec read

Things to Consider While Building a Bracket Order Execution…

Building a Bracket Order Strategy is the most demanded request we got from most of the algomojo traders. This article explains the list of...
Rajandran R
12 min read

PlaceOrder – Multi Broker Exectuion Code Snippets for Amibroker

This tutorial explains how to build a button trading right from scratch and with a click of a button how you can send orders...
Rajandran R
7 min read

14 Replies to “How to do Portfolio Backtesting in Amibroker”

  1. sir good backtest result. good job. இந்த சப்ஜெக்டை தமிழில் நீங்கள் எழுதியிருந்தால் ஷேர் மார்க்கெட் துறையில் ஈடுபட்டு கொண்டிருக்கும் என்னை போன்றவர்களுக்கு மிகவும் பயனுள்ளதாக இருக்கும். . விரைவில் உங்கள் தமிழ் தளத்தை மிகவும் ஆவலுடன் எதிர்பார்க்கிறேன்.. நன்றி.

  2. Dear sir,

    Can u help me how to do position sizing on % basis, add more lots when capital increases and decrease when capital comes down, how to write afl and back test the same for our strategy.

    would be great help

  3. i had added NIFTY and BANKNIFTY ( spot )in the watchlist. i take the backtes as per your instruction. but result is different. that is showing contract and position price is different. but i had added NIFTY-I and BANKNIFTY-I in the watchlist the backtest result is good. another one point i follow 1 min. time frame. but i couldnt i min. setting in periodicity box. why.?

    1. If you need to change the symbols you need to change at code level. And you have to set the Symbol information (lot size and margin details as explained above)

  4. sir one kind help,

    I have set all as u said, its working fine for equity futures but when i change into commodity like lead and i changed in the code itself in afl, plus symbol information lot size 5000, then i could not get result as i get in nifty and bank nifty–equity futures.

    shares traded shown in different size for every trade…4,00,000 only kept capital, margin set as u given only, still i didn’t get, what could be the problem?

  5. I have a formula which shows backtest results of a single symbol only once in the selected timeline. Whereas when I change the symbols option to “current” then it shows multiple trades in the desired time frame on the same symbol. How to have multiple trades of a single symbol while bactesting all symbols in the trade list?

  6. Hi Rajendran, had a query in amibroker, if I am testing a strategy on say a watchlist with say 100+ names and I run a portfolio backtest specifying the position size and max number of open positions. But am not using any ranking (positionscore). In that case how does Amibroker pick the stocks if more than max are meeting the criteria?

    Let me also take this opportunity to thank you for your regular efforts with this website!! It has been very informative and extremely helpful. Thanks again

  7. Hi Rajendran,

    Your site is very useful!

    I am facing some problem in backtesting with nifty future intraday data. I have placed the backtesting code (EMA cross formula which is mentioned in your site). Amibroker is showing zero for all the backtesting results like Profit =0. CAR = 0 etc., Please guide me on how to backtest properly.

    Thanks,
    Sreenath

  8. Hello Rajandran.
    I need to backtest more than three strategy at a time, how can i do that in amybroker?

Leave a Reply to Rajandran R Cancel reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More