[amibroker] Custom Metric: Seen by backtest but not optimization

 

Hi All,


I'm testing some new code to which I've added a custom metric. I've been using custom metrics for a long time now, and this is the first time I've run into this sort of problem. I'm not sure what could be causing it.


Here's the situation. The metric is showing up in my backtest report just fine, but when I try to optimize using the metric as my objective function, the optimizer says it can't find the metric. It's NOT an issue of misspelling, as I've cut-and-pasted the string from the AddCustomMetric() function into the optimize box. What else could cause it? I've been scouring AmiBroker knowledge base for half the day now and haven't found mentions of any other causes.


Code is below, then screenshot. The metric is called ps and is returned in the second line after the conditional via a function called ParamStability(). It is then saved in a static variable and retrieved in the CBT. METHOD is a global constant. 


The same error shows up during optimization with or without the encapsulating status() conditional on the main formula.

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

if (Status("ActionEx") != actionPortfolio AND Status("ActionEx") != actionExOptimizePortfolio) {

ticker = Name();

ps = ParamStability(ticker, METHOD, GetFirstBarInRange(), GetLastBarInRange(), 8, 12, 95, 105);

Buy = Sell = Short = Cover = 0;

Buy = VarGet(ticker+"simBuy");

Sell = VarGet(ticker+"simSell");

Short = VarGet(ticker+"simShort");

Cover = VarGet(ticker+"simCover");

StaticVarSet("ps", ps);


_TRACE("Stability report. ParamStability: "+ps);

_TRACE("Avg CAR: "+VarGet(Name()+"PSCAR"));

_TRACE("Number of Trades: "+VarGet(Name()+"PSNumTrades"));

_TRACE("Portfolio Equity: "+VarGet(Name()+"PSPortEquity"));

_TRACE("Sortino: "+VarGet(Name()+"PSSortino"));

_TRACE("Distribution Adjusted Sortino: "+VarGet(Name()+"PSRiskPerf"));

_TRACE("WinPct: "+VarGet(Name()+"PSWinPCT"));

_TRACE("Avg Length of Trade: "+VarGet(Name()+"PSTradeLength"));

_TRACE("Std Dev of Trades: "+VarGet(Name()+"PSTradeStDev"));

_TRACE("==================================================");

}


SetCustomBacktestProc(""); 


/* Now custom-backtest procedure follows */ 


if( Status("action") == actionPortfolio OR Status("ActionEx") == actionExOptimizePortfolio ) 

 { 

    bo = GetBacktesterObject(); 


    bo.Backtest(); // run default backtest procedure 


    st = bo.GetPerformanceStats(0); // get stats for all trades 

    ps = StaticVarGet("ps");

     // Here we add custom metric to backtest report 

     bo.AddCustomMetric( "ParamStability", ps ); 

 }


Here is a screenshot of a completed backtest. You can see no errors and the ParamStability metric is showing up up with an accurate value in the backtest report:



Here is a screenshot of the entry to use ParamStability for Optimization. The name is spelled correctly (cut-and-pasted from the code):



And here's a screenshot of an attempt to do an optimization run, showing the error:




__._,_.___

Posted by: rosenberggregg@yahoo.com
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (1)
**** 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/


.

__,_._,___


EmoticonEmoticon