Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

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

[wp_ad_camp_5]

 
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 Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

[Live Coding Webinar] Build Your First Trading Bridge for…

In this course, you will be learning to build your own trading bridge using Python. This 60-minute session is perfect for traders, Python enthusiasts,...
Rajandran R
1 min read

[Webinar] Understanding and Mitigating Curve Fitting in System Trading

"Understanding and Mitigating Curve Fitting in System Trading"! This dynamic session aims to equip novice to intermediate traders, quantitative analysts, and financial engineers with...
Rajandran R
1 min read

P-Signal Strategy Long Only Strategy – Amibroker AFL Code

This tutorial provides an overview of the P-Signal reversal strategy, a quantitative trading strategy that utilizes statistical parameters and error functions to generate probabilistic...
Rajandran R
2 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

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