PureBytes Links
Trading Reference Links
|
I want to apologize for not taking the time necessary to work all the
problems in properly relating addressing in Omega EL and the more
conventional languages and understanding the algorithm which I was
using to achieve a Polynomial Fit.
The following code properly relates EL variables and the variables
that were used in the original procedure.
FOR KX=1 TO NumPoint BEGIN
YK=Price[NumPoint-KX];
The above properly puts data into the matrix in increasing order
by time (x axis).
Sum=CX[DegPoly+1];
FOR KX=DegPoly DOWNTO 1 BEGIN
Sum=CX[KX]+Sum*(NumPoint+NPointPd);
END;
The above changes are due to pure stupidity on my part initially
in not realizing that the computation of the projection value should
be made based on a X value that relates to the initial element of
the data series.
Again, sorry to cause problems but this I have faith is right.
Code listed below for non ts4/ts2k users.
Ela attached.
Clyde
{
Function: PolyFit_Proj
}
Input: Price(NumericSeries), {Price data to fit polynomial to
and project }
DegPoly(NumericSimple), {Degree of polynomial to fit --
max=7 }
NumPoint(NumericSimple), {Number of data points to use in
fit--max=53 }
NPointPd(NumericSimple); {Number of points forward to
predict price }
{ PROGRAM LPOLYNOM}
{C ----------------------------------------------------------------}
{C Alg5"2.for FORTRAN program for implementing Algorithm 5.2}
{C }
{C NUMERICAL METHODS: FORTRAN Programs, (c) John H. Mathews 1995}
{C To accompany the text:}
{C NUMERICAL METHODS for Math., Science & Engineering, 2nd Ed, 1992}
{C Prentice Hall, Englewood Cliffs, New Jersey, 07632, U.S.AX.}
{C Prentice Hall, Inc.; USA, Canada, Mexico ISBN 0-13-624990-6}
{C Prentice Hall, International Editions: ISBN 0-13-625047-5}
{C This free software is compliments of the author.}
{C E-mail address: in%"mathews@xxxxxxxxxxxxx"}
{C }
{C Algorithm 5.2 (Least Squares Polynomial).}
{C Section 5.2, Curve Fitting, Page 278}
{C ----------------------------------------------------------------}
{
SUBROUTINE SOLVELI(Price,NumPoint,AX,BX,DegPoly,CX)
INTEGER Col,IX,JX,KX,DegPoly,IP,RX,Row,T
REAL AX,BX,CX,XX,Price,PX,Sum,Pow,Prod,XK,YK,Err,Z1
DIMENSION AX(1:8,1:8),BX(1:8),CX(1:8),Price(1:53)
DIMENSION Row(1:7),ZX(1:7)
DIMENSION Pow(0:14)
}
Vars: Col(0),IX(0),JX(0),KX(0),IP(0),RX(0),Temp(0);
Vars: XX(0),PX(0),Sum(0),Prod(0),XK(0),YK(0),Z1(0);
Array: AX[8,8](0),BX[8](0),CX[8](0),Row[8](0),ZX[8](0),Pow[16](0) ;
{C FILL MATRIX FIRST}
FOR RX=1 TO DegPoly+1 BEGIN
BX[RX]=0;
END;
FOR KX=1 TO NumPoint BEGIN
YK=Price[NumPoint-KX];
XK=KX;
Prod=1;
FOR RX=1 TO DegPoly+1 BEGIN
BX[RX]=BX[RX]+YK*Prod;
Prod=Prod*XK;
END;
END;
FOR JX=1 TO 2*DegPoly BEGIN
Pow[JX]=0;
END;
Pow[0]=NumPoint;
FOR KX=1 TO NumPoint BEGIN
XK=KX;
Prod=KX;
FOR JX=1 TO 2*DegPoly BEGIN
Pow[JX]=Pow[JX]+Prod;
Prod=Prod*XK;
END;
END;
FOR RX=1 TO DegPoly+1 BEGIN
FOR Col=1 TO DegPoly+1 BEGIN
AX[RX,Col]=Pow[RX+Col-2];
END;
END;
{C NOW SOLVE FOR COEFFICIENTS}
FOR JX=1 TO DegPoly+1 BEGIN
Row[JX]=JX;
END;
FOR IP=1 TO DegPoly BEGIN
FOR KX=IP+1 TO DegPoly+1 BEGIN
IF ABSValue(AX[Row[KX],IP])>ABSValue(AX[Row[IP],IP]) THEN BEGIN;
Temp=Row[IP];
Row[IP]=Row[KX];
Row[KX]=Temp;
END;
END;
FOR KX=IP+1 TO DegPoly+1 BEGIN
AX[Row[KX],IP]=AX[Row[KX],IP]/AX[Row[IP],IP];
FOR Col=IP+1 TO DegPoly+1 BEGIN
AX[Row[KX],Col]=AX[Row[KX],Col]-AX[Row[KX],IP]*AX[Row[IP],Col];
END;
END;
END;
ZX[1]=BX[Row[1]];
FOR KX=2 TO DegPoly+1 BEGIN
Sum=0;
FOR Col=1 TO KX-1 BEGIN
Sum=Sum+AX[Row[KX],Col]*ZX[Col];
END;
ZX[KX]=BX[Row[KX]]-Sum;
END;
CX[DegPoly+1]=ZX[DegPoly+1]/AX[Row[DegPoly+1],DegPoly+1];
FOR KX=DegPoly DOWNTO 1 BEGIN
Sum=0;
FOR Col=KX+1 TO DegPoly+1 BEGIN
Sum=Sum+AX[Row[KX],Col]*CX[Col];
END;
CX[KX]=(ZX[KX]-Sum)/AX[Row[KX],KX];
END;
{C NOW COMPUTE NEXT POINT IN SERIES AND RETURN}
Sum=CX[DegPoly+1];
FOR KX=DegPoly DOWNTO 1 BEGIN
Sum=CX[KX]+Sum*(NumPoint+NPointPd);
END;
PolyFit_Project=Sum;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Clyde Lee Chairman/CEO (Home of SwingMachine)
SYTECH Corporation email: <clydelee@xxxxxxx>
7910 Westglen, Suite 105 Work: (713) 783-9540
Houston, TX 77063 Fax: (713) 783-1092
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>
Attachment Converted: "c:\eudora\attach\Polyfitp.ela"
|