PureBytes Links
Trading Reference Links
|
I have found this on internet.
Erkan
/*Author: Rainer Hegger, last modified: May 24th, 1998 */#include <stdio.h>#include <stdlib.h>#include <malloc.h>#include <math.h>#include <limits.h>#include <string.h>#include <tsa_routines.h>#define NMAX 256char *outfile;double *series,*lyap;long box[NMAX][NMAX],*list;int dim=2,delay=1,steps=10,mindist=0;unsigned int column=1;const unsigned int nmax=NMAX-1;unsigned long length=ULONG_MAX,exclude=0;long *found;double eps0=1.e-3,eps,epsinv;void show_options(void){ fprintf(stderr,"Estimates the maximal Lyapunov exponent;" " Rosenstein et al.\n"); fprintf(stderr,"Usage: lyap_r filename [options]\n"); fprintf(stderr,"Options:\n"); fprintf(stderr,"\t-l# of datapoints [default is whole file]\n"); fprintf(stderr,"\t-x# of lines to be ignored [default is 0]\n"); fprintf(stderr,"\t-ccolumn to read[default 1]\n"); fprintf(stderr,"\t-dembedding dimension [default 2]\n"); fprintf(stderr,"\t-Ddelay [default 1]\n"); fprintf(stderr,"\t-wtime window to omit [default 0]\n");
fprintf(stderr,"\t-eepsilon size to start with [default 1.e-3]\n"); fprintf(stderr,"\t-i# of iterations [default 10]\n"); fprintf(stderr,"\t-oname of output file [default 'filename'.ros]\n"); fprintf(stderr,"\t-h show these options\n"); fprintf(stderr,"\n"); exit(0);}void scan_options(int n,char **argv){ int i; char slength,scol,sdel,sdim,swin,siter,sfile,seps,shelp,sex; for (i=2;i<n;i++) { slength=(argv[i][0] == '-') && (argv[i][1] == 'l'); sex=(argv[i][0] == '-') && (argv[i][1] == 'x'); scol=(argv[i][0] == '-') && (argv[i][1] == 'c'); sdel=(argv[i][0] == '-') && (argv[i][1] == 'D'); sdim=(argv[i][0] == '-') && (argv[i][1] == 'd'); swin=(argv[i][0] == '-') && (argv[i][1] == 'w'); seps=(argv[i][0] == '-') && (argv[i][1] == 'e'); siter=(argv[i][0] == '-') && (argv[i][1] == 'i'); sfile=(argv[i][0] == '-') && (argv[i][1] == 'o'); shelp=(argv[i][0] == '-') && (argv[i][1] == 'h'); if (slength) length=(unsigned long)atol(argv[i]+2); if
(sex) exclude=atol(argv[i]+2); if (scol) column=atoi(argv[i]+2); if (sdel) delay=atoi(argv[i]+2); if (sdim) dim=atoi(argv[i]+2); if (swin) mindist=atoi(argv[i]+2); if (siter) steps=atoi(argv[i]+2); if (seps) sscanf(argv[i]+2,"%lf",&eps0); if (sfile) { outfile=argv[i]+2; } if (shelp) show_options(); }} void put_in_boxes(void){ int i,j,x,y,del; for (i=0;i<NMAX;i++) for (j=0;j<NMAX;j++) box[i][j]= -1; del=delay*(dim-1); for (i=0;i<length-del-steps;i++) { x=(int)(series[i]*epsinv)&nmax; y=(int)(series[i+del]*epsinv)&nmax; list[i]=box[x][y]; box[x][y]=i; }}char make_iterate(long act){ char ok=0; int x,y,i,j,i1,k,del1=dim*delay; long element,minelement= -1; double dx,mindx=1.0; x=(int)(series[act]*epsinv)&nmax; y=(int)(series[act+delay*(dim-1)]*epsinv)&nmax; for (i=x-1;i<=x+1;i++) { i1=i&nmax; for (j=y-1;j<=y+1;j++) { element=box[i1][j&nmax]; while (element !=
-1) { if (labs(act-element) > mindist) { dx=0.0; for (k=0;k<del1;k+=delay) { dx += (series[act+k]-series[element+k])* (series[act+k]-series[element+k]); if (dx > eps) break; } if (k==del1) { if (dx < mindx) { ok=1; if (dx > 0.0) { mindx=dx; minelement=element; } } } } element=list[element]; } } } if ((minelement != -1) ) { act--; minelement--; for (i=0;i<=steps;i++) { act++; minelement++; dx=0.0; for (j=0;j<del1;j+=delay) { dx += (series[act+j]-series[minelement+j])* (series[act+j]-series[minelement+j]); } if (dx > 0.0) { found[i]++; lyap[i] += log(dx); } } } return ok;}void main(int argc,char **argv){ char stdi,*done,alldone; int i; unsigned long n; long maxlength; double min,max; FILE *file; if ((argc < 2) || scan_help(argc,argv)) show_options(); stdi= !strcmp(argv[1],"-"); if (!stdi) { if ((file=fopen(argv[1],"r")) == NULL) {
fprintf(stderr,"File %s does not exist!\n",argv[1]); exit(127); } fclose(file); } if (!stdi) { outfile=(char*)calloc(strlen(argv[1])+5,1); strcpy(outfile,argv[1]); strcat(outfile,".ros"); } else { outfile=(char*)calloc(10,1); strcpy(outfile,"stdin.ros"); } scan_options(argc,argv); series=(double*)get_series(argv[1],&length,exclude,column); rescale_data(series,length,&min,&max); list=(long*)malloc(length*sizeof(long)); lyap=(double*)malloc((steps+1)*sizeof(double)); found=(long*)malloc((steps+1)*sizeof(long)); done=(char*)malloc(length); for (i=0;i<=steps;i++) { lyap[i]=0.0; found[i]=0; } for (i=0;i<length;i++) done[i]=0; maxlength=length-delay*(dim-1)-steps-1-mindist; alldone=0; file=fopen(outfile,"w"); for (eps=eps0;!alldone;eps*=1.1) { epsinv=1.0/eps; put_in_boxes(); alldone=1; for (n=0;n<=maxlength;n++) { if (!done[n]) done[n]=make_iterate(n); alldone &= done[n]; } fprintf(stderr,"epsilon: %e
already found: %ld\n",eps,found[0]); } for (i=0;i<=steps;i++) if (found[i]) fprintf(file,"%d %e\n",i,lyap[i]/found[i]/2.0); fclose(file);}
---------------------------------
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
[Non-text portions of this message have been removed]
------------------------ Yahoo! Groups Sponsor --------------------~-->
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~->
Check AmiBroker web page at:
http://www.amibroker.com/
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|