Questions tagged [moving-average]

A calculation of the average value of the most recent (within some window) values in a time series, rather than the average of the entire series.

Moving average is a calculation of the average value of the most recent (within some window) values in a time series, rather than the average of the entire series.

1034 questions
24
votes
16 answers

How to calculate simple moving average faster in C#?

What is the fastest library/algorithm for calculating simple moving average? I wrote my own, but it takes too long on 330 000 items decimal dataset. period / time(ms) 20 / 300; 60 / 1500; 120 / 3500. Here is the code of my method: public…
zozed
  • 343
  • 1
  • 2
  • 5
23
votes
1 answer

Add Moving average plot to time series plot in R

I have a plot of time series in ggplot2 package and I have performed the Moving average and I would like to add the result of moving average to the plot of time series. Sample of Data-set (p31): ambtemp dt -1.14 2007-09-29…
A.Amidi
  • 2,502
  • 5
  • 25
  • 37
22
votes
4 answers

Moving Average based on Timestamps in PostgreSQL

I wanted to perform moving average through timestamps. I have two columns: Temperature and timestamps (time-date) and I want to perform the moving average based on every 15 minutes successive temperature observations. In other words, selecting data…
A.Amidi
  • 2,502
  • 5
  • 25
  • 37
21
votes
4 answers

Does Pandas calculate ewm wrong?

When trying to calculate the exponential moving average (EMA) from financial data in a dataframe it seems that Pandas' ewm approach is incorrect. The basics are well explained in the following…
jeronimo
  • 241
  • 1
  • 2
  • 5
19
votes
2 answers

T-SQL calculate moving average

I am working with SQL Server 2008 R2, trying to calculate a moving average. For each record in my view, I would like to collect the values of the 250 previous records, and then calculate the average for this selection. My view columns are as…
RunW
  • 269
  • 1
  • 2
  • 12
19
votes
1 answer

Numpy Two-Dimensional Moving Average

I have a 2d numpy array. I want to take the average value of the n nearest entries to each entry, just like taking a sliding average over a one-dimensional array. What is the cleanest way to do this?
Sean Mackesey
  • 10,701
  • 11
  • 40
  • 66
18
votes
3 answers

Adaptive moving average - top performance in R

I am looking for some performance gains in terms of rolling/sliding window functions in R. It is quite common task which can be used in any ordered observations data set. I would like to share some of my findings, maybe somebody would be able to…
jangorecki
  • 16,384
  • 4
  • 79
  • 160
17
votes
8 answers

LINQ to calculate a moving average of a SortedList

I have a time series in the form of a SortedList. I would like to calculate a moving average of this series. I can do this using simple for loops. I was wondering if there is a better way to do this using linq. my version: using…
Andre P.
  • 613
  • 1
  • 7
  • 21
17
votes
2 answers

Replace NaN or missing values with rolling mean or other interpolation

I have a pandas dataframe with monthly data that I want to compute a 12 months moving average for. Data for for every month of January is missing, however (NaN), so I am using pd.rolling_mean(data["variable"]), 12, center=True) but it just gives me…
Alexis Eggermont
  • 7,665
  • 24
  • 60
  • 93
16
votes
3 answers

Moving average of previous three values in R

In the zoo package there is a function called rollmean, which enables you to make moving averages. The rollmean(x,3) will take the previous, current and next value (ie 4, 6 and 2) in the table below. This is shown in the second column. x …
Jochem
  • 3,295
  • 4
  • 30
  • 55
16
votes
13 answers

SQL moving average

How do you create a moving average in SQL? Current table: Date Clicks 2012-05-01 2,230 2012-05-02 3,150 2012-05-03 5,520 2012-05-04 1,330 2012-05-05 2,260 2012-05-06 3,540 2012-05-07 …
Don P
  • 60,113
  • 114
  • 300
  • 432
14
votes
3 answers

Numpy Root-Mean-Squared (RMS) smoothing of a signal

I have a signal of electromyographical data that I am supposed (scientific papers' explicit recommendation) to smooth using RMS. I have the following working code, producing the desired output, but it is way slower than I think it's…
heltonbiker
  • 26,657
  • 28
  • 137
  • 252
13
votes
4 answers

Calculating moving average in C++

I am trying to calculate the moving average of a signal. The signal value ( a double ) is updated at random times. I am looking for an efficient way to calculate it's time weighted average over a time window, in real time. I could do it my self,…
0x26res
  • 11,925
  • 11
  • 54
  • 108
13
votes
3 answers

pine script with two indicators one overlaid on the chart and another on its own?

I am trying to write a pine script with two indicators one overlaid on the chart (EMA) and another on its own?(Stoch) I cannot seem to find any info on how to separate these (Visually) but keep them within 1 pine script, ie to be able to take…
Brandon Saccone
  • 139
  • 1
  • 1
  • 3
13
votes
2 answers

rolling average to multiple variables in R using data.table package

I would like to get rolling average for each of the numeric variables that I have. Using data.table package, I know how to compute for a single variable. But how should I revise the code so it can process multiple variables at a time rather than…
Vicki1227
  • 151
  • 1
  • 3
  • 10
1
2
3
68 69