I have written a custom UPI function which needs, in my application, to give identical results as I get in the Backtester. I copied the test code below, if you want to run it copy it to the AA, run a Backtest to see AB UPI values, run an explore to see the UPI function value.s
I have been struggling with this; can anyone see why my function doesn't match the Backtester values? How nice if we had AFL functions for all the BT stats to apply on other arrays...(of course without having to run any Backtester)
btw,
1) how does the test period figure in the AB UPI? Is it based on a fixed yearly period or is it corrected for the test period?
2) If it is based on a yearly period.... how can this be used for shorter test periods?
many thanks for any help you can give,
herman
/////////////////////////////////////// custom UPI ////////////////////////////////////
function CustomUPI( EquityArray, NumberOfBars )
{
InitialEquity = GetOption( "InitialEquity" );
NumOfPeriods = 100;
MaxValue = SumSq = UI = MV = SS = 0;
PercentProfit = ( LastValue( EquityArray ) - InitialEquity ) / InitialEquity * 100;
for ( b = BarCount - NumberOfBars - 1; b < BarCount; b++ )
{
MV[b] = MV[b-1];
SS[b] = SS[b-1];
if ( EquityArray[b] > MaxValue )
{
MaxValue = EquityArray[b];
MV[b] = MaxValue; // test
}
else
{
SumSq = SumSq + ( 100 * ( EquityArray[b] / MaxValue - 1 ) ) ^ 2;
SS[b] = SumSq; // test
}
UI[b] = sqrt( SumSq / NumberOfBars );
}
Plot( MV, "MaxValue", 5, 1 );
Plot( SS, "SumSq", 4, 1 );
return (PercentProfit-5.4)/UI;
}
Firstbar = Status( "FirstBarInTest" );
NumberBars = LastValue( BarsSince( FirstBar ) );
BuyPrice = SellPrice = ShortPrice = CoverPrice = C;
SetTradeDelays( 0, 0, 0, 0 );
Buy = Cross( MACD(), Signal() ); // test system
Sell = Cross( Signal(), MACD() );
Short = Sell;
Cover = Buy;
E = Nz( Equity() );
UPI = CustomUPI( E, NumberBars );
GraphXSpace = 20;
Plot( e, "", 2, styleLeftAxisScale );
Plot( UPI, "UI", 6, 1 );
Filter = Status( "LastbarInTest" );
SetOption( "NoDefaultColumns", False );
AddColumn( UPI, "cUPI",1.2 );
//////////////////////////////////////////////////////////////////////////////////
__._,_.___
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
__,_._,___
|