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

[amibroker] Re: Sector and industry analysis



PureBytes Links

Trading Reference Links

Hi,

In this case, I would use the first version of the Z-Score formula.

For any population, no matter what its shape or form, the 
distribution of means taken from that population with a constant 
sample size will be normally distributed if the sample size is 
sufficiently large (i.e., at least 30). 

The standard deviation of the sampling distribution, or standard 
error, is equal to the standard deviation of the population divided 
by the square root of the sample size. 

Because of these properties, we can feel fairly confident that when 
we use sample sizes (n) greater than 30, the mean of that sample can 
be used to infer to the population mean, using the standard error as 
the unit of deviation. 

Sampling theory tells us that we can be certain our sample statistics 
lie within a certain margin of error of the true population mean. 
Based on the properties we know about percentile under the normal 
curve, for example, we can say that we are 95 percent sure that the 
population mean lies within roughly two standard error units of the 
observed sample mean. The exact number of standard error units that 
determines the 95 percent confidence span depends on the sample size: 
for example with n = 30, the 95% confidence interval is ± 2.042 
standard error units; for n = 60 it is exactly ± 2.00; and for n = 
120 it is ± 1.98. More important though, is what this 95 percent 
confidence interval means. It means that if were to conduct this 
study repeatedly (i.e., an infinite number of times), and each time 
calculate a 95 percent confidence interval for the population mean, 
the interval would include the true population mean 95 percent of the 
time. Conversely our resulting interval would not include the true 
population mean 5 percent of the time. 

CENTRAL LIMIT THEOREM

For any population with mean m and standard deviation s , the 
distribution of sample means for sample size n will approach a NORMAL 
DISTRIBUTION with a mean of m and a standard deviation of s/(Square 
root of n) as n approaches infinity

LAW OF LARGE NUMBERS

The larger the sample size, the more probable it is that the sample 
mean will be close to the population mean.

The mean of the sampling distribution is equal to the mean of the 
sample but is called the expected value of the sample mean

The standard deviation of the sampling distribution is called the 
standard error.

It is determined by two properties:

the standard deviation of the population, s —as the standard 
deviation increases, so does the standard error; as the standard 
deviation decreases, so does the standard error. 

the sample size, n—as n increases, the standard error decreases, and 
vice versa. 

Suppose you have 20 values, then the mean or moving average of these 
values is (sum of 20 values)/(n = 20).

Regards,

Pal

--- In amibroker@xxxxxxxxxxxxxxx, "Gary A. Serkhoshian" 
<serkhoshian777@xxxx> wrote:
> Pal,
>  
> Great stuff, and thanks for the thorough explaination.  If I 
interpret what you've written below on the mean, the determinant of 
normal distribution is the number of samples > 30 and size of 
samples.  How big does the sample need to be, and could you provide a 
practical example with something simple like a moving average?
>  
> Thanks for the code.  Regarding the two versions of Z Scores listed 
in my prior e-mail which do you prefer using?
>  
> Many thanks in advance, and appreciate you breaking-down these 
complexities in terms my 10 year-old cousin could understand : )
>  
> Warmest,
> Gary
>  
>  
> If a large number of random samples (of size 30 or more) are 
>  collected, the means from a sampling distribution of means where > 
> 
> > > a)  the mean of the sample will be equal to the mean of the 
> > population
> > > 
> > > b)  The StDev of the sampling distribution is the standard 
error 
> of 
> > > the mean and 
> > > 
> > > c)  when n is large (> 30) the sampling distribution of means 
is 
> > > approximately normally distributed regardless of the shape of 
the 
> > > distribution of the population as long as the sample size of 
each 
> > > sample is the same
>  
>  
> 
> 
> palsanand <palsanand@xxxx> wrote:
> Hi,
> 
> Third attempt...
> 
> //PlotShapes(shapeUpTriangle*Cross(x2,Ref(C,1)),colorAqua);
> PlotShapes(shapeUpArrow*(Cross(bb,C)),colorAqua);
> //PlotShapes(shapeDownTriangle*Cross(Ref(C,1),x1),colorPink);
> PlotShapes(shapeDownArrow*(Cross(C,bt)),colorRed);
> 
> It's getting late...
> 
> Pal
> --- In amibroker@xxxxxxxxxxxxxxx, "palsanand" <palsanand@xxxx> 
wrote:
> > Hi,
> > 
> > Sorry, here is the correct code:
> > 
> > PlotShapes(shapeUpTriangle*Cross(x2,Ref(C,1)),colorAqua);
> > //PlotShapes(shapeUpArrow*(Cross(bb,C)),colorRed);
> > PlotShapes(shapeDownTriangle*Cross(Ref(C,1),x1),colorPink);
> > //PlotShapes(shapeDownArrow*(Cross(C,bt)),colorBrightGreen);
> > 
> > Pal
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "palsanand" <palsanand@xxxx> 
> wrote:
> > > Hi,
> > > 
> > > The Central Limit Theorem states:
> > > 
> > > If a large number of random samples (of size 30 or more) are 
> > > collected, the means from a sampling distribution of means 
where 
> > > 
> > > a)  the mean of the sample will be equal to the mean of the 
> > population
> > > 
> > > b)  The StDev of the sampling distribution is the standard 
error 
> of 
> > > the mean and 
> > > 
> > > c)  when n is large (> 30) the sampling distribution of means 
is 
> > > approximately normally distributed regardless of the shape of 
the 
> > > distribution of the population as long as the sample size of 
each 
> > > sample is the same.
> > > 
> > > Z-Scores of the COT data can be combined with the Z-Scores of 
the 
> > > close price to accurately pinpoint turning points.  But, I 
would 
> > > still detect, verify and interpret a Entry/Exit Trading Signal 
> for 
> > > precise timing.
> > > 
> > > I also modified plots for the following code to indicate 
whether 
> > the 
> > > Bands have been crossed, which would warn me to look for a 
> trading 
> > > signal, whether a continuation signal or counter-trend 
> > > pullback/Breakout signal:
> > > 
> > > /* Anticipating the next bar BBandBot OR BBandTop Cross, by D. 
> > > Tsokakis, Sept 2003.  Both crosses come from the same 2nd 
degree 
> > > equation A2*X^2+A1*X+A0=0  The solution is the X2 array.  For 
> > visual 
> > > verification, a pink arrow is plotted when the X2 crosses the 
> next 
> > > bar Close AND a red arrow points the actual Cross. */
> > > 
> > > n=20; f=2;
> > > Qn=Sum(C^2,n);Qn_1=Sum(C^2,n-1);
> > > Sn=Sum(C,n);Sn_1=Sum(C,n-1);
> > > Mn=Sn/n;Mn_1=Sn_1/(n-1);
> > > Kn=(1/n)*sqrt(n*Qn-Sn^2);Kn_1=(1/(n-1))*sqrt((n-1)*Qn_1-Sn_1^2);
> > > bb=Mn-f*Kn;bt=Mn+f*Kn;
> > > S=Sn_1;Q=Qn_1;
> > > A2=(n-1)*(f^2-n+1);
> > > A1=-2*(f^2+1-n)*S;
> > > A0=f^2*n*Q-f^2*S^2-S^2;
> > > x1=(-A1-sqrt(A1^2-4*A2*A0))/(2*A2);
> > > x2=(-A1+sqrt(A1^2-4*A2*A0))/(2*A2);
> > > Plot(C,"C",1,8);
> > > Plot(X1,"",colorBlue,1);
> > > Plot(X2,"",colorBlue,1);Plot(bb,"BBandBot",7,1);Plot
> > > (bt,"BBandTop",7,1);
> > > PlotShapes(shapeUpTriangle*Cross(x2,Ref(C,1)),colorPink);
> > > //PlotShapes(shapeUpArrow*(Cross(bb,C)),colorRed);
> > > PlotShapes(shapeDownTriangle*Cross(Ref(C,1),x1),colorAqua);
> > > //PlotShapes(shapeDownArrow*(Cross(C,bt)),colorBrightGreen);
> > > Title="The next "+Name()+" Close should be "+"\n 
*below"+WriteVal
> > (x2)
> > > +" for a BBandBot Cross"+
> > > "\n *above"+WriteVal(x1)+" for a BBandTop Cross"+
> > > "\n  Actual Next Close = "+WriteIf(Cum(1)!=LastValue(Cum
> > (1)),WriteVal
> > > (Ref(C,1)),"?");
> > > 
> > > 
> > > Regards,
> > > 
> > > Pal
> > > 
> > > 
> > > 
> > > 
> > > 
> > > --- In amibroker@xxxxxxxxxxxxxxx, "Gary A. Serkhoshian" 
> > > <serkhoshian777@xxxx> wrote:
> > > > Pal,
> > > >  
> > > > That makes sense as I've visually seen what you've 
described.  
> It 
> > > seems like our primary job when interpreting the data is to 
> > determine 
> > > where the critical inflection points are versus noise.
> > > >  
> > > > I've worked with Bollinger Bands and the net positions of the 
> > three 
> > > groups, but am interested in how Z-Score differs from what a 
> > > Bollinger Band plots, and does it give a better sense of the 
> > > inflection point we seek.
> > > >  
> > > > In addition, should any changes be made to the ZScore code as 
> > > listed below for non-normal distribution as you describe COT 
data 
> > to 
> > > be?  How do you determine if the data is normally distributed?
> > > >  
> > > > Sorry for all the questions, but you've piqued my interest, 
and 
> > > you've been very clear in your explainations.
> > > >  
> > > > I'd be happy to code any adjustments based on your 
suggestions, 
> > and 
> > > post them on the board.
> > > >  
> > > > Code Below
> > > >  
> > > > Kind Regards,
> > > > Gary
> > > >  
> > > > 
> > > > /*
> > > > 
> > > > There is one interpretation of the Z-Score that takes an 
> > > observation from a
> > > > 
> > > > population and returns a Z-Score statistic, where the Z-Score 
> is a
> > > > 
> > > > measurement of the number of standard deviations that that 
> > specific
> > > > 
> > > > observation deviates from the mean. If this is the 
> interpretation 
> > > you
> > > > 
> > > > intend, the following afl code returns the Z-Score of the 
Close 
> > of 
> > > the most recent 50 days of an end-of-day price series and plots 
> it. 
> > > Copy this code and paste it into Indicator Builder.
> > > > 
> > > > Note that most of the Closes (95 percent, on average) will 
have 
> > > ZScore
> > > > 
> > > > values between -2.0 and +2.0.
> > > > 
> > > > */
> > > > 
> > > > // ZScore of Close
> > > > 
> > > > ZLen = 50;
> > > > 
> > > > ZScore = (C-MA(C,ZLen))/StDev(C,ZLen);
> > > > 
> > > > Plot(C,"C",colorBlack,style=styleCandle);
> > > > 
> > > > Plot(ZScore,"ZScore",colorBlue,styleOwnScale|styleNoLabel,-
3,3);
> > > > 
> > > > Plot(0,"",colorRed,styleOwnScale|styleNoLabel,-3,3);
> > > > 
> > > > Plot(-2.0,"", colorRed,styleOwnScale|styleNoLabel,-3,3 ); 
> > > > 
> > > > Plot(2.0,"", colorRed,styleOwnScale|styleNoLabel,-3,3);
> > > > 
> > > > /* 
> > > > 
> > > > Version 2
> > > > 
> > > > normal percentile to Z Score conversion 
> > > > 
> > > > 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);
> > > > 
> > > > //----------------------
> > > > 
> > > >  
> > > >  
> > > >  
> > > >  
> > > > 
> > > > 
> > > > palsanand <palsanand@xxxx> wrote:
> > > > Gary,
> > > > 
> > > > If you plot the Net Longs of all the 3 players (Commercials, 
> > Large 
> > > > speculators and Small traders), you will see that the plot of 
> the 
> > > > Commercials and Large speculators are at opposite sides about 
> the 
> > > > mean (most of the time) and the small traders closer to the 
> mean.
> > > > 
> > > > You will see that the plot of the Commercials and Large 
> > speculators 
> > > > are either diverging from each other or going parallel (most 
of 
> > the 
> > > > time).
> > > > 
> > > > You can then watch for trend-change pullbacks or breakout 
> signals 
> > > at 
> > > > the specific time on the plot where the Commercials and Large 
> > > > Speculators begin converging from their extreme positions 
> > (visually 
> > > > identified) on either side of the mean.  
> > > > 
> > > > You may use Z-Scores to identify the extreme positions.  Z-
> Scores 
> > > > tend to be used mainly in the context of the normal curve, 
and 
> > > their 
> > > > interpretation based on the standard normal table. It would 
be 
> > > > erroneous to conclude, however, that Z-Scores are limited to 
> > > > distributions that approximate the normal curve. Non-normal 
> > > > distributions can also be transformed into sets of Z-Scores. 
In 
> > > this 
> > > > case the standard normal table cannot be consulted, since the 
> > shape 
> > > > of the distribution of Z-Scores is the same as that for the 
> > > original 
> > > > non-normal distribution. For instance, if the original 
> > distribution 
> > > > is positively skewed the distribution of Z-Scores also will 
be 
> > > > positively skewed.
> > > > 
> > > > Regardless of the shape of the distribution, the shift to Z-
> > Scores 
> > > > always produces a distribution with a mean of 0 and a 
variance 
> of 
> > 1.
> > > > 
> > > > Regards,
> > > > 
> > > > Pal
> > > > 
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "Gary A. Serkhoshian" 
> > > > <serkhoshian777@xxxx> wrote:
> > > > > Pal,
> > > > >  
> > > > > Thanks for the post as I've been racking my brain thinking 
of 
> > > ways 
> > > > to trade COT.  Could you please elaborate on your statement 
> > below.  
> > > > Specifically, how are you identifying extremes (std dev?), 
and 
> > when 
> > > > you write "low points and turning up" are you referring to 
the 
> > net 
> > > > commercial position.  Taking it a step further, can I assume 
> you 
> > > mean 
> > > > net-short commerical?
> > > > >  
> > > > > Thanks,
> > > > > Gary
> > > > >  
> > > > > So, for those places where the 
> > > > > Commercials are at extreme low points and turning up, and 
the 
> > > Large 
> > > > > speculators are at the opposite extreme and turning down, 
the 
> > > > market 
> > > > > will probably turn down shortly (vice-versa for an upside 
> > move).  
> > > > The 
> > > > > small speculators are usually trading with the primary 
trend.
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > ---------------------------------
> > > > > Do you Yahoo!?
> > > > > Yahoo! SiteBuilder - Free, easy-to-use web site design 
> software
> > > > 
> > > > 
> > > > Yahoo! Groups SponsorADVERTISEMENT
> > > > 
> > > > Send BUG REPORTS to bugs@xxxx
> > > > Send SUGGESTIONS to suggest@xxxx
> > > > -----------------------------------------
> > > > 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 the Yahoo! Terms of 
> > > Service. 
> > > > 
> > > > 
> > > > ---------------------------------
> > > > Do you Yahoo!?
> > > > Yahoo! SiteBuilder - Free, easy-to-use web site design 
software
> 
> 
> Yahoo! Groups SponsorADVERTISEMENT
> 
> Send BUG REPORTS to bugs@xxxx
> Send SUGGESTIONS to suggest@xxxx
> -----------------------------------------
> 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 the Yahoo! Terms of 
Service. 
> 
> 
> ---------------------------------
> Do you Yahoo!?
> The New Yahoo! Shopping - with improved product search


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/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/