PureBytes Links
Trading Reference Links
|
I was playing around with this for grins and think that you may want
to ask Tomasz about the function of Percentile(). It isn't doing
what I would have expected.
First, you can make your code run by using the following line in
place of the original -
x[i]=LastValue(Percentile( ROC260, count-1, y[i] ));
I don't think that this is going to end up doing what you want,
though. To me, it looks like the Percentile() function finds the
percentile rank in the PREVIOUS "N" tick period. When count is used,
it is referencing before the first value.
To see this, look at the following exploration -
Data = Null;
Data[BarCount-1] = 500;
Data[BarCount-2] = 40;
Data[BarCount-3] = 100;
X = Percentile(Data, 2, 100);
Filter = Status("lastbarinrange");
AddColumn(BarIndex(), "BARINDEX", 5.0);
AddColumn(x, "X", 5.0);
I'd expect X to equal 500. Instead, it equals 100. if you set the
rank to 50, the Percentile() function yields 70 (halfway between 40
and 100. You can also see the issue by setting the period to 3 - the
last value of X will be Null.
-- Bruce R.
--- In amibroker@xxxxxxxxxxxxxxx, "acesheet" <acesheet@xxxx> wrote:
> Folks,
>
> Can someone explain to me why the series '~xroc' is always zeros.
> What this script does is to assemble all the 1 year rate of changes
> of a watchlist into one variable called ROC260. The ROC data is
> shifted forward so that the most recent times record the ROC data
> (i.e. rather than near index 0 , it goes back from index BarCount-
1).
>
> I'd then like to determine the ROC's fitting into the 1%, 10%,
> 20%...90%, 99% ranks based on this data. This is what the
>
> The variable 'count' stores the actual length of data from the
Group
> list being surveyed. This becomes the period for the Percentile
> function.
>
> The variable 'y' is the rank that is being sought. It records via
> AddToComposite without a problem, even at index 0 (or the first
> point). For some reason I can't record '~xroc' or it comes up with
> zeroes via some other error.
>
> Anyone have an idea of why I can't record ~xroc? I'm pulling my
hair
> out right now over this one. I don't want to go bald.
>
> Thanks.
>
> -ace
>
> //-----------------------------------------------------------
> // First seed the temporary variable for ROC(C,260) with the ROC's
> // of all the stocks in in Group0
> //-----------------------------------------------------------
> list = CategoryGetSymbols( categoryGroup, 0 );
> ROC260=Null;
> count=0;
> x=Null;
> y=Null;
> AddToComposite(y,"~yrank","C");
> AddToComposite(x,"~xroc","C");
> for( i = 0; ( sym = StrExtract( list, i ) ) != ""; i++ )
> {
> ROC260[i+1]=LastValue(ROC(Nz(Foreign( sym, "Close" )),260));
> count=count+1;
> }
> k=(BarCount-1-count);
> roc260=Ref(ROC260,-k); // This is correct
> AddToComposite(ROC260,"~roc260","C",1);
> //-----------------------------------------------------------
> // Loop i goes through percentile ranks in
> // increments of 10 from 1 to 99
> // x = the ROC(C,260) that corresponds to rank y
> // y = % Rank in 10% Increments
> //-----------------------------------------------------------
> for( i = 0; i<=10; i++ )
> {
> y[i]=i*10;
> if(i<1) y[i]=1;
> if(i>9) y[i]=99;
> x[i]=LastValue(Percentile( ROC260, count, y[i] ));
> }
> AddToComposite(y,"~yrank","C",1);
> AddToComposite(x,"~xroc","C",1);
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Yahoo! Groups Links
To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
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/
|