3
$\begingroup$

If I have a time series s, and if you'll pardon the pseudo code, such that

s = {t_i, v_i}

is there an easy way to calculate the series

{t_i, Mean[s[[t_0 ;; t_i]]}

As I say this is pseudo code. In reality s is a TimeSeries object

s = TimeSeries[v,{t}]

I can generate a new TimeSeries object using MovingAverage with ease, but that is not what I require. What I do require is to create a TimeSeries object which is at time t the mean of values in the initial time series having a timestamp less than or equal to t

I could code this up for a simple sequence, but given MovingAverage is supported I was hoping for something similar for this case.

Thanks in advance

$\endgroup$
1

2 Answers 2

3
$\begingroup$

You may use Accumulateand TimeSeriesThread.

With

s = TimeSeries[{a, b, c}];

then

t = TimeSeriesThread[Apply[Divide], {Accumulate[s], Range@s["PathLength"]}];
t["Values"]

{ a , (a+b)/2 , (a+b+c)/3 }

Hope this helps.

$\endgroup$
0
$\begingroup$

Perhaps you are looking for TimeSeriesWindow:

{#, Mean@TimeSeriesWindow[ts, {tmin, #}]} & /@ tvalues
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.