Backtest of portfolio

Hi, i´m starting using AMiBroker for backtesting several strategies, so may be my question is alredy answered although i haven´t read something similar at the forum.
I have some issues when making backtest of a portfolio. The Portfolio backtest Profit Net and % result is totally different from the sum of each backtest made with the Individual Backtest option. So, I can obtain -5000$ on the Portfolio, but the sum of the result backtest of the components is +7000$.
I supposed the portfolio backtest strategy summary was a sum of the results of applying same strategy to inididual stocks included on this portfolio. What is wrong? I have raised without results Max Open Positions to 100, even i don´t have more than 10-12 concurrent trades on the whole portfolio .

Thanks.

1 Like

Ok I see the problem may be on the position size of the trades. But if i assign 10% of capital to 10 stocks, the sum of results should be the same of 100% of capital assigned to the Portfolio of these 10 stocks. Still results are very different...

No, they are not the same thing. You are comparing apples to oranges, basket backtesting to true portfolio backtesting.

This has been asked here already
http://ask.amibroker.org/index.php?qa=134&qa_1=portfolio-backtest-positive-individual-backtest-negative

So as written there just read the manual.

Hi fxshrat, thanks for your help.
I knew this entry of the guide and read a couple of times. But once i get the correct Pos. size over every stock assigned, i thought the results was comparable. If i win 1000$ on Coke and lose 300$ on BA, the profit of my Portfolio is 700$, same as the sum of the parts. Maybe i´m still losing something and refering to basket backtesting..so how can i do that?

In portfolio mode you are not trading a single symbol at time but multiple symbols. So you have to take into account things such as available cash, number of positions, position score, money management, ...

When you run individual backtest then you run single symbol at a time to be taken care of only.

So don't you understand that in a portfolio backtest a symbol that has had trades in individual backtest may not have had same trades in portfolio because of over symbols having being opened and having influence there and based on all circumstances some symbols are prevented from getting traded at same time or at all (e.g. because of running out of cash, or symbols with better score etc). So you simply end up with different trades and results.... because it simply is apples vs. oranges.

1 Like

Hi Everyone,

Just i finished my system and i'm runing the backtest, but if i run several times the result always is different the net profit. The different is small but different.

Some times it is happen, but i don't know why. Some one have happened the same?

Best

Thx Fxshrat for the explanation.
I understand it, but i also think if you assign, in an hypotetical scenario, same cash for whole portfolio than sum of cash in every stock assigned, and positions of portfolio equal or higher to sum of all position in every stock the result must be the same. Timing is not an issue as my strategy is daily based and signals are not frequent, so there are no concurrent trades on the stocks of the basket.
I´m just trying to optimize my strategy on several basquets instead of individual stocks, and by the way to avoid overoptimize to any particular case. So although i´m looking for the basket profit, i need same results on every stock of the basket than on every individual analysys. Some advice?

Best,

Consider a very simple scenario where you only have two trades, A and B. Each is allocated 10% of your $100,000 initial equity.

  1. In case #1, the symbols are tested independently, so each trade uses $10,000. If they each gain 10%, then the two trades each exit for $11,000, so now you have $2,000 profit.

  2. In case #2, the symbols are tested as a portfolio. Trade A uses $10,000 for entry, and generates a $1,000 profit. Now your equity is $101,000. Trade B uses 10,100 for entry and generates a profit of $1,010. Your total profits are now $2010.

There are lots of other reasons that your performance metrics may vary, but this is one example. The easiest way to see what's going on is to start comparing the individual trade lists for the single symbol vs. portfolio backtests. You will quickly see differences in position sizing, trades taken, etc.

1 Like

Hi mrtrade, yes you are right and of course i´m considering the allocation. On this scenario the difference between results of sum of Individual Backtest and results of Portfolio Backtest is right, but marginal and not an issue for me: 2000$ vs 2010$. My watchlists for portfolio backtesting are not big, 10 symbols each. and capital and size are right allocated but the diffrences are huge: 29.899$ (sum of Indiv Backt) Vs -6.441(Portfolio Backt).
Anyways, now the only way i know to do that right is doing Backtesting of my watchlist in Individual Backtest Summary mode and export to excel the results for obtaining the True profit of the whole basket as i need.
I think it would be nice to have that result also in AmiBroker.

@robx even if you're not experiencing the particular scenario I described, the answer is the same: compare the trade lists, find the differences, and then review your code until you can explain WHY the differences are occurring. AmiBroker is certainly more than capable of reporting the "true profit of the whole basket"... that's the entire point of running a portfolio test. If you're getting results that are incorrect, it's because you're making a mistake, not because the platform is lacking.

2 Likes

@Robx,
Allow me to jump in here even though I'm a relative newbie; it seems you're trying to make AmiBroker conform to your own programming style rather than adapting your style to fit AmiBroker. You need to learn it like a new language.

You may use programming techniques from your background but you must learn how to "say them" in AFL.

Start here:
https://www.amibroker.com/guide/tutorial.html
https://www.amibroker.com/guide/h_understandafl.html

Thank you guys, i´ll try to solve this following your advice.
Best,

Sir fxshrat, are you able to provide an updated link to your reply of March 2019?

With highest regards, Coltrane153