[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] How is the AB UPI calculated?



PureBytes Links

Trading Reference Links

Hi Herman
I think this calculates the UPI correctly for a single symbol test. In
this case it is over 5 years (1260 bars)

bi = BarIndex();
BarsPerYear = 252;
bars = 1260;
TresuryNotesProfit = 5.4;
eq = C;
Heq = HighestSince( bi == (BarCount-bars), eq );
DD = (Heq-eq)/Heq;
UI5 = sqrt(Sum( DD^2/bars, bars));
UPI5 = ( 100*(eq/Ref(eq,-bars)-1)^(BarsPerYear/bars) -
TresuryNotesProfit ) / UI5;


-- 
Cheers
Graham Kav
AFL Writing Service
http://www.aflwriting.com


2008/4/24 Herman <psytek@xxxxxxxx>:
>
>
>
> 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
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:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto: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/