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

Re: [Metastockusers] How to calculate monthly standard deviation on daily chart



PureBytes Links

Trading Reference Links

Larry

----- Original Message ----- 
From: "lseldin" <larry@xxxxxxxxxx>
To: <Metastockusers@xxxxxxxxxxxxxxx>
Sent: Wednesday, July 02, 2003 10:25 PM
Subject: [Metastockusers] How to calculate monthly standard deviation on
daily chart


> I like calculating 2 sigma (2 standard deviation) on a monthly chart,
> where the period is 13 and the deviation is 2.
>
> Can someone help me caluclate this same number on the daily chart, so
> that the daily chart has the monthly figure.
>
> Thanks much,
>
> larry@xxxxxxxxxx
>

Here's the same code I sent off list, but with 14 months maximum. Also 21
week standard deviation for daily charts and 21 hour standard deviation for
intraday charts. Typos in the latter two are quite likely.

Roy


  {Monthly Standard Deviation}
  {© 2003 Roy Larsen}
  {rlarsen@xxxxxxxxxxxxxx}
  {use with daily charts}
N:=Input("Periods (Months)",2,14,13);
G:=Input("Deviations",0,9,2);
Q:=Input("1=Dynamic last bar,  2=Sample only @ end of month",1,2,1);
 {1=dynamic last month, MS compatible}
 {2=only update current month at end of month}
D:=DayOfMonth(); M:=Month(); Z:=DayOfWeek(); Y:=Year();
M8:=M=2 AND Frac(Y/4)>0; {28 day month}
M0:=M=4 OR M=6 OR M=9 OR M=11; {30 day month}
M1:=M<>4 AND M<>6 AND M<>9 AND
M<>11 AND M<>2; {31 day month}
M9:=M8+M0+M1=0; {29 day month}
A:=(M8 AND (D=28 OR (Z=5 AND D>25))) OR
(M9 AND (D=29 OR (Z=5 AND D>26))) OR
(M0 AND (D=30 OR (Z=5 AND D>27))) OR
(M1 AND (D=31 OR (Z=5 AND D>28))) OR Cum(1)=2;
B:=DayOfMonth()<=ValueWhen(2,1,DayOfMonth());
F:=LastValue(Cum(1))=Cum(1);
J:=If(A,1,If(Alert(A,2)=0 AND B,2,0));
J:=If(F AND J=0 AND Q=1,1,J);
K:=ValueWhen(1,J,If(J=1,C,ValueWhen(2,1,C)));
M:=(Cum(If(J,K,0))-ValueWhen(N+1,J,Cum(If(J,K,0))))/N;
X:=Power(M-ValueWhen(1,J,K),2)+
Power(M-ValueWhen(2,J,K),2)+
If(N>2,Power(M-ValueWhen(3,J,K),2),0)+
If(N>3,Power(M-ValueWhen(4,J,K),2),0)+
If(N>4,Power(M-ValueWhen(5,J,K),2),0)+
If(N>5,Power(M-ValueWhen(6,J,K),2),0)+
If(N>6,Power(M-ValueWhen(7,J,K),2),0)+
If(N>7,Power(M-ValueWhen(8,J,K),2),0)+
If(N>8,Power(M-ValueWhen(9,J,K),2),0)+
If(N>9,Power(M-ValueWhen(10,J,K),2),0)+
If(N>10,Power(M-ValueWhen(11,J,K),2),0)+
If(N>11,Power(M-ValueWhen(12,J,K),2),0)+
If(N>12,Power(M-ValueWhen(13,J,K),2),0)+
If(N>13,Power(M-ValueWhen(14,J,K),2),0);
R:=G*Sqrt(X/N); R;

  {Weekly Standard Deviation}
  {© 2003 Roy Larsen}
  {rlarsen@xxxxxxxxxxxxxx}
  {use on daily charts}
N:=Input("Periods (Weeks)",1,21,14);
G:=Input("Deviations",0,9,2);
Q:=Input("1=Dynamic last bar,  2=Sample only @ end of week",1,2,1);
 {1=dynamic last week, MS compatible}
 {2=sample end of week when available}
A:=DayOfWeek()=5 OR Cum(1)=2;
B:=DayOfWeek()<=ValueWhen(2,1,DayOfWeek());
F:=LastValue(Cum(1))=Cum(1);
J:=If(A,1,If(Alert(A,2)=0 AND B,2,0));
J:=If(F AND J=0 AND Q=1,1,J);
K:=ValueWhen(1,J,If(J=1,C,ValueWhen(2,1,C)));
M:=(Cum(If(J,K,0))-ValueWhen(N+1,J,Cum(If(J,K,0))))/N;
X:=Power(M-ValueWhen(1,J,K),2)+
Power(M-ValueWhen(2,J,K),2)+
If(N>2,Power(M-ValueWhen(3,J,K),2),0)+
If(N>3,Power(M-ValueWhen(4,J,K),2),0)+
If(N>4,Power(M-ValueWhen(5,J,K),2),0)+
If(N>5,Power(M-ValueWhen(6,J,K),2),0)+
If(N>6,Power(M-ValueWhen(7,J,K),2),0)+
If(N>7,Power(M-ValueWhen(8,J,K),2),0)+
If(N>8,Power(M-ValueWhen(9,J,K),2),0)+
If(N>9,Power(M-ValueWhen(10,J,K),2),0)+
If(N>10,Power(M-ValueWhen(11,J,K),2),0)+
If(N>11,Power(M-ValueWhen(12,J,K),2),0)+
If(N>12,Power(M-ValueWhen(13,J,K),2),0)+
If(N>13,Power(M-ValueWhen(14,J,K),2),0)+
If(N>14,Power(M-ValueWhen(15,J,K),2),0)+
If(N>15,Power(M-ValueWhen(16,J,K),2),0)+
If(N>16,Power(M-ValueWhen(17,J,K),2),0)+
If(N>17,Power(M-ValueWhen(18,J,K),2),0)+
If(N>18,Power(M-ValueWhen(19,J,K),2),0)+
If(N>19,Power(M-ValueWhen(20,J,K),2),0)+
If(N>20,Power(M-ValueWhen(21,J,K),2),0);
R:=G*Sqrt(X/N); R;

  {Hourly Standard Deviation}
  {© 2003 Roy Larsen}
  {rlarsen@xxxxxxxxxxxxxx}
  {use on intraday charts}
N:=Input("Periods (Hours)",2,21,14);
G:=Input("Deviations",.1,9,2);
Q:=Input("1=Dynamic last bar,  2=Sample only @ end of hour",1,2,1);
 {1=dynamic last hour, MS compatible}
 {2=sample end of hour when available}
A:=Minute()=0 OR Cum(1)=2;
B:=Hour()<>ValueWhen(2,1,Hour()) OR DayOfWeek()<>
ValueWhen(2,1,DayOfWeek()) OR Cum(1)=2;
F:=LastValue(Cum(1))=Cum(1);
J:=If(A,1,If(Alert(A,2)=0 AND B,2,0));
J:=If(F AND J=0 AND Q=1,1,J);
K:=ValueWhen(1,J,If(J=1,C,ValueWhen(2,1,C)));
M:=(Cum(If(J,K,0))-ValueWhen(N+1,J,Cum(If(J,K,0))))/N;
X:=Power(M-ValueWhen(1,J,K),2)+
Power(M-ValueWhen(2,J,K),2)+
If(N>2,Power(M-ValueWhen(3,J,K),2),0)+
If(N>3,Power(M-ValueWhen(4,J,K),2),0)+
If(N>4,Power(M-ValueWhen(5,J,K),2),0)+
If(N>5,Power(M-ValueWhen(6,J,K),2),0)+
If(N>6,Power(M-ValueWhen(7,J,K),2),0)+
If(N>7,Power(M-ValueWhen(8,J,K),2),0)+
If(N>8,Power(M-ValueWhen(9,J,K),2),0)+
If(N>9,Power(M-ValueWhen(10,J,K),2),0)+
If(N>10,Power(M-ValueWhen(11,J,K),2),0)+
If(N>11,Power(M-ValueWhen(12,J,K),2),0)+
If(N>12,Power(M-ValueWhen(13,J,K),2),0)+
If(N>13,Power(M-ValueWhen(14,J,K),2),0)+
If(N>14,Power(M-ValueWhen(15,J,K),2),0)+
If(N>15,Power(M-ValueWhen(16,J,K),2),0)+
If(N>16,Power(M-ValueWhen(17,J,K),2),0)+
If(N>17,Power(M-ValueWhen(18,J,K),2),0)+
If(N>18,Power(M-ValueWhen(19,J,K),2),0)+
If(N>19,Power(M-ValueWhen(20,J,K),2),0)+
If(N>20,Power(M-ValueWhen(21,J,K),2),0);
R:=G*Sqrt(X/N); R;



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get A Free Psychic Reading! Your Online Answer To Life's Important Questions.
http://us.click.yahoo.com/Lj3uPC/Me7FAA/ySSFAA/zMEolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
Metastockusers-unsubscribe@xxxxxxxxxxx

 

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