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

Re: your _sma3 (some interesting things)



PureBytes Links

Trading Reference Links

Alex,

the relationship between L and N is mainly for you and your understanding when 
you compare your _sma3(L) to a simpleMovingAverage(L). You have to define N 
because the other two coefficients are depending on N and you can do this 
either by defining N itself or by defining L and R so that R*L = N 
I say this because I have found some interesting and surprising relations, 
which becomes clear if you focus on N:

First let's move the 'origin' of your _sma3-Filter from L to N.

This is your original with N = R*L:
	_sma3(L) = avg( avg( avg(Signal, rnd(N), rnd(N/1.25)), rnd(N/1.5) ),
or
	sma3(N/R) = avg( avg( avg(Signal, rnd(N), rnd(N/1.25)), rnd(N/1.5) ),

Let me write (we'll see later, why) your filter:
	_sma3(a/R) = avg( avg( avg(Signal, c), a), b);
So c=N and L becomes:
	L = rnd(c/R) (now you select c to that L meet your needs).

Now (as I wrote to you):
	a = rnd( c/1.25 ) = rnd( 0.80*c ) = rnd( c*4/5 )
and
	b = rnd( c/1.50 ) = rnd( 0.6667*c) = rnd (c*2/3)

Now if you set R = 0.75, c=5 (L = 5/0.75 = 6.667) you get for a, b: 4,  3:
	_sma3(6.667) = avg( avg( avg(Signal, 5), 4), 3).

These are Phythagoras' numbers from his theorem of the right-angled triangle: 
The square of the long side (hypotenuse) is equal to the sum of the squared 
short sides (cathetus) 
	c² = a² + b² (that's how we wrote it in school)
- WOW. (I have no idea, if this is just accedentally so or it has some meaning 
in the context of filtering noises, but it inspires)

But the relationship
	c, a=c*4/5, b=c*2/3
does not leed exactly to the Phythagoras' numbers, for this the relationship 
the calculus should be:
	c, 
	a = c*4/5 = c*0.8, 
	b = c*3/5 = c*0.6
	( 1^2 = 0.8^2 + 0.6^2 => 1 = 0.64 + 0.36 )

so that the filter becomes
	_sma3( a/0.75 ) = avg( avg( avg(Signal, c), rnd(0.8*a)), rnd(b*0.6))

Hmm, now I would like to ask you, Bob, as you had posted the *.gifs with the 
'saw blade' quotes applied to Alex' filter, to compare both variations, if 
there is a difference, may be you can vary a bit with the coefficients 0.8 
and 0.6. Might be interesting.

Carl



Am Montag, 14. Juni 2004 01:13 schrieb Alex Matulich:
> > playing around with your formulas I found this (maybe you allready know
> > this):
> >
> > L is the length, from there you calc the N = int(0.5 + L*0.75), now
> > b=int(a/1.25), c=a/1.5, finally the sum of all (see the tab below, as
> > higher  L is as more precise no. I get)
> >
> > So you can calc your formula as:
> > 	N=int(0.5 + 0.75*L)
> > 	b=int(0.5 + 0.60*L)
> > 	c=int(0.5 + 0.50*L)
> > and you have (without rounding):
> > 	_SMA3 = avg( avg( avg(Sig, 0.75*L), 0.60*L), 0.50*L).
>
> You're missing something.  There's a reason to keep that original 0.75
> isolated.  The factors 1.25 and 1.5 are the moving average tuning factors
> that control the phase cancellation, resulting in a steep roll-off in
> frequency response.  Let's define R=0.75.  Then the formula is:
>
>  	_SMA3 = avg( avg( avg(Sig, R*L), R*L/1.25), R*L/1.5).
>
> R determines the rolloff point, and ultimately the lag.  For example, if
> you want the _SMA3 of length L to have the same lag as a simple moving
> average of length L, you would use R=0.42 instead of R=0.75.  The number
> 0.75 was chosen to have 20 dB of attenuation at wavelength L -- a purely
> arbitrary choice.
>
> R is actually another input parameter, just like L.  In my original code,
> I simply embedded it.  I actually find R=0.42 to be more useful.
>
> -Alex