moving-average

Moving averages with MongoDB's aggregation framework?

会有一股神秘感。 提交于 2019-11-28 01:59:59
If you have 50 years of temperature weather data (daily) (for example) how would you calculate moving averages, using 3-month intervals, for that time period? Can you do that with one query or would you have to have multiple queries? Example Data 01/01/2014 = 40 degrees 12/31/2013 = 38 degrees 12/30/2013 = 29 degrees 12/29/2013 = 31 degrees 12/28/2013 = 34 degrees 12/27/2013 = 36 degrees 12/26/2013 = 38 degrees ..... The agg framework now has $map and $reduce and $range built in so array processing is much more straightfoward. Below is an example of calculating moving average on a set of data

How to calculate simple moving average faster in C#?

非 Y 不嫁゛ 提交于 2019-11-27 21:41:04
问题 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 decimal MA_Simple(int period, int ii) { if (period != 0 && ii > period) { //stp.Start(); decimal summ = 0; for (int i = ii; i > ii - period; i--) { summ = summ + Data.Close[i]; } summ = summ / period; //stp.Stop(); //if (ii == 1500) System.Windows.Forms

Add Moving average plot to time series plot in R

淺唱寂寞╮ 提交于 2019-11-27 18:35:26
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 00:01:57 -1.12 2007-09-29 00:03:57 -1.33 2007-09-29 00:05:57 -1.44 2007-09-29 00:07:57 -1.54 2007-09-29 00:09:57 -1.29 2007-09-29 00:11:57 Applied code for time series presentation: Require(ggplot2) library(scales) p29$dt=strptime(p31$dt, "%Y-%m-%d %H:%M:%S") ggplot(p29, aes(dt, ambtemp)) + geom_line() + scale_x_datetime(breaks = date_breaks("2 hour"),labels=date_format("%H:

Bigquery SQL for sliding window aggregate

你。 提交于 2019-11-27 16:40:23
问题 Hi I have a table that looks like this Date Customer Pageviews 2014/03/01 abc 5 2014/03/02 xyz 8 2014/03/03 abc 6 I want to get page view aggregates grouped by week but showing aggregates for past 30 days - (sliding window aggregates with window-size of 30 days for every week) I am using google bigquery EDIT: Gordon - re your comment about "Customer", Actually what I need is slightly more complicated thats why I included customer in the table above. I am looking to get the number of customers

How can I (efficiently) compute a moving average of a vector?

时光总嘲笑我的痴心妄想 提交于 2019-11-27 14:08:55
问题 I've got a vector and I want to calculate the moving average of it (using a window of width 5). For instance, if the vector in question is [1,2,3,4,5,6,7,8] , then the first entry of the resulting vector should be the sum of all entries in [1,2,3,4,5] (i.e. 15 ); the second entry of the resulting vector should be the sum of all entries in [2,3,4,5,6] (i.e. 20 ); etc. In the end, the resulting vector should be [15,20,25,30] . How can I do that? 回答1: The conv function is right up your alley: >>

Moving Average- Pandas

只谈情不闲聊 提交于 2019-11-27 13:55:50
I would like to add a moving average calculation to my exchange time series. Original data from Quandl Exchange = Quandl.get("BUNDESBANK/BBEX3_D_SEK_USD_CA_AC_000", authtoken="xxxxxxx") Value Date 1989-01-02 6.10500 1989-01-03 6.07500 1989-01-04 6.10750 1989-01-05 6.15250 1989-01-09 6.25500 1989-01-10 6.24250 1989-01-11 6.26250 1989-01-12 6.23250 1989-01-13 6.27750 1989-01-16 6.31250 Calculating Moving Avarage MovingAverage = pd.rolling_mean(Exchange,5) Value Date 1989-01-02 NaN 1989-01-03 NaN 1989-01-04 NaN 1989-01-05 NaN 1989-01-09 6.13900 1989-01-10 6.16650 1989-01-11 6.20400 1989-01-12 6

How to efficiently compute average on the fly (moving average)?

为君一笑 提交于 2019-11-27 10:28:20
问题 I come up with this n=1; curAvg = 0; loop{ curAvg = curAvg + (newNum - curAvg)/n; n++; } I think highlights of this way are: - It avoids big numbers (and possible overflow if you would sum and then divide) - you save one register (not need to store sum) The trouble might be with summing error - but I assume that generally there shall be balanced numbers of round up and round down so the error shall not sum up dramatically. Do you see any pitfalls in this solution? Have you any better proposal

T-SQL calculate moving average

て烟熏妆下的殇ゞ 提交于 2019-11-27 08:53:46
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 follows: TransactionID | TimeStamp | Value | MovAvg ---------------------------------------------------- 1 | 01.09.2014 10:00:12 | 5 | 2 | 01.09.2014 10:05:34 | 3 | ... 300 | 03.09.2014 09:00:23 | 4 | TransactionID is unique. For each TransactionID , I would like to calculate the average for column value, over previous 250 records. So for TransactionID 300

Does Pandas calculate ewm wrong?

本秂侑毒 提交于 2019-11-27 08:09:07
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 link: http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:moving_averages When going to Pandas explanation, the approach taken is as follows (using the "adjust" parameter as False): weighted_average[0] = arg[0]; weighted_average[i] = (1-alpha) * weighted_average[i-1] + alpha * arg[i] This in my view is incorrect. The "arg" should be (for example) the closing values, however, arg[0

Computing a moving average

↘锁芯ラ 提交于 2019-11-27 06:25:37
问题 I need to compute a moving average over a data series, within a for loop. I have to get the moving average over N=9 days. The array I'm computing in is 4 series of 365 values (M), which itself are mean values of another set of data. I want to plot the mean values of my data with the moving average in one plot. I googled a bit about moving averages and the "conv" command and found something which i tried implementing in my code.: hold on for ii=1:4; M=mean(C{ii},2) wts = [1/24;repmat(1/12,11,1