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

[amibroker] Re: Lyapunov exponent and predictability (day)



PureBytes Links

Trading Reference Links


Hello..
just a note... the formula posted by Dimitris is referred to Hurst 
Exponent, not to Lyapunov.
:)
--- In amibroker@xxxxxxxxxxxxxxx, "ntk98_2000" <ntk98_2000@xxxx> 
wrote:
> 
> Could you pls explain what setvar() or getvar() are doing? 
Sometimes 
> compact code could make the mechanism very hard to understand.
> Is it the only way to re-construct the Lyapunov formula?
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "DIMITRIS TSOKAKIS" 
> <TSOKAKIS@xxxx> wrote:
> > 
> > The final form could be
> > 
> > in =ln(Close/Ref(Close,-1));
> > BarsToEnd = LastValue( BarIndex() ) - BarIndex();
> > Z=LastValue(Cum(1))-Cum(1);
> > for(i=3;i<=8;i++)
> > {
> > VarSet("mean"+i,ValueWhen( BarsToEnd % 2^i == 0, MA( in, 2^i ), 
> 0 ));
> > VarSet("dist"+i,Cum( in - VarGet("mean"+i) ) - ValueWhen( 
> BarsToEnd % 
> > 2^i == 0, in-VarGet("mean"+i) ));
> > VarSet("RS"+i,( HHV( VarGet("dist"+i), 2^i ) - LLV( VarGet
> ("dist"+i), 
> > 2^i ) ) / StDev( in , 2^i ));
> > VarSet("ARS"+i,(257-2^i)*MA(VarGet("RS"+i)*(Z%(2^i)==0),257-
2^i)/2^
> (8-
> > i));
> > VarSet("Y"+i,log(VarGet("ARS"+i))/log(2));
> > }
> > Y8=VarGet("Y8");Y7=VarGet("Y7");Y6=VarGet("Y6");
> > Y5=VarGet("Y5");Y4=VarGet("Y4");Y3=VarGet("Y3");
> > Sumx = 3+4+5+6+7+8;
> > Sumy = Y8 + Y7 + Y6 + Y5 + Y4 + Y3;
> > sumxy = 8*Y8 + 7*Y7 + 6*Y6 + 5*Y5 + 4*Y4 + 3*Y3;
> > Sumx2 = 3*3 + 4*4 + 5*5 + 6*6 + 7*7 + 8*8;
> > b=( 6 * sumxy - sumx*sumy )/( 6 * sumx2 - sumx*sumx); 
> > Filter = BarsToEnd == 0;
> > AddColumn( Close, "Close", 1.5 );
> > AddColumn( b, "Hurst Exponent", 1.5);
> > AddColumn( 2-b, "Fractal Dim", 1.5 );
> > 
> > Dimitris
> > --- In amibroker@xxxxxxxxxxxxxxx, "DIMITRIS TSOKAKIS" 
> <TSOKAKIS@xxxx> 
> > wrote:
> > > 
> > > The part
> > > 
> > > ARS8 = RS8;
> > > ARS7 = ( RS7 + Ref( RS7, -128 ) ) / 2;
> > > ARS6 = ( RS6 + Ref( RS6, -64 ) + Ref( RS6, -128 ) + 
> > > Ref( RS6, -192) ) / 4;
> > > ARS5 = ( RS5 + Ref( RS5, -32 ) + Ref( RS5, -64 ) + 
> > > Ref( RS5, -96 ) + Ref( RS5, -128 ) +Ref( RS5, -160 ) + 
> > > Ref( RS5, -192 ) +Ref( RS5, -224 ) ) / 8;
> > > ARS4 = ( RS4 + Ref( RS4, -16 ) + Ref( RS4, -32 ) + 
> > > Ref( RS4, -48 ) + Ref( RS4, -64 ) + Ref( RS4, -80 ) + 
> > > Ref( RS4, -96 ) +Ref( RS4, -112 ) + Ref( RS4, -128 ) +
> > > Ref( RS4, -144 ) + Ref( RS4, -160 ) +Ref( RS4, -176 ) +
> > > Ref( RS4, -192 ) +Ref( RS4, -208 ) + Ref( RS4, -224 ) +
> > > Ref( RS4, -240 ) ) / 16;
> > > ARS3 = ( RS3 + 
> > > Ref( RS3, -8 ) + Ref( RS3, -16 ) + 
> > > Ref( RS3, -24 ) + Ref( RS3, -32 ) + 
> > > Ref( RS3, -40 ) + Ref( RS3, -48 ) + 
> > > Ref( RS3, -56 ) + Ref( RS3, -64 ) + 
> > > Ref( RS3, -72 ) + Ref( RS3, -80 ) +
> > > Ref( RS3, -88 ) + Ref( RS3, -96 ) + 
> > > Ref( RS3, -104 ) + Ref( RS3, -112 ) + 
> > > Ref( RS3, -120 ) + Ref( RS3, -128 ) + 
> > > Ref( RS3, -136 ) + Ref( RS3, -144 ) + 
> > > Ref( RS3, -152 ) + Ref( RS3, -160 ) + 
> > > Ref( RS3, -168 ) + Ref( RS3, -176 ) + 
> > > Ref( RS3, -184 ) + Ref( RS3, -192 ) + 
> > > Ref( RS3, -200 ) + Ref( RS3, -208 ) + 
> > > Ref( RS3, -216 ) + Ref( RS3, -224 ) + 
> > > Ref( RS3, -232 ) + Ref( RS3, -240 ) + 
> > > Ref( RS3, -248 ) ) / 32;
> > > 
> > > may be replaced by
> > > 
> > > Y=LastValue(Cum(1))-Cum(1);
> > > ARS8 = RS8;
> > > ARS7=129*MA(RS7*(Y%128==0),129)/2;
> > > ARS6=193*MA(RS6*(Y%64==0),193)/4;
> > > ARS5=225*MA(RS5*(Y%32==0),225)/8;
> > > ARS4=241*MA(RS4*(Y%16==0),241)/16;
> > > ARS3=249*MA(RS3*(Y%8==0),249)/32;
> > > 
> > > Dimitris
> > > 
> > > 
> > > 
> > > --- In amibroker@xxxxxxxxxxxxxxx, "DIMITRIS TSOKAKIS" 
> > <TSOKAKIS@xxxx> 
> > > wrote:
> > > > 
> > > > Hans,
> > > > Thank you for your reply and the ref you posted in other 
> messages.
> > > > Here is some notes:
> > > > 
> > > > 1. 
> > > > The formula references FUTURE quotes.
> > > > If you read for ^NDX Oct1 Hurst=0.58, ten days later the 
value 
> > for 
> > > > the same date Oct1 WILL NOT BE 0.58 !!
> > > > We have discussed the topic many times in the past, a "HURST" 
> > > > research of this list archives will give more than 50 
> messages. 
> > > > 
> > > > 1a.
> > > > How do you use this code ?
> > > > 
> > > > 2. 
> > > > If you still want to use it, the code may be substantially 
> > shorter .
> > > > Example :
> > > > The part
> > > > 
> > > > mean8 = ValueWhen( BarsToEnd % 256 == 0, MA( in, 256 ), 0 );
> > > > mean7 = ValueWhen( BarsToEnd % 128 == 0, MA( in, 128 ), 0 );
> > > > mean6 = ValueWhen( BarsToEnd % 64 == 0, MA( in, 64 ), 0 );
> > > > mean5 = ValueWhen( BarsToEnd % 32 == 0, MA( in, 32 ), 0 );
> > > > mean4 = ValueWhen( BarsToEnd % 16 == 0, MA( in, 16 ), 0 );
> > > > mean3 = ValueWhen( BarsToEnd % 8 == 0, MA( in, 8 ), 0 );
> > > > dist8 = Cum( in - mean8 ) - ValueWhen( BarsToEnd % 256 == 0, 
> in-
> > > > mean8 );
> > > > dist7 = Cum( in - mean7 ) - ValueWhen( BarsToEnd % 128 == 0, 
> in-
> > > > mean7 );
> > > > dist6 = Cum( in - mean6 ) - ValueWhen( BarsToEnd % 64 == 0, 
in-
> > > > mean6 );
> > > > dist5 = Cum( in - mean5 ) - ValueWhen( BarsToEnd % 32 == 0, 
in-
> > > > mean5 );
> > > > dist4 = Cum( in - mean4 ) - ValueWhen( BarsToEnd % 16 == 0, 
in-
> > > > mean4 );
> > > > dist3 = Cum( in - mean3 ) - ValueWhen( BarsToEnd % 8 == 0, in-
> > > mean3 );
> > > > RS8 = ( HHV( dist8, 256 ) - LLV( dist8, 256 ) ) / StDev( in , 
> > 256 );
> > > > RS7 = ( HHV( dist7, 128 ) - LLV( dist7, 128 )) / StDev( in , 
> > 128 );
> > > > RS6 = ( HHV( dist6, 64 ) - LLV( dist6, 64 )) / StDev( in , 
> 64 );
> > > > RS5 = ( HHV( dist5, 32 ) - LLV( dist5, 32 )) / StDev( in , 
> 32 );
> > > > RS4 = ( HHV( dist4, 16 ) - LLV( dist4, 16 )) / StDev( in , 
> 16 );
> > > > RS3 = ( HHV( dist3, 8 ) - LLV( dist3, 8 )) / StDev( in , 8 );
> > > > 
> > > > may be written
> > > > 
> > > > for(i=3;i<=8;i++)
> > > > {
> > > > VarSet("mean"+i,ValueWhen( BarsToEnd % 2^i == 0, MA( in, 
> 2^i ), 
> > > 0 ));
> > > > VarSet("dist"+i,Cum( in - VarGet("mean"+i) ) - ValueWhen( 
> > BarsToEnd 
> > > % 
> > > > 2^i == 0, in-VarGet("mean"+i) ));
> > > > VarSet("RS"+i,( HHV( VarGet("dist"+i), 2^i ) - LLV( VarGet
> > > ("dist"+i), 
> > > > 2^i ) ) / StDev( in , 2^i ));
> > > > }
> > > > RS8=VarGet("RS8");
> > > > RS7=VarGet("RS7");
> > > > RS6=VarGet("RS6");
> > > > RS5=VarGet("RS5");
> > > > RS4=VarGet("RS4");
> > > > RS3=VarGet("RS3");
> > > > 
> > > > You may continue for the rest of the code in this way. 
> > > > It is always interesting to see 10 code lines instead of an 
A4 
> > page.
> > > > [ If you are interested, I will do the rest of the code for 
> you 
> > > some 
> > > > other time ]
> > > > 3.
> > > > The "Chaos Hypertextbook" is interesting. I will translate it 
> in 
> > > AFL 
> > > > someday. I hope Glenn Elert will be also happy, since the 
fair 
> > use 
> > > is 
> > > > encouraged [in one way or the other I will ask his 
> > > opinion/permission]
> > > > 
> > > > Dimitris
> > > > 
> > > > 
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "Hans" <hansib@xxxx> wrote:
> > > > > 
> > > > > Hello Dimitris,
> > > > > 
> > > > > here is the code for the exploration of Hurst Exponent:
> > > > > 
> > > > > // we use logarithmic returns
> > > > > in =ln(Close/Ref(Close,-1));
> > > > > 
> > > > > BarsToEnd = LastValue( BarIndex() ) - BarIndex();
> > > > > 
> > > > > // calculate R/S statistics
> > > > > // for last 256 bars. We divide this period into
> > > > > // 1 region of 256 bars
> > > > > // 2 regions of 128 bars
> > > > > // 4 regions of 64 bars
> > > > > // 8 regions of 32 bars
> > > > > // 16 regions of 16 bars
> > > > > // 32 regions of 8 bars
> > > > > // (63 regions in total)
> > > > > 
> > > > > mean8 = ValueWhen( BarsToEnd % 256 == 0, MA( in, 256 ), 0 );
> > > > > mean7 = ValueWhen( BarsToEnd % 128 == 0, MA( in, 128 ), 0 );
> > > > > mean6 = ValueWhen( BarsToEnd % 64 == 0, MA( in, 64 ), 0 );
> > > > > mean5 = ValueWhen( BarsToEnd % 32 == 0, MA( in, 32 ), 0 );
> > > > > mean4 = ValueWhen( BarsToEnd % 16 == 0, MA( in, 16 ), 0 );
> > > > > mean3 = ValueWhen( BarsToEnd % 8 == 0, MA( in, 8 ), 0 );
> > > > > 
> > > > > dist8 = Cum( in - mean8 ) - ValueWhen( BarsToEnd % 256 == 
0, 
> in-
> > > > > mean8 );
> > > > > dist7 = Cum( in - mean7 ) - ValueWhen( BarsToEnd % 128 == 
0, 
> in-
> > > > > mean7 );
> > > > > dist6 = Cum( in - mean6 ) - ValueWhen( BarsToEnd % 64 == 0, 
> in-
> > > > > mean6 );
> > > > > dist5 = Cum( in - mean5 ) - ValueWhen( BarsToEnd % 32 == 0, 
> in-
> > > > > mean5 );
> > > > > dist4 = Cum( in - mean4 ) - ValueWhen( BarsToEnd % 16 == 0, 
> in-
> > > > > mean4 );
> > > > > dist3 = Cum( in - mean3 ) - ValueWhen( BarsToEnd % 8 == 0, 
> in-
> > > > mean3 );
> > > > > 
> > > > > // calculate RS statistics for all regions
> > > > > 
> > > > > RS8 = ( HHV( dist8, 256 ) - LLV( dist8, 256 ) ) / StDev( 
> in , 
> > > 256 );
> > > > > RS7 = ( HHV( dist7, 128 ) - LLV( dist7, 128 )) / StDev( 
in , 
> > > 128 );
> > > > > RS6 = ( HHV( dist6, 64 ) - LLV( dist6, 64 )) / StDev( in , 
> 64 );
> > > > > RS5 = ( HHV( dist5, 32 ) - LLV( dist5, 32 )) / StDev( in , 
> 32 );
> > > > > RS4 = ( HHV( dist4, 16 ) - LLV( dist4, 16 )) / StDev( in , 
> 16 );
> > > > > RS3 = ( HHV( dist3, 8 ) - LLV( dist3, 8 )) / StDev( in , 
8 );
> > > > > 
> > > > > // calculate average RS is corresponding regions
> > > > > 
> > > > > ARS8 = RS8;
> > > > > ARS7 = ( RS7 + Ref( RS7, -128 ) ) / 2;
> > > > > ARS6 = ( RS6 + 
> > > > > Ref( RS6, -64 ) + Ref( RS6, -128 ) + 
> > > > > Ref( RS6, -192) ) / 4;
> > > > > ARS5 = ( RS5 + 
> > > > > Ref( RS5, -32 ) + Ref( RS5, -64 ) + 
> > > > > Ref( RS5, -96 ) + Ref( RS5, -128 ) +
> > > > > Ref( RS5, -160 ) + Ref( RS5, -192 ) +
> > > > > Ref( RS5, -224 ) ) / 8;
> > > > > ARS4 = ( RS4 + 
> > > > > Ref( RS4, -16 ) + Ref( RS4, -32 ) + 
> > > > > Ref( RS4, -48 ) + Ref( RS4, -64 ) + 
> > > > > Ref( RS4, -80 ) + Ref( RS4, -96 ) +
> > > > > Ref( RS4, -112 ) + Ref( RS4, -128 ) +
> > > > > Ref( RS4, -144 ) + Ref( RS4, -160 ) +
> > > > > Ref( RS4, -176 ) + Ref( RS4, -192 ) +
> > > > > Ref( RS4, -208 ) + Ref( RS4, -224 ) +
> > > > > Ref( RS4, -240 ) ) / 16;
> > > > > 
> > > > > ARS3 = ( RS3 + 
> > > > > Ref( RS3, -8 ) + Ref( RS3, -16 ) + 
> > > > > Ref( RS3, -24 ) + Ref( RS3, -32 ) + 
> > > > > Ref( RS3, -40 ) + Ref( RS3, -48 ) + 
> > > > > Ref( RS3, -56 ) + Ref( RS3, -64 ) + 
> > > > > Ref( RS3, -72 ) + Ref( RS3, -80 ) +
> > > > > Ref( RS3, -88 ) + Ref( RS3, -96 ) + 
> > > > > Ref( RS3, -104 ) + Ref( RS3, -112 ) + 
> > > > > Ref( RS3, -120 ) + Ref( RS3, -128 ) + 
> > > > > Ref( RS3, -136 ) + Ref( RS3, -144 ) + 
> > > > > Ref( RS3, -152 ) + Ref( RS3, -160 ) + 
> > > > > Ref( RS3, -168 ) + Ref( RS3, -176 ) + 
> > > > > Ref( RS3, -184 ) + Ref( RS3, -192 ) + 
> > > > > Ref( RS3, -200 ) + Ref( RS3, -208 ) + 
> > > > > Ref( RS3, -216 ) + Ref( RS3, -224 ) + 
> > > > > Ref( RS3, -232 ) + Ref( RS3, -240 ) + 
> > > > > Ref( RS3, -248 ) ) / 32;
> > > > > 
> > > > > // calculate Hurst exponent as a linear regression slope
> > > > > // of Log2( AvgRS )/ Log2( region size )
> > > > > 
> > > > > Y8 = log( ARS8 )/log( 2 );
> > > > > Y7 = log( ARS7 )/log( 2 );
> > > > > Y6 = log( ARS6 )/log( 2 );
> > > > > Y5 = log( ARS5 )/log( 2 );
> > > > > Y4 = log( ARS4 )/log( 2 );
> > > > > Y3 = log( ARS3 )/log( 2 );
> > > > > 
> > > > > Sumx = 3+4+5+6+7+8; // sum of log2( region size )
> > > > > Sumy = Y8 + Y7 + Y6 + Y5 + Y4 + Y3; // sum of log2( AvgRS )
> > > > > sumxy = 8*Y8 + 7*Y7 + 6*Y6 + 5*Y5 + 4*Y4 + 3*Y3;
> > > > > Sumx2 = 3*3 + 4*4 + 5*5 + 6*6 + 7*7 + 8*8;
> > > > > 
> > > > > // the slope of linear regression from R/S
> > > > > // is the estimate of Hurst exponent
> > > > > b=( 6 * sumxy - sumx*sumy )/( 6 * sumx2 - sumx*sumx); 
> > > > > Hurst = b;
> > > > > Filter = BarsToEnd == 0;
> > > > > AddColumn( Close, "Close", 1.5 );
> > > > > AddColumn( Hurst, "Hurst Exponent", 1.5);
> > > > > AddColumn( 2-Hurst, "Fractal Dim", 1.5 );
> > > > > /*
> > > > > there is also another aersion of hurst calculation at 
> > > > > http://www.amibroker.com/library/detail.php?id=65
> > > > > 
> > > > > I hope this could be a good start
> > > > > 
> > > > > --- In amibroker@xxxxxxxxxxxxxxx, "DIMITRIS TSOKAKIS" 
> > > > <TSOKAKIS@xxxx> 
> > > > > wrote:
> > > > > > 
> > > > > > ...
> > > > > > Aleksandr Mikhailovich Lyapunov
> > > > > > He was born 6 June 1857 in Yaroslavl (Russia) and died 3 
> > > November 
> > > > > > 1918 in Odessa (he committed suicide three days after the 
> > death 
> > > > of 
> > > > > > his wife).
> > > > > > ...
> > > > > > This would probably be a start for this interesting 
> > discussion. 
> > > > The 
> > > > > > topic is fairly advanced and I do not know if it is 
> > interesting 
> > > > for 
> > > > > > the readers of this list.
> > > > > > Hans,
> > > > > > Since you already have the AFL code for Hurst Exponent, 
> post 
> > it 
> > > > > > together with a short description for the use to begin 
> with.
> > > > > > Dimitris 
> > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "Hans" <hansib@xxxx> 
> wrote:
> > > > > > > Dear group members,
> > > > > > > 
> > > > > > > I would like to calculate Lyapunov exponent as 
> exploration.
> > > > > > > 
> > > > > > > Please find in this page some reference and formula:
> > > > > > > http://www.iqnet.cz/dostal/CHA1.htm
> > > > > > > 
> > > > > > > Is anyone of you able (and so kind) to build the code 
> for 
> > > > > Amibroker 
> > > > > > > starting from the linked formula?
> > > > > > > (NOTE: I have already the code for Hurst Exponent).
> > > > > > > 
> > > > > > > many thanks!
> > > > > > > 
> > > > > > > PS maybe Dimitri has already some code. ;)





------------------------ 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/