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

[EquisMetaStock Group] Re: Power( DataArray, VariablePower ) - now geometric means for the people!



PureBytes Links

Trading Reference Links


I gotta find a better brew of stimulus! :-)

Preston



--- In equismetastock@xxxxxxxxxxxxxxx, "MG Ferreira" <quant@xxxx> 
wrote:
> 
> 
> (peeping carefully from my cubicle....)
> 
> Just a note, we are neither calculating a simple nor an exponential
> moving average with
> 
> > > x1:=Exp(Sum(Log(y),n)/n);
> > > x2:=Exp(Mov(Log(y),n,S));
> 
> They should yield the same result, I suspect the difference between
> the two are due to rounding.
> 
> What we are calculating here is the *geometric* average.  How to
> interpret this?  It is especially easy if you are working with 
return
> or interest rates.  Say Jose invests 100 AUD in one of our systems 
and
> we do not charge any fees for that (insert chuckle here somewhere). 
> Suppose the returns he gets from this system are as follows in the
> next 10 bars:
> 
>     1%, 2%, 3%, 4%, 5%, 6%, 7%, 8%, 9%, 10%
> 
> Now, to get to the final amount he would have in the account, you 
can
> calculate it as follows:
> 
>     100 x 1.01 x 1.02 x 1.03 x 1.04 x 1.05 x 1.06 x 1.07 x 1.08 x 
1.09
> x 1.10 = 170.2
> 
> So at the end he has 170.2 in the account.  What was the average
> return that he got per bar?  We could calculate the average of 1, 2,
> ... 10 to get 5.5%.  However, if we apply 5.5% per bar, we get an
> overstated return of
> 
>     100 x 1.055 x 1.055 x 1.055 x ... x 1.055 = 170.81
> 
> This is a small difference in this example, but next time a 
consultant
> shows you 'linear' return figures, know he is overstating things!  
We
> once had a guy trying to sell us some investment where he used this
> method to get returns in line with what the market offered on some 5
> year plan.  If you calculated it correctly, as shown next, the 
return
> was quite a bit less.....
> 
> How do we get the actual return?  We calculate the geometric average
> as discussed before, as follows:
> 
>   ( 1.01 x 1.02 x 1.03 ... x 1.10 ) ^ ( 1 / 10 )
> 
> or, using the method discussed before,
> 
>   exp [ ( ln 1.01 + ln 1.02 + ln 1.03 + ... + ln 1.10 ) / 10 ]
> 
> which yields 1.054609 or 5.46% per bar - quite a bit less than the
> salesman's 5.5%!  Applying 5.46% for ten bars also correctly yields
> the actual return of 170.2 (roughly, depending on how many digits 
you
> ignored after the decimal....should be accurate if you use them 
all).
> 
> How can we use this in the market?  Say you have a YTM series (bond
> rates, for those who do not know what YTM stands for).  If you
> calculate the geometric mean of the yield, say
> 
> n   := Input( "Period length", 1, 1000, 21 );
> YTM := 1 + C / 100;              {To convert 5.43 to 1.0543}
> GM  := Exp(Mov(Log(YTM),n,S));   {Geometric mean}
> 100 * ( GM - 1 )                 {Convert 1.0543 back to 5.43}
> 
> you get the 'average' return that the bond yielded during the past n
> days.  If you had the bond the whole time, this is the return (pa)
> that you received per day and you can compare it to say the federal
> funds rate or whatever during this time.
> 
> To do the same thing for prices is actually very easy, since you
> simply compare the final period price to the starting one and
> calculate how much it has risen on average, percentage wise, per day
> to get to the final.  In math we have
> 
> yn = y0 x [ ( 1 + r / 100 ) ^ n ]
> 
> and we are looking for r.  This reduces to
> 
> r = 100 x [ ( yn / y0 ) ^ ( 1 / n ) - 1 ]
> 
> which gives the average percentage increase.  Using log and exp and
> OTC MSFL (Off The Cuff MSFL) this then simply becomes
> 
> n     := Input( "Period length", 1, 1000, 21 );
> AVRET := 100 * ( Exp( Log( C / Ref( C, -n ) ) / n ) - 1 );
> AVRET
> 
> and it plots the average percentage returns, per bar, that a price
> yielded over the past n bars.
> 
> (Whoooop - I am back inside.....)
> 
> Regards
> MG Ferreira
> TsaTsa EOD Programmer and trading model builder
> http://www.ferra4models.com
> http://fun.ferra4models.com
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> --- In equismetastock@xxxxxxxxxxxxxxx, "Jose Silva" 
<josesilva22@xxxx>
> wrote:
> > 
> > > Comparing that to a 12EMA...
> > > From my perspective, X1 and X2 actually appear smoother.
> > 
> > So they should, Preston - both x1 & x2 are SMAs (Simple Moving 
> > Averages).  Same data/period SMAs are always smoother than EMAs.
> > 
> > There is little or no benefit in using Exp/Log over Mov(DataArray,
> > Periods,S).
> > 
> > 
> > jose '-)
> > 
> > 
> > --- In equismetastock@xxxxxxxxxxxxxxx, pumrysh <no_reply@xxxx> 
wrote:
> > > 
> > > MG,Jose,
> > > 
> > > Not so quick to the cubicle!
> > > There was a coding error. The fix is below:
> > > y:=C;
> > > n:=12;
> > > x1:=Exp(Sum(Log(y),n)/n);
> > > x2:=Exp(Mov(Log(y),n,S));
> > > x1;x2
> > > 
> > > That being said, there is a slight difference between x1 and x2 
when 
> > > compared. Comparing that to a 12EMA of the close there is still 
> > > another difference. From my perspective, X1 and X2 actually 
appear 
> > > smoother. So we have a new way of writing an exponential moving 
> > > average. 
> > > 
> > > Finally, MG I've used the sum method to derive a SMA before.
> > > I always enjoy new methods of writing moving averages. 
> > > 
> > > Thanks to both of you for the mental stimulus.
> > > 
> > > Preston
> > > 
> > > 
> > > --- In equismetastock@xxxxxxxxxxxxxxx, "Jose Silva" 
> > > <josesilva22@xxxx> wrote:
> > > > 
> > > > > 1000 * exp( Cum( log( y / 1000 ) ) )
> > > > 
> > > > In *theory*, this would be quite useful in accumulating large 
> > > values  
> > > > (such as Volume), but unfortunately MetaStock cannot handle 
large 
> > > > values for the Exp() function, so there is no advantage here.
> > > > 
> > > > Here is an example:
> > > > Exp(Cum(Log(V/1000)))*1000
> > > > 
> > > > 
> > > > > Exp( Sum( Log( y ), n ) / n )
> > > > > or simply
> > > > > Exp( Mov( Log( y, n, S ) ) )
> > > > 
> > > > Neither of these is an improvement on Mov(y,n,S).
> > > > 
> > > > 
> > > > MG, back to your modeling cubicle with you...
> > > > 
> > > > 
> > > > jose '-)
> > > > http://www.metastocktools.com
> > > > 
> > > > 
> > > > 
> > > > --- In equismetastock@xxxxxxxxxxxxxxx, "MG Ferreira" 
<quant@xxxx> 
> > > > wrote:
> > > > > 
> > > > > OK, here is a quick, off the cuff example.  The Cum function
> > > > > 
> > > > > Cum(y)
> > > > > 
> > > > > gives
> > > > > 
> > > > > y1 + y2 + y3 + ...
> > > > > 
> > > > > What if you want
> > > > > 
> > > > > y1 * y2 * y3 * ...
> > > > > 
> > > > > Well, use
> > > > > 
> > > > > exp( Cum( log( y ) )
> > > > > 
> > > > > This will generally give an overflow quickly, unless you use
> > > > > smallish values, so you may need to rescale it to get it to 
> > work,
> > > > > ie calculate
> > > > > 
> > > > > 1000 * exp( Cum( log( y / 1000 ) ) )
> > > > > 
> > > > > If you think the Cum function is useful, then this must 
appeal 
> > to
> > > > > you as well!
> > > > > 
> > > > > Another example, the geometric average.  The simple moving 
> > average
> > > > > is defined as
> > > > > 
> > > > > ( y1 + y2 + y3 + ... + yn ) / n
> > > > > 
> > > > > Of course, in MSFL we all use
> > > > > 
> > > > > Mov(y,n,S)
> > > > > 
> > > > > to calculate this, but we could also use
> > > > > 
> > > > > Sum(y,n) / n
> > > > > 
> > > > > to get the answer the brute-force way.
> > > > > 
> > > > > The geometric moving average, which may actually be more 
> > > applicable
> > > > > to markets due to the exponential growth often seen in 
prices,
> > > > > is defined as
> > > > > 
> > > > > ( y1 x y2 x y3 x ... x yn ) ^ ( 1 / n )
> > > > > 
> > > > > To do this in MSFL, use
> > > > > 
> > > > > Exp( Sum( Log( y ), n ) / n )
> > > > > 
> > > > > or simply
> > > > > 
> > > > > Exp( Mov( Log( y, n, S ) ) )
> > > > > 
> > > > > Regards
> > > > > MG Ferreira
> > > > > TsaTsa EOD Programmer and trading model builder
> > > > > http://www.ferra4models.com
> > > > > http://fun.ferra4models.com





------------------------ Yahoo! Groups Sponsor --------------------~--> 
In low income neighborhoods, 84% do not own computers.
At Network for Good, help bridge the Digital Divide!
http://us.click.yahoo.com/EpW3eD/3MnJAA/cosFAA/BefplB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/equismetastock/

<*> To unsubscribe from this group, send an email to:
    equismetastock-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/