exponential moving average with a varying exponents.
- To: mathgroup at smc.vnet.net
- Subject: [mg98433] exponential moving average with a varying exponents.
- From: Andreas <aagas at ix.netcom.com>
- Date: Thu, 9 Apr 2009 05:58:46 -0400 (EDT)
I have a function with calculates an exponential moving average with a varying exponent. EMAVariableExponent[data_, exponents_]:=Module[{ema}, ema = {data[[1]]}; Do[ema =Append[ema,ema[[t-1]] + exponents[[t]] * (data[[t]] - ema[[t-1]])], {t,2,Length[data]}] ]; You supply the function with a list of data and with a list of exponents used at each step in the calculations. This seems to work OK but I'd like to replace it with a clearer and more elegant functional construct. I wish ExponentialMovingAverage[] could take a list of exponents rather than a constant, something like: ExponentialMovingAverage[list, exponentList] I tried the following to try to Map an ExponentialMovingAverage[] across the list of exponents. ExponentialMovingAverage[data, #]&/@ exponents but it gives me a list of lists, each of which has mapped each exponent in exponents to the list of data. Any suggestions much appreciated.