MetaStock™ Zone Forum & FAQ Artykuły Linki Elliott Waves EasyLanguage™ Zone

A B C D E F G H I J K L M N O P R S T U V W Y Z #

Frequency Distribution by MG Ferreira

From: robcpettit <robcpettit / at / yahoo.co.uk>
To: equismetastock / at / yahoogroups.com <equismetastock / at / yahoogroups.com>
Date: Monday, May 16, 2005, 11:18:41 PM
Subject: [EquisMetaStock Group] frequency distribution.

Hi, I think the answer no but I have to ask. Is it possible to do frequency distribution charts, in the traditional bell shape, without purchasing tradesim.

Regards Robert

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

From: mgf_za_1999 <no_reply / at / yahoogroups.com>
To: equismetastock / at / yahoogroups.com <equismetastock / at / yahoogroups.com>
Date: Tuesday, May 17, 2005, 8:14:27 AM
Subject: [EquisMetaStock Group] Re: frequency distribution.

Hi Robert,

I think this is not that difficult to do actually, using a few 'Cum' and 'LastValue' statements should do the trick. It won't be as nice as you'd want it to be, but will be a lot easier than copy and paste to Excel. If I have more time, I'll see if I can cook up something for this.

Regards
MG Ferreira
TsaTsa EOD Programmer and trading model builder
http://www.ferra4models.com
http://fun.ferra4models.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

From: mgf_za_1999 <no_reply / at / yahoogroups.com>
To: equismetastock / at / yahoogroups.com <equismetastock / at / yahoogroups.com>
Date: Tuesday, May 17, 2005, 9:16:57 AM
Subject: [EquisMetaStock Group] Re: frequency distribution.
Robert,

Actually I am in so much trouble now with all the time I just spent on this very interesting challenge. Here it is


Frequency Distribution

{MG Ferreira}
{http://www.ferra4models.com}
{Plots frequency distribution of daily returns}
{and fitted normal distribution, either in values}
{or percentages.}
{For personal use only}

{Number of bins, use log(n) if not sure}
Bins:=Input("Number of bins?",5,20,10);
UsePct:=Input("Actual count(0) or percentage(1)?",0,1,0);

{What we want to distribute, change to your liking}
Y:=100*(C/Ref(C,-1)-1); {Daily returns}

{Calcs}
yMax:=LastValue(Highest(Y));
yMin:=LastValue(Lowest(Y));
yRange:=yMax-yMin;
BinSize:=yRange/Bins;

{Count frequency in each bin}
ii:=Cum(1);
nn:=LastValue(ii);
CumFreq:=0*(ii<=2)+
LastValue(Cum(Y<yMin+BinSize*1))*(ii=3)+
LastValue(Cum(Y<yMin+BinSize*2))*(ii=4)+
LastValue(Cum(Y<yMin+BinSize*3))*(ii=5)+
LastValue(Cum(Y<yMin+BinSize*4))*(ii=6)+
LastValue(Cum(Y<yMin+BinSize*5))*(ii=7)+
LastValue(Cum(Y<yMin+BinSize*6))*(ii=8)+
LastValue(Cum(Y<yMin+BinSize*7))*(ii=9)+
LastValue(Cum(Y<yMin+BinSize*8))*(ii=10)+
LastValue(Cum(Y<yMin+BinSize*9))*(ii=11)+
LastValue(Cum(Y<yMin+BinSize*10))*(ii=12)+
LastValue(Cum(Y<yMin+BinSize*11))*(ii=13)+
LastValue(Cum(Y<yMin+BinSize*12))*(ii=14)+
LastValue(Cum(Y<yMin+BinSize*13))*(ii=15)+
LastValue(Cum(Y<yMin+BinSize*14))*(ii=16)+
LastValue(Cum(Y<yMin+BinSize*15))*(ii=17)+
LastValue(Cum(Y<yMin+BinSize*16))*(ii=18)+
LastValue(Cum(Y<yMin+BinSize*17))*(ii=19)+
LastValue(Cum(Y<yMin+BinSize*18))*(ii=20)+
LastValue(Cum(Y<yMin+BinSize*19))*(ii=21)+
LastValue(Cum(Y<yMin+BinSize*20))*(ii=22)+
(nn-1)*(ii>22);

Freq:=(CumFreq-Ref(CumFreq,-1))/(UsePct*nn+(UsePct=0));

{Now fit a normal distro to it}
Mu:=LastValue(Cum(y))/(nn-1);
Sigma:=LastValue(Stdev(y,nn-2));
NormDistro:=Exp(-0.5*Power((yMin+BinSize*(ii-2)-Mu)/Sigma,2))/sigma;
CumNorm:=LastValue(Cum(NormDistro));
NormFin:=NormDistro/CumNorm*((UsePct=0)*(nn-1)+(UsePct=1));

NormFin;Freq

 

 

This asks you to give the number of bins, say 10. Use log(#obs) if you are not sure, and I should probably have used this somewhere as well. It then calculates the frequency distro and also fits a normal distro to it, which it plot. If you enter say 20 bins (the max) then the first 20 + 2 values contain the frequency and normal distros. The rest you can basically ignore.

Now, this is plotted on a date axis. To plot it on a proper axis can not be done, but just change the last line to something like

NormFin;Freq;yMin+BinSize*(ii-2)

to get the values of the x axis as well. You can then copy this out to say Excel for further analysis.

Regards
MG Ferreira
TsaTsa EOD Programmer and trading model builder
http://www.ferra4models.com
http://fun.ferra4models.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

From: robcpettit <robcpettit / at / yahoo.co.uk>
To: equismetastock / at / yahoogroups.com <equismetastock / at / yahoogroups.com>
Date: Tuesday, May 17, 2005, 9:37:24 AM
Subject: [EquisMetaStock Group] Re: frequency distribution.

MG Ferreira, Thank you for your reply, well beyond the kind of reply was expecting. This looks like it took some time to put together so its much appreciated and Ill have fun playing with it. It will take a while to learn whats actually happening.
Regards Robert

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

From: robcpettit <robcpettit / at / yahoo.co.uk>
To: equismetastock / at / yahoogroups.com <equismetastock / at / yahoogroups.com>
Date: Tuesday, May 17, 2005, 11:12:10 AM
Subject: [EquisMetaStock Group] Re: frequency distribution.

I hate to ask, as youve spent long enough on this, Ive messed around with this but my lack of understanding doesnt help. Id like a distribution of say how many times a price changes by 1, or 2, or 3, or -1, or -2 etc. Which areas would I have to change. Ive altered the formula to c-(ref(c,-1) and played around with other parts. With the ref to bins is this setting up different areas to add repeated values to. Sorry for my lack of understanding. I have excel so I can use that.
Regards Robert

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

From: mgf_za_1999 <no_reply / at / yahoogroups.com>
To: equismetastock / at / yahoogroups.com <equismetastock / at / yahoogroups.com>
Date: Tuesday, May 17, 2005, 3:15:46 PM
Subject: [EquisMetaStock Group] Re: frequency distribution.

Hi Robert,

Please, don't be so apologetic about it! You are free to ask and I guess this forum is exactly for this - a free flow of ideas,
indicators and MSFL stuff.

You are right in changing the c-ref(c,-1) bit. Also, specify the starting bin (this is the minimum observed percentage change in the original) to say -5. Then the histogram will start at -5. Now, make BinSize:=1, then the histogram starts at -5, the next bin at -4 etc. Change these (yMin and BinSize) to whatever applies to you. If you have a histogram with more than 20 bins, you'd have to extend the big formula with all the lastvalue's in, but it should be more or less obvious how to do this. And, of course, if you do this, let me have a copy of it please.

Regards
MG Ferreira
TsaTsa EOD Programmer and trading model builder
http://www.ferra4models.com
http://fun.ferra4models.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

From: Khamsina <Khamsina11 / at / yahoo.fr>
To: equismetastock / at / yahoogroups.com <equismetastock / at / yahoogroups.com>
Date: Tuesday, May 17, 2005, 3:27:59 PM
Subject: [EquisMetaStock Group] Re: frequency distribution.

Hi MG,

After plotting your code, I have a straight line :-[

Where is my mistake ?

Thanks in advance for your help,
Regards,

Marco

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

From: mgf_za_1999 <no_reply / at / yahoogroups.com>
To: equismetastock / at / yahoogroups.com <equismetastock / at / yahoogroups.com>
Date: Tuesday, May 17, 2005, 5:12:24 PM
Subject: [EquisMetaStock Group] Re: frequency distribution.

Hi there,

The whole frequency distro is shuffed into the first few (20 or so) observations of a time series. Everything beyond this is just a straight line. So zoom in to the plot and then slide right to the beginning of it.

Regards
MG Ferreira
TsaTsa EOD Programmer and trading model builder
http://www.ferra4models.com
http://fun.ferra4models.com

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


From: mgf_za_1999 <no_reply / at / yahoogroups.com>
To: equismetastock / at / yahoogroups.com <equismetastock / at / yahoogroups.com>
Date: Tuesday, May 17, 2005, 5:19:26 PM
Subject: [EquisMetaStock Group] Re: frequency distribution.

> straight line. So zoom in to the plot and then slide right to the
> beginning of it.

This of course means you have to slide to the left....

Regards
MG Ferreira
TsaTsa EOD Programmer and trading model builder
http://www.ferra4models.com
http://fun.ferra4models.com

Source / From: TOP
equismetastock[at]yahoogroups[dot]com

Equis and MetaStock® and MetaStock Professional® are registered trademarks of Equis International. Achelis Binary Wave®, The DownLoader®,
Expert Advisor®, OptionScope®, Quotecenter® and Smart Charts® are trademarks of Equis International, a Thomson Reuters company.

TradeStation® Pro, TradeStation® 2000i, OptionStation®, SuperCharts®, PowerEditor® and EasyLanguage®
are registered trademarks of TradeStation Technologies, Inc. Other names and marks referred to are the property of their respective owners.

All information provided on this website is for educational purposes only. Trading involves risk, including possible loss of principal and other losses.

Ten i inne materiały na tej stronie zostały zamieszczone zostały jedynie w celach edukacyjnych, nie ponoszę żadnej odpowiedzialno¶ci za ich stosowanie.

Gra na giełdzie i rynkach walutowych (FOREX) niesie ze sob± ryzyko poważnych strat finansowych!