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

How to do very simple calculations using MS?



PureBytes Links

Trading Reference Links

Hi folks,

lets consider one wants to take a few sample auto
correlation values using Metastock.

If one would take the first three of them the code could
be written straightforward as follows

---------- sample 1 -----------
Num:= 4;

Avg:= Mov(C, Num, S);

H0:=
+ (Ref(C, -0) - Avg) * (Ref(C, -0) - Avg)
+ (Ref(C, -1) - Avg) * (Ref(C, -1) - Avg)
+ (Ref(C, -2) - Avg) * (Ref(C, -2) - Avg)
+ (Ref(C, -3) - Avg) * (Ref(C, -3) - Avg)
;

H1:=
+ (Ref(C, -0) - Avg) * (Ref(C, -1) - Avg)
+ (Ref(C, -1) - Avg) * (Ref(C, -2) - Avg)
+ (Ref(C, -2) - Avg) * (Ref(C, -3) - Avg)
;

H2:=
+ (Ref(C, -0) - Avg) * (Ref(C, -2) - Avg)
+ (Ref(C, -1) - Avg) * (Ref(C, -3) - Avg)
;

H3:=
+ (Ref(C, -0) - Avg) * (Ref(C, -3) - Avg)
;

rho1:= H1 / H0;
rho2:= H2 / H0;
rho3:= H3 / H0;

rho1;
rho2;
rho3;

{ 95% confidence bands }
+2 / Sqrt(Num);
-2 / Sqrt(Num);
---------- end of sample 1 -----------

If you now want to take a few more auto correlation samples
then this 'software' doesn't accept your attempts, this is,
EITHER the maximum space it allows for code is exceeded
IF YOU EXTEND the following code sample to N=12 ... OR ...

---------- sample 2 -----------
N:= 4;
A:= Mov(C,N,S);

H0:=(C-A)*(C-A)
+(Ref(C,-1)-Avg)*(Ref(C,-1)-A)
+(Ref(C,-2)-Avg)*(Ref(C,-2)-A)
+(Ref(C,-3)-Avg)*(Ref(C,-3)-A)
;

H1:=(C-A)*(Ref(C,-1)-A)
+(Ref(C,-1)-A)*(Ref(C,-2)-A)
+(Ref(C,-2)-A)*(Ref(C,-3)-A)
;

H2:=(C- A)*(Ref(C,-2)-A)
+(Ref(C,-1)- A)*(Ref(C,-3)-A)
;

H3:=(C-A)*(Ref(C,-3)- A)
;

r1:=H1/H0;
r2:=H2/H0;
r3:=H3/H0;

r1; r2; r3;

+2/Sqrt(N);
-2/Sqrt(N);
---------- end of sample 2 -----------

 ... OR ... the maximum of 20 (yes, twenty!) variables is
exceeded IF YOU EXTEND the following code sample to N=11

---------- sample 3 -----------
N:=4;

A:=Mov(C,N,S);

Rf0:=C-A;
Rf1:=Ref(C,-1)-A;
Rf2:=Ref(C,-2)-A;
Rf3:=Ref(C,-3)-A;

z:=
+Rf0*Rf0
+Rf1*Rf1
+Rf2*Rf2
+Rf3*Rf3
;

B:=
+Rf0*Rf1
+Rf1*Rf2
+Rf2*Rf3
;r1:=B/z;

B:=
+Rf0*Rf2
+Rf1*Rf3
;r2:=B/z;

B:=
+Rf0*Rf3
;r3:=B/z;

r1;r2;r3;

+2/Sqrt(N);
-2/Sqrt(N);
---------- end of sample 3 -----------

Now, my point is the question if there is ANY way to do that
simple standard calculation using Metastock?

Since I'm not used to using functional programming languages
there might still be some recursive way using the PREV 'constant'
(thought it to be a operator) or some other trick I am not aware
of.

Functions that take arguments do not exist and I don't also know
how to utilize the "fml" or "fmlvar" 'operator' do help to get
the horse run. Furthermore, I would like to use, say, 50 periods,
thus N=:50

I would be glad to hear what you think on that problem.
Thank you all in advance!

Regards - Jasper