[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: testing multiple systems simultaneously



PureBytes Links

Trading Reference Links

Hi,

As I consider Tomasz is always right, I must admit I don't understand the question. Anyway, I try to give an answer to his questions at the end of this post.

I maintain "multiple-system portfolio backtesting where portfolios have more than one symbol" is an easy problem to solve. I'd like to add some precisions to my previous post :

>> step 2.1 : "backtesting each system independantly and storing all the issued Buy/Sell signals ..."
--> By hand (with current afl capabilities), this means : create a composite symbol for each signal and for each TS stored in a unique Watcklist (wl_<MTS>). For instance ~<TS>_<Symbol>. In my case, each bar is filled by :
  Close : Nop/buy/sell/short/cover (0/1/2/3/4)
  Open : BuyPrice/SellPrice/ShortPrice/CoverPrice
  High : PositionScore
  Low : PositionSize

Step 2.2 : "backtesting the stored signals ..."
--> BackTest watchlist wl_<MTS> with the following code :
buy = (C==1); 
sell = (C==2);
short = (C==3);
cover = (C==4);
BuyPrice=SellPrice=ShortPrice=CoverPrice = Open
//foreign() to be used to display, auto-trade in fact symbol 

You can directly complete this code to correctly manage Qtty (with PositionSize)and PositionScore operations (based on TsPositionScore and PositionScore - see previous post).
 
With an integrated solution, this code would be hidden (so not to be written by end-user like me) and automatically run by the "MultipleSystemBacktest" backtest mode. 

Tomasz, 
- "when to rebalance" : on each bar. Indeedevery buy/sell/short/cover signal of every TS are stored and used to make the Real MultipleTS backtest
- "howToRebalance" : thanks to the composite MtsPositionScore based on stored PositionScore (for each signal, at each bar) and on TsPositionScore defined in the AddSystem function (this is needed to ponderate TSs between them).

Important note : the method works because the Symbols'space is unique for each TS during step 2.2.
>From run time point of view, there are lots of improvements to make but this was not an issue for me.

Benoit

----MultipleTradingSystem afl code---
addSystem (..\TrendFollower\ts1_main.afl,1)
addSystem (..\MaCrossing\ts3_main.afl,2)
addSystem (..\Reverse\DDOptimized\ts2_main.afl,3)


----end of MultipleTradingSystem afl code---

--- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@xxx> wrote:
>
> As I wrote it is not technical problem but human problem.
> The problem of understanding.
> 
> You simply don't see that there is BIG difference between:
> 
> a) multiple-system on individual symbols
> which is currently possible and quite easy in fact
> and described back in 2006
> http://www.amibroker.com/kb/2006/09/29/how-to-set-individual-trading-rules-for-symbols-in-the-same-backtest/
> 
> b) multiple-system portfolio backtesting where portfolios have more than one symbol and
> possible overlap between symbols traded.
> 
> In this case you MUST resolve problem on *when* and *how* to rebalance positions between systems.
> Without that you would end up with trading only "winning" system after some time, because worse
> systems would run out of money. Why? Simply because if winning system does not go to the cash
> but opens other positions or reverses positions the other systems would not get the chance
> to use the cash from winning trades of the other system, because at the time when worse
> systems want to open positions, the cash from winning system would be allocated to the new
> trades of winning system, simply because entry/exit moments are (in most cases) not synchronized between systems.
> 
> Therefore one needs to have a method of reallocating equity to restore original allocation percentages
> between symbols. The simplest method to do is to rebalance periodically. For example quarterly.
> You can close all open positions quarterly and then re-open them with corrected position sizes
> to reflect ideal (desired) balance between systems.
> 
> But that is just one (simplest) method of doing rebalancing different system portfolios.
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> ----- Original Message ----- 
> From: "benoitek1" <benoit.marchand@xxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Thursday, May 07, 2009 12:00 PM
> Subject: [amibroker] Re: testing multiple systems simultaneously
> 
> 
> > Hi all,
> >
> > I also do believe that this question is easy to deal with. I do believe that because I (badly) did it as I showed in a previous 
> > post (http://finance.groups.yahoo.com/group/amibroker/message/137900).
> >
> > An integrated solution made by Tomasz could consist in :
> >
> > 1. adding an afl function "addSystem (<ts_afl_main_file>,TsPositionScore)" to add all the independant Trading System (TS) to make 
> > THE Multiple Trading System. The TsPositionScore is a global PositionScore attached to each TS. I attached an associated afl 
> > sample below.
> >
> > 2. adding a MultipleSystemBacktest which would consist in :
> > 2.1 backtesting each system independantly and storing all the issued Buy/Sell signals (rather than the trades themselves) with 
> > their associated Buy/SellPrice and their PositionScore as coded in the TS.
> > 2.2 backtesting the stored signals using as PositionScore a composite PositionScore (MtsPositionScore) based on the TS 
> > PositionScore (the one you know) and the TsPositionScore (the one globally attached to TS)
> >
> > I feel like Tomasz is almost ready to go ahead :-). Could we all of us try to converge to completly convince him ? (ie could we 
> > all of us discuss on a concrete implementation rather than philosophiing on the concept - which is very nice sometimes but also 
> > slows down the execution some other times)
> >
> > ----MultipleTradingSystem afl code---
> > addSystem (..\TrendFollower\ts1_main.afl,1)
> > addSystem (..\MaCrossing\ts3_main.afl,2)
> > addSystem (..\Reverse\DDOptimized\ts2_main.afl,3)
> > ----end of MultipleTradingSystem afl code---
> >
> > To be complete on what I've done, I did not find THE optimized equation to generate the MtsPositionScore. But I'm sure this is 
> > just due to my personal limitations ;-)
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "Paolo Cavatore" <pcavatore@> wrote:
> >>
> >> First of all I'd like to say this discussion is very interesting and a key point according to me.
> >>
> >> Secondly I do believe the issue is much easier than what many are suggesting.
> >> Multiple Systems testing should be considered with the same logic that Portfolio backtesting is using with underlying securities.
> >> Therefore I believe a new AB feature would be required. This feature should ask the user which AFL systems combine and then the 
> >> user can simply use standard Portfolio functions like:
> >> -PositionSize (this would take care of Sizing each position and could be tied up to each single system)
> >> -PositionScore (this would take care of multiple signals coming from different systems)
> >> -MaxOpenPositions (to avoid having several open positions due to different systems giving a signal at the same time)
> >>
> >> Furthermore I fully agree with ang_60 that when you use just "one equity pool", you don't assigne X% of capital to system A and 
> >> Y% of capital to System B: so, there's no need to rebalance anything.
> >>
> >> I cannot imagine anything easier than that and there wouldn't be any need to rebalance actually.
> >>
> >> paolo
> >>
> >> --- In amibroker@xxxxxxxxxxxxxxx, "ang_60" <ima_cons@> wrote:
> >> >
> >> > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@> wrote:
> >> > >
> >> > > Hello,
> >> > >
> >> > > The main problem is not technical but "human" - i.e. I guess that everyone
> >> > > that would be interested, would like to have rebalancing implemented differently.
> >> > > The devil is always in the details.
> >> > >
> >> > > So, let us discuss *your* preference. Let assume the following:
> >> > >
> >> > > a) we have 2 systems, and initially system A gets 60% of initial equity
> >> > > and system B gets 40% of initial equity
> >> > >
> >> >
> >> >
> >> > Hi everybody,
> >> >
> >> > maybe it's just me but I think this is a great discussion.
> >> >
> >> > Just some thoughts:
> >> >
> >> > 1) when you use just "one equity pool", you don't assigne X% of capital to system A and Y% of capital to System B: so, there's 
> >> > no need to rebalance anything.
> >> >
> >> > You start applying position sizing rules to your entire capital as soon as Sistem A, B, .... N gives you a signal.
> >> >
> >> > You need to rebalance only when you start dividing your trading capital from the N system which - I concur wuth Hicks - is a 
> >> > less efficient way to use your money (providing both your systems have positive expectation)
> >> >
> >> > 2) That's the very same reason you cannot simply add N equity curve to do portfolio testing.... because when mixing in one 
> >> > account (as in the real life) signal from system A and system B AND increasing trading size with the closed profits, it's 
> >> > mandatory to take into account the chronological order of the combined series of trades.
> >> >
> >> > 3) Hicks, I'm pretty sure Graham can do it (provided you don't want to run system A on database A and System B on database 
> >> > B.... ).... but if you are a bit like me (I'm not a programmer turned trader..... I'm an investor that thinks his daytime is 
> >> > better spent when I'm not programming.... ) maybe you will find his code a little complicated, would any further manipulation 
> >> > be needed from you.
> >> >
> >>
> >
> >
> >
> >
> > ------------------------------------
> >
> > **** IMPORTANT PLEASE READ ****
> > This group is for the discussion between users only.
> > This is *NOT* technical support channel.
> >
> > TO GET TECHNICAL SUPPORT send an e-mail directly to
> > SUPPORT {at} amibroker.com
> >
> > TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
> > http://www.amibroker.com/feedback/
> > (submissions sent via other channels won't be considered)
> >
> > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> > http://www.amibroker.com/devlog/
> >
> > Yahoo! Groups Links
> >
> >
> >
>




------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/