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

[amibroker] RE: Z Score



PureBytes Links

Trading Reference Links

Hi Pal --

Here is a conversion of the (Abramowitz & Stegun) algorithm you originally
asked about into afl code.  

Am I correct in the following interpretation?  Given a percentile of the
normal probability density, what is the corresponding Z Score?

Z Scores are based on a normal density with mean 0.0 and standard deviation
1.0.  95% of Z Scores fall between -2.0 and +2.0.  So setting p to 0.025 and
0.975 should return Z Scores of -2.0 and 2.0.  And setting p to 0.50 should
return 0.0. 

If so, then the (Abramowitz & Stegun) algorithm is NOT correct.  See if
there is a term missing or a coefficient wrong.  I do not have reference
books handy so cannot check for myself.  

The simpler (Schmeiser) routine you described, with code given below, works
correctly and executes quickly.

The perl routine you described more recently (afl code not included with
this message) uses a binary search and will take much longer to return the Z
Score than either of the others.  No problem for an occasional use, but time
consuming if done within loops.

If you are using either of these in a trading system, you probably do not
need precision better than 3e-3, or even better than two digits -- there is
lots else going that will throw more random variation into the system than
that.

If I am not too nosy, can you tell us how you will be using this (after it
is corrected)?  Usually some number of data items, such as trade profits,
are converted to Z Scores as part of a normalization process.  What is the
situation where you will want to know the Z Score corresponding to a point
on the normal probability density curve?

Thanks,
Howard

//----------------------
//	normal percentile to Z Score conversion 
//	Version 1 -- Abramowitz & Stegun

//	the formula needs to be corrected

a0 = 2.30753;
a1 = 0.27061;
b1 = 0.99229;
b2 = 0.04481;


//p = 0.025;

p = Param("p", 0.025, 0.0001, 0.9999, 0.0001 );

pp = IIf(p<=0.5, p, 1.0-p);

t = sqrt(log(1.0/pp^2));
z = t - (a0 + a1*t) / (1.0 - t * (b1 + b2*t));

z = IIf(p<=0.5, z, -z);

//----------------------


//----------------------
//	normal percentile to Z Score conversion 
//	Version 2
//
//	Schmeiser (1979) came up with the following simple 
//	formula for p > 0.5:
//
//    z = {p ^ 0.135 - (1-p) ^ 0.135} / 0.1975
//
//	According to a table in Shore (1982), it is accurate 
//	to two digits at p = 0, 0.4, 0.8, ..., 
//	which may be good enough.

//p = 0.025;

p = Param("p", 0.025, 0.0001, 0.9999, 0.0001 );

pp = IIf(p>=0.5, p, 1.0-p);

z = ((pp ^ 0.135) - ((1.0-pp) ^ 0.135)) / 0.1975;

z = IIf(p>=0.5, z, -z);

//----------------------




>    Date: Fri, 19 Sep 2003 19:01:08 -0000
>    From: "palsanand" <palsanand@xxxxxxxxx>
> Subject: Z-Score
> 
> Hi,
> 


<<SNIP>>




------------------------ Yahoo! Groups Sponsor ---------------------~-->
Special Sale: 50% off ReplayTV
Easily record your favorite shows!
CNet Ranked #1 over Tivo!
http://us.click.yahoo.com/WUMW7B/85qGAA/ySSFAA/GHeqlB/TM
---------------------------------------------------------------------~->

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 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/