Get optimisation results and calculate percentage of profitable combination

The picture below shows a table of optimisation results.

OptimisationResults

From the "Net % Profit" column, I would like to calculate the percentage of positive "Net % profit". For this table, there are 8 rows with positive "Net % profit". There are 24 rows in total. So, percentage of positive "Net % profit" would be 8/24=33%.

Is it possible to use AFL to extract out the "Net % profit" of each row of the optimisation results? Any other method of extracting this information to calculate the percentage is welcomed.

I am using Amibroker ver6.28.0

I am looking for similar function too. Does anyone have idea?

You have to do it via CBT to get performance stats.

Here is solution:

/// @link https://forum.amibroker.com/t/get-optimisation-results-and-calculate-percentage-of-profitable-combination/6980/3
/// by fxshrat@gmail.com
if (Status("actionex") == actionExOptimizeSetup) {
	StaticVarRemove("CBT_*");
}
SetCustomBacktestProc( "" );  
if ( Status( "action" ) == actionPortfolio ) {
	bo = GetBacktesterObject();
	bo.Backtest(); // run default backtest procedure 
	stats = bo.GetPerformanceStats(0);	
	metric = stats.GetValue("NetProfit");
	metric_check = metric > 0;
	get = Nz(StaticVarGet( "CBT_StatsCheck"))+metric_check;
	if ( Status("actionex") == actionExOptimizePortfolio ) {		
		StaticVarSet("CBT_StatsCheck", get);
		StaticVarSet("CBT_Count", Nz(StaticVarGet("CBT_Count"))+1);
		_TRACE("Optimize Step: TRUE");
    }
}

if (Status("actionex") == actionExOptimizePortfolio)  {
	num_greater_zero = StaticVarGet("CBT_StatsCheck");
	cnt = StaticVarGet("CBT_Count");
	rate = num_greater_zero/cnt*100;
	_TRACEF("NetProfit greater zero: %g",num_greater_zero);
	_TRACEF("Number of steps: %g", cnt);
	_TRACEF("NetProfit positive steps rate: %1.2f%%", rate);
}

// Dummy system start
SetPositionSize(1, spsShares);
per = Optimize("per", 20, 5, 20, 1);
m = MA( Close, per );
Buy = Cross( Close, m ); 
Sell = Cross( m, Close ); 
Short = Cover = 0;
// Dummy system end

In example result below...
after optimization finish 15 out of 16 steps had positive NetProfit result (93...%).

26

12 Likes