PureBytes Links
Trading Reference Links
|
Robert,
Actually I am in so much trouble now with all the time I just spent on
this very interesting challenge. Here it is
----8<----------------------
{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
----8<----------------------
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
--- In equismetastock@xxxxxxxxxxxxxxx, mgf_za_1999 <no_reply@xxxx> wrote:
> 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
>
>
> --- In equismetastock@xxxxxxxxxxxxxxx, "robcpettit" <robcpettit@xxxx>
> wrote:
> > 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
------------------------ Yahoo! Groups Sponsor --------------------~-->
What would our lives be like without music, dance, and theater?
Donate or volunteer in the arts today at Network for Good!
http://us.click.yahoo.com/Tcy2bD/SOnJAA/cosFAA/BefplB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/equismetastock/
<*> To unsubscribe from this group, send an email to:
equismetastock-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|