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

[EquisMetaStock Group] Re: Power( DataArray, VariablePower ) MS function



PureBytes Links

Trading Reference Links


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



--- In equismetastock@xxxxxxxxxxxxxxx, "MG Ferreira" <quant@xxxx> wrote:
> 
> Thanks for your kind words!  The ln and exp has many uses, one is to
> determine sums of stuff that is otherwise very difficult to calculate
> or that gives rise to overflows.  I don't have an example handy, but
> will post one when it comes to mind.  I think you can calculate
> geometric averages this way for one, or use it to calculate very
> accurate, time weighted return figures.  The beauty of it is locked up
> in the fact that
> 
> log( a x b ) = log( a ) + log( b )
> 
> and
> 
> log ( a ^ b ) = b log ( a )
> 
> and you can write books just on this and the indicators you can derive
> from it.  After applying this, just use exp to get back to 'real'
> values, since exp( log( a ) ) = a ... <tonk>
> 
> 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:
> > 
> > Excellent, MG.
> > 
> > Here is the MetaStock code version:
> > 
> > ================
> > Power - variable
> > ================
> > ---8<--------------------
> > 
> > { Power(DataArray,VariablePower) MS function }
> > { With thanks to MG Ferreira }
> > { http://www.metastocktools.com }
> > 
> > DataArray:=C;
> > VariablePower:=DataArray/Mov(DataArray,63,S);
> > VarPower:=Exp(Log(DataArray)*VariablePower);
> > 
> > VarPower
> > 
> > ---8<--------------------
> > 
> > 
> > jose '-)
> > http://www.metastocktools.com
> > 
> > 
> > 
> > --- In equismetastock@xxxxxxxxxxxxxxx, "MG Ferreira" <quant@xxxx>
> > > wrote:
> > > 
> > > Hi Jose,
> > > 
> > > As in the reply to Eric, if you want x = a ^ b, use something like
> > > 
> > > x := Exp( b * Log( a ) )
> > > 
> > > Please, I am sidestepping one of your rules here, so just test it
> > > before you use it!  It may be Ln in MSFL, I am not sure and can not
> > > test it from here.  Regarding the world economy, we are up to our
> > > ears in work regarding the local economy at the moment.  Must have
> > > something to do with sudden changes in interest rates.......  Of
> > > course our model predicted this, but we did not believe it.....
> > > 
> > > Regards
> > > MG Ferreira
> > > TsaTsa EOD Programmer and trading model builder
> > > http://www.ferra4models.com
> > > http://fun.ferra4models.com
> > > 
> > > 
> > > 
> > > --- In equismetastock@xxxxxxxxxxxxxxx, "Jose Silva" <josesilva22@xxx
> > .> wrote:
> > >
> > >> MSFL does not allow a time series as a parameter in the 'Power'
> > >> function.  So we have to use exps and lns.
> > > 
> > > MG, if you're not too busy modeling the World's economy, do you
know 
> > > of a simple way to use the Log() (natural Logarithm) and Exp() 
> > > functions to calculate Power(DataArray,VariablePower)?
> > > 
> > > Example:
> > > DataArray:=C;
> > > VarPower:=Mov(C,21,E)/C;
> > > Pwr(DataArray,VarPower) <-- only constant data allowed.
> > > 
> > > 
> > > jose '-)
> > > http://www.metastocktools.com





------------------------ Yahoo! Groups Sponsor --------------------~--> 
Has someone you know been affected by illness or disease?
Network for Good is THE place to support health awareness efforts!
http://us.click.yahoo.com/Rcy2bD/UOnJAA/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/