PureBytes Links
Trading Reference Links
|
Yes.
Once you enter the custom backtesting phase, the active symbol is ~~~Equity. Any arrays constructed for symbols during the signal generation phase are no longer accessible.
Mike
--- In amibroker@xxxxxxxxxxxxxxx, B S <bs2167@xxx> wrote:
>
> Mike-
> Â
> Thank you. I have been freezing up my machine for 30 minutes at a time trying to get the staticvarset() to work (never did). This does it. Thanks again.
> Â
> For my edification, could you tell me why the alternative below doesn't work? Is it that once the backtester begins, all arrays (other than signal arrays) are erased from memory?
> Â
> Vol = ATR(14);Â
> SetCustomBacktestProcif
> {
> Â Â Â bo = GetBacktesterObject();
> Â Â Â bo.Backtest(True);
> Â
> for(trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade())
> {
> Â Â Â entryBar = LastValue(ValueWhen(trade.EntryDateTime == DateTime(), BarIndex()));
> Â Â Â VolNum = Vol[entryBar];
> Â Â Â trade.AddCustomMetric("ATR",VolNum);
> }
> Â Â Â bo.ListTrades();
> }(Status("action") == actionPortfolio) ("");
>
>
>
>
> ________________________________
> From: Mike <sfclimbers@xxx>
> To: amibroker@xxxxxxxxxxxxxxx
> Sent: Wed, January 20, 2010 8:28:49 PM
> Subject: [amibroker] Re: CBT - trade.addcustommetric() - 13x slower - bad code/settings?
>
> Â
> For what it's worth, static arrays were introduced to the 32 bit version in 5.24.0 as seen here: http://www.amibroke r.com/devlog/ wp-content/ uploads/2009/ 03/readme5240. html If the feature is not yet available in the 64 bit version, creating a static variable for every bar of every symbol would probably be overkill. You could instead get greatly improved timings just by creating the ATR arrays once per symbol, as opposed to once per trade. For example;
>
> SetTradeDelays( 0, 0, 0, 0);
> PositionSize= -2;
>
> weekDay = DayOfWeek();
>
> Buy= weekDay == 1;
> BuyPrice= Open;
> Sell= weekDay == 5;
> SellPrice= Close;
>
> SetCustomBacktestPr oc( "");
>
> if( Status( "action") == actionPortfolio)
> {
> Â Â Â Â bo = GetBacktesterObject();
> Â Â Â Â bo.Backtest( True);
> Â Â Â Â dates = DateTime();
> Â Â Â Â bi = BarIndex();
>
> Â Â Â Â for( trade = bo.GetFirstTrade( ); trade; trade = bo.GetNextTrade( ) )
> Â Â Â Â {
> Â Â Â Â Â Â Â Â foreignATR = VarGet( trade.Symbol + "ATR");
> Â Â Â Â Â Â Â Â undefined = IIF( IsNull( foreignATR ), true, false);
>
> Â Â Â Â Â Â Â Â if( LastValue( undefined ) )
> Â Â Â Â Â Â Â Â {
> Â Â Â Â Â Â Â Â Â Â Â Â _TRACE( "Constructing ATR(14) for "+ trade.Symbol );
>
> Â Â Â Â Â Â Â Â Â Â Â Â SetForeign( trade.Symbol ) ;
> Â Â Â Â Â Â Â Â Â Â Â Â foreignATR = ATR( 14);
> Â Â Â Â Â Â Â Â Â Â Â Â VarSet( trade.Symbol + "ATR", foreignATR );
> Â Â Â Â Â Â Â Â Â Â Â Â RestorePriceArrays();
> Â Â Â Â Â Â Â Â }
>
> Â Â Â Â Â Â Â Â entryBar = LastValue( ValueWhen( trade.EntryDateTime == dates, bi ) );
> Â Â Â Â Â Â Â Â trade.AddCustomMetr ic( "Entry ATR", foreignATR[ entryBar] );
> Â Â Â Â }
>
> Â Â Â Â bo.ListTrades( );
> }
>
> Mike
>
> --- In amibroker@xxxxxxxxx ps.com, B S <bs2167@> wrote:
> >
> > Thanks Tomasz.� One stupid follow up question:� my understanding is that StaticVarSet will take only� a single number not an array, therefore do i need to create a loop outside the CBT from 0 to BarCount - 1 and create a static variable for every bar as follows?
> >
> > StaticVarSet( "MyAtr"+Name( )+BarIndex() , ATR(14) );
> >
> > ____________ _________ _________ __
> > From: Tomasz Janeczko groups@
> > To: amibroker@xxxxxxxxx ps.com
> > Sent: Wed, January 20, 2010 6:06:41 PM
> > Subject: Re: [amibroker] CBT - trade.addcustommetr ic() - 13x slower - bad code/settings?
> >
> > Ã?Â
> > Hello,
> >
> > Foreign is costly. Move your calculations OUTSIDE custom backtest part.
> > ATR can easily be calculated outside CBT and passed via Static variable.
> >
> > So instead of Foreign use Static variables. Store your ATR into static variables keyed with
> >
> > StaticVarSet( "MyAtr"+Name( ), ATR(14) );
> >
> > and inside custom backtester use StaticVarGet( "MyAtr"+trade. Symbol);
> >
> > Best regards,
> > Tomasz Janeczko
> > amibroker.com
> >
> > On 2010-01-20 23:39, B S wrote:
> > Hi-
> > >
> > >I have run into some major performance problems when trying to add a single simple metric to the backtest results.� I have no doubt that its something I'm doing, I just have no idea what that might be..� I have seen a post or two in the past on how to accomplish what I'm trying to do (as the examples below� will replicate), but there was no follow up on the performance of the proposed solutions.� Since there was no further discussion, I'm wondering if the code is fine but my settings (or something else) may be causing the problem.� Below I list what I believe to be all pertinent information - would very much appreciate any help on this.
> > >
> > >Base system is tested on 5 symbols, 5min data, from 1/1/2000 - 12/31/2006. Quick AFL is checked in the setting and data is padded andÃ? aligned.Ã? I'mÃ? running the 64bit version of AB 5.22.Ã?Â
> > >
> > >Performance without calling CBT : 65 secs
> > >
> > >------------ --------- --------- --------- --------- ---
> > >
> > >Performance with the code below added: 72 secs (very good)
> > >(code is from http://www.. amibroke r.org/userkb/ 2008/03/16/ amibroker- custom-backteste r-interface- 2/Ã? )Ã?Â
> > >SetCustomBacktestPr oc("");
> > >if (Status("action" ) == actionPortfolio)
> > >{
> > > bo = GetBacktesterObject (); // Get backtester object
> > > bo.Backtest( True); // Run backtests with no trade listing
> > > stat = bo.GetPerformanceSt ats(0); // Get Stats object for all trades
> > > winAvgProfit = stat.GetValue( "WinnersAvgProfi t");
> > > loseAvgLoss = stat.GetValue( "LosersAvgLoss" );
> > > for (trade = bo.GetFirstTrade( ); trade; trade = bo.GetNextTrade( ))
> > > { // Loop through all closed trades
> > > prof = trade..GetProfit( ); // Get trade profit in dollars
> > > relProf = 0; // This will be profit/avgProfit as %
> > > if (prof > 0) // If a winner (profit > 0)
> > > relProf = prof / winAvgProfit * 100; // Profit relative to average
> > > else // Else if a loser (profit <= 0)
> > > relProf = -prof / loseAvgLoss * 100; // Loss relative to average
> > > trade.AddCustomMetr ic("Rel Avg Profit%", relProf); // Add metric
> > > } // End of for loop over all trades
> > > bo.ListTrades( ); // Generate list of trades
> > >}
> > >------------ --------- --------- --------- --------- --------- --------- --------- --------- --------- ------
> > >Performance with the code below added to record ATR at entry: 854 secsSetCustomBackte stPr oc("");
> > >if(Status("action" ) == actionPortfolio)
> > >{
> > >bo = GetBacktesterObject ();
> > >bo.Backtest( True);
> > >dates = DateTime();
> > >bi = BarIndex();
> > >for(trade = bo.GetFirstTrade( ); trade; trade = bo.GetNextTrade( ))
> > >{
> > >SetForeign(trade. Symbol) ;
> > >entryBar = LastValue(ValueWhen (trade.EntryDate Tim e == dates, bi));
> > >foreignATR = ATR(14);
> > >trade.AddCustomMetr ic("Entry ATR",foreignATR[ entryBar] );
> > >RestorePriceArrays( );
> > >}
> > >bo.ListTrades( );
> > >}
> > >Anyone have any ideas where I may be going wrong?
> > >Ã?Â
> > >
> >
>
------------------------------------
**** 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:
amibroker-digest@xxxxxxxxxxxxxxx
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/
|