Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

The nonparametric performance measure (ACC) for Amibroker (AFL)

Copy & Paste Friendly
/*
The nonparametric performance measure (ACC) described by Guy Brys AND Luc Van Hof in 
"A Nonparametric Performance Measure" in this issue could be used to evaluate the 
performance of any trading system.

Calculating ACC involves ranking AND sorting daily MAE AND PAE figures. These tasks 
could be relatively easily implemented in AmiBroker using JScript embedded in the 
native AFL formula. In the sample code given here, we calculate the ACC of a simple 
directional movement indicator system, but as the authors mention in the article, 
the ACC measure can be applied to any system.

One interesting point to note about this implementation is that it uses JScript's 
built-in sort function with custom callback to sort by absolute value of the 
difference between the PAE AND MAE figures. 
*/

// The trading system for which we want
// to calculate nonparametric performance measure
// here as an example ADX system
pr = Optimize( "pr", 25, 5, 50, 1 );
Buy = ADX(pr) > 10 AND Cross( PDI(pr), MDI(pr) );
Sell = Cross( MDI(pr), PDI(pr) );
Short = ADX(pr) > 10 AND Cross( MDI(pr), PDI(pr) );
Cover = Cross( PDI(pr), MDI(pr) );
// MAIN PART:
// Calculation of Nonparametric
// Performance Measure
//
// First we calculate Equity
e = Equity( 1 );
Entry = Buy OR Short;
// ... and excursion (the difference between current equity
// and value of equity at entry
Excursion = e - ValueWhen( Entry, e );
// determine start and end intraday bar of the day
StartOfDay = DateNum() != Ref( DateNum(), -1 );
EndOfDay = Ref( StartOfDay, 1 );
//
// calculate daily maximum MAE, PAE and DAE
MAE = HighestSince( StartOfDay, Max( -Excursion, 0 ) );
PAE = HighestSince( StartOfDay, Max( Excursion, 0 ) );
DAE = PAE - MAE;
// number of days that intraday data span
NumDays = LastValue( Cum( EndOfDay ) );
EnableScript("JScript");
<%
// compare function for JScript sort
// we will be sorting by absolute value
function CmpFun( x, y )
{
  return Math.abs(x) - Math.abs(y);
}
// get variables from AFL part
NumDays = AFL("NumDays");
DAE = VBArray( AFL("DAE") ).toArray();
EndOfDay = VBArray( AFL("EndOfDay") ).toArray();
// now we build small array
// from DAE values at the end of day
//
nday = 0;
SortedDAE = new Array();
for( i = 0; i < DAE.length; i++ )
 if( EndOfDay[ i ] == 1 ) SortedDAE[ nday++ ] = DAE[ i ];
// sort the array by absolute value of DAE
SortedDAE.sort( CmpFun );
// after sorting RAE is simply array index + 1
// SAE is index + 1 with appropriate sign depending on DAE value
// but for ACC we just sum only positve SAEs
SumSAE = 0; SumRAE = 0;
for( i = 0; i < nday; i++ )
{
   RAE = i + 1;
   SumRAE += RAE;
   if( SortedDAE[ i ] >= 0 ) SumSAE += RAE;
}
AFL("ACC") = SumRAE > 0 ? 1 - (SumSAE/SumRAE) : 0;
%>
// now ACC variable holds nonparametric performance estimator
// Exploration code
Filter = Status("LastBarInRange") OR EndOfDay;
AddColumn(MAE,"MAE");
AddColumn(PAE,"PAE");
AddColumn(DAE,"DAE");
AddColumn(abs(DAE),"AbsDAE");
AddColumn(ACC, "ACC-Nonparametric Performance Estimator" );
Back