I do have a top-end portfolio backtesting question and would like to understand how much or how Amibroker could help with this objective.
Requirement: I do have 2 (or more) strategies coded in two different AFL files and would like to backtest these two strategies and generate 1 equity curve and 1 set of statistics, i.e. CAR/MDD. Also I would like to have portfolio backtesting results on a trade by trade basis for both of the systems on the same “Analyses” tab. I mentioned 2 systems as an example but the suggested solution should be able to cope with 5 systems or more too.
Currently, as a short cut, I am able to run these systems individually and compare the results, make correlation analyses etc but as I mentioned above what really I am after is complete integration of backtesting and optimization capability for 2 or more systems at the same time.
I would be most appreciate for any suggestions, solutions.
Yes, it can be done. One thing you’ll need to manage is what happens when you have entry signals from multiple systems on the same bar but not enough capital to take all of them.
Here’s an code example that demonstrates the sort of thing you’re after, and uses
PositionScore as a way of prioritising the signals. http://www.amibroker.com/members/library/detail.php?id=1227
In addition to Alan's User Library link you may want to take a look at these links.
This link needs registration, or we can ask fxshrat to post his codes here.
Similar ideas from the old forum,
This is also noted and much appreciated.
@portfoliobuilder I can’t access any of the links.
Do you or @fxshrat or anyone have these mentioned codes?
Nick I think you can register for fxshrat’s user group. (that link doesn’t seem to be working for me either?). If you can’t then get back to me and I will send a couple of codes I have saved but don’t have the forum posts or discussions that may explain them.
Similarly the old forum post, I was able to copy a code but the discussions around the topic might be able to explain what the code was intended to do.
This first one was intended to backtest multiple systems from one code I think.
// From Aron at that link
n = Optimize( "system", 0, 0, 2, 1 );
PositionSize = 10000;
SetOption( "holdminbars", 1 );
Buy = Sell = Short = Cover = 0;
switch( n )
case 0 :
Buy = 1;
case 1 :
Short = Cover = 1;
Buy = Sell = 1;
SetCustomBacktestProc( "" );
/* Custom-backtest procedure follows */
if( Status( "action" ) == actionPortfolio )
bo = GetBacktesterObject();
bo.Backtest(); // run default backtest procedure
StaticVarSet( "system" + n, bo.EquityArray() );
for( i = 0; i < 3 ; i ++ )
e = StaticVarGet( "system" + i ) ;
clr = ColorHSB( 240 / 3 * i , 200, 200 );
Plot( e, "\n" + EncodeColor( clr ) + "system" + i , clr );
This next one was later in the same thread about testing multiple signals on the same instrument I believe.
// combining multiple signals for entires/exits by Aron on the old forum
entries = 0 ;
exits = 0;
for( i = 0; i < 10 ; i ++ )
// trading system
buy = mtRandomA() < 0.3 ;
sell = mtRandomA() < 0.1;
Equity( 1, 0 );
entries += Buy ;
exits += Sell ;
// visualise signals
Filter = 1 ;
AddColumn( entries , "entries" );
AddColumn( exits, "exits" ) ;
Tomasz you closed my topic and sent me here. But I find no answers here. I had already read this topic and I fail to see how can I use this topic to backtest a multisystem sharing the same capital and max position. Maybe its not difficult for you but for me it is. If I was a great programmer with plenty of time I would be backtesting in python using my own backtesting environment. So I need some help.
I need a practical example on how to backtest several different systems with different exits and all sharing the same capital and max position. Please help me.
Practical examples are already included in the links I given plus this:
Backtesting multiple systems with different parameters and Different exits
If you can't program, hire someone who can: Third party services, blogs, courses, books, add-ons
I can program well enough, thank you. I am a professional trader and amibroker helped me a lot getting there. But its not perfect. Having backtesting results for multisystems should be as easy as picking the systems you want to share the capital and creating some simple money management rules. Tradestation can do this and so can others You obviously dont think this is important when in fact its one of the most important things for sistematic trading there is.
The example in "different exits" was useful, thank you. All others are not useful. Now lets say I want 2 systems to share 50% of the capital and 5 other systems to share the other 50%, so 2 pools of capital. The systems that get the buy first get the 50%. Its getting messier right? Yes its possible using the loop and the case, I can see that now. But its not easy and you can make a lot of mistakes. It should be very simple and easy and give flexibility to change money management rules and systems used fast.
just my feedback
AmiBroker can do ALL the things that Tradestation can PLUS zillions of others. And Tradestation has only SINGLE SECURITY backtester. TS does not even have true portfolio-level backtesting so TS backtesting is very limited. AmiBroker is in different league, orders of magnitude better and provides features and speed not available anywhere else.
In fact Tradestation guys wanted to buy AmiBroker's technology for lots of $$$ but we said NO, because we cared about our customers and did not want them to leave them dead in the water. So you don't know what you are talking about, if you think TS is any better.
It is extremely frustrating for software creator to hear such nonsense considering the fact what I did for customers. It would be way easier to cash out huge pile of $$$ and go away but I cared about PEOPLE not about myself. Every unfair/nonsense complaint that I hear is just another example of "no good deed goes ever unpunished".
Interesting information Tomasz. I guess Tradestation guys are smarter than I initially thought. Now, as for the second part of your post, firstly I would like to thank you for your approach. In the times we live, dominated by $$$ your standing should recognised by the community and I think it is. Secondly, I would recommend to take opinions of some random guys with a grain of salt. That @gueco guy obviously does not know what he is talking about (him and many others over here and on other forum boards) thus why would you care about his opinion ?
First of all I love amibroker. If i didnt why would I even be here. I can buy any other software package.
But wouldnt it be nice for multisystem backtesting to be easy with amibroker ? Imagine I want a system to be able to leave the position in the same bar but I dont want another to do the same. Its not that easy right now to backtest them together, ok? And I have 100s of systems that I need to test together in an easy and fast manner just like amibroker always did for me.
Tradestation now has Portfolio Maestro that can backtest multisystems and portfolios. But I am not saying its better. All I am saying is that to be able to easily test multi-system is important and some other software packages already do that. And ff I did not love amibroker why would I even bother coming here about this.