MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Creating a Moving Average Function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg51626] Re: [mg51615] Creating a Moving Average Function
  • From: DrBob <drbob at bigfoot.com>
  • Date: Wed, 27 Oct 2004 23:42:13 -0400 (EDT)
  • References: <200410270554.BAA24573@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

MA[theSeries_,theWindowSize_]:=PadLeft[MovingAverage[theSeries,theWindowSize],
       Length@theSeries];
Range@10
MA[Range@10,3]

{1,2,3,4,5,6,7,8,9,10}

{0,0,2,3,4,5,6,7,8,9}

That seems to do what you asked for.

Why did you have the constant 1000 hardwired in your version?

Bobby

On Wed, 27 Oct 2004 01:54:37 -0400 (EDT), Gregory Lypny <gregory.lypny at videotron.ca> wrote:

> Hello Everyone,
>
> I'd like to create some custom moving average functions that retain the
> same length as the original series by padding the lost observations
> with zeros.  I can get the moving average part of the function to work
> but not the padding part.
>
> This part without padding works:
>
> MA[theSeries_, theWindowSize_] = MovingAverage[theSeries,
>      theWindowSize];
>
> But adding the padding causes it to fail:
>
> MA[theSeries_, theWindowSize_] = PadLeft[MovingAverage[theSeries,
>      theWindowSize], 1000];
>
> Any suggestions would be most appreciated.
>
> 	Greg
>
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: Another bizarre phenomenon
  • Next by Date: Re: Help with a calculation
  • Previous by thread: Creating a Moving Average Function
  • Next by thread: Re: Creating a Moving Average Function