moving-average

How to calculate a moving average in MySQL in a correlated subquery?

送分小仙女□ 提交于 2019-12-11 00:49:51
问题 I want to create a timeline report that shows, for each date in the timeline, a moving average of the latest N data points in a data set that has some measures and the dates they were measured. I have a calendar table populated with every day to provide the dates. I can calculate a timeline to show the overall average prior to that date fairly simply with a correlated subquery (the real situation is much more complex than this, but it can essentially be simplified to this): SELECT c.date , (

Pandas - moving average grouped by multiple columns

我是研究僧i 提交于 2019-12-10 20:37:38
问题 New to Pandas, so bear with me. My dataframe is of the format date,name,country,tag,cat,score 2017-05-21,X,US,free,4,0.0573 2017-05-22,X,US,free,4,0.0626 2017-05-23,X,US,free,4,0.0584 2017-05-24,X,US,free,4,0.0563 2017-05-21,X,MX,free,4,0.0537 2017-05-22,X,MX,free,4,0.0640 2017-05-23,X,MX,free,4,0.0648 2017-05-24,X,MX,free,4,0.0668 I'm trying to come up with a way to find the X day moving average within the country/tag/category group, so I need: date,name,country,tag,cat,score,moving_average

A moving average with different functions and varying time-frames

余生长醉 提交于 2019-12-10 19:51:23
问题 I have a matrix time-series data for 8 variables with about 2500 points (~10 years of mon-fri) and would like to calculate the mean, variance, skewness and kurtosis on a 'moving average' basis. Lets say frames = [100 252 504 756] - I would like calculate the four functions above on over each of the (time-)frames, on a daily basis - so the return for day 300 in the case with 100 day-frame, would be [mean variance skewness kurtosis] from the period day201-day300 (100 days in total)... and so on

rollapply time series in R (zoo) on backward looking data

只谈情不闲聊 提交于 2019-12-10 07:04:20
问题 I would like to use the zoo function rollapply to apply a function (for example mean) on a time series but only using the last N known points. For example: x = zoo(c(1,2,3,4), order.by=c(10,11,12,13)) rollmean(x,2) Produces: 10 11 12 1.5 2.5 3.5 I would like to produce a series that would have date entries of 11, 12, 13 and values of 1.5, 2.5, 3.5. The values seem correct but the dates that rollmean outputs don't seem to correspond to what I would like. I'm a bit worried about just assigning

Data structure/algorithm to efficiently save weighted moving average

我怕爱的太早我们不能终老 提交于 2019-12-09 18:50:23
问题 I'd like to sum up moving averages for a number of different categories when storing log records. Imagine a service that saves web server logs one entry at a time. Let's further imagine, we don't have access to the logged records. So we see them once but don't have access to them later on. For different pages, I'd like to know the total number of hits (easy) a "recent" average (like one month or so) a "long term" average (over a year) Is there any clever algorithm/data model that allows to

Calculating weighted moving average using pandas Rolling method

半城伤御伤魂 提交于 2019-12-09 07:03:25
问题 I calculate simple moving average: def sma(data_frame, length=15): # TODO: Be sure about default values of length. smas = data_frame.Close.rolling(window=length, center=False).mean() return smas Using the rolling function is it possible to calculate weighted moving average? As I read in the documentation, I think that I have to pass win_type parameter. But I'm not sure which one I have to choose. Here is a definition for weighted moving average. Thanks in advance, 回答1: Yeah, that part of

BIGQUERY moving average with missing values

Deadly 提交于 2019-12-08 07:00:31
问题 I have the following data with dummy_data as ( SELECT '2017-01-01' as ref_month, 18 as value, 1 as id UNION ALL SELECT '2017-02-01' as ref_month, 20 as value, 1 as id UNION ALL SELECT '2017-03-01' as ref_month, 22 as value, 1 as id -- UNION ALL SELECT '2017-04-01' as ref_month, 28 as value, 1 as id UNION ALL SELECT '2017-05-01' as ref_month, 30 as value, 1 as id UNION ALL SELECT '2017-06-01' as ref_month, 37 as value, 1 as id UNION ALL SELECT '2017-07-01' as ref_month, 42 as value, 1 as id --

C# MSChart Candle Stick & Moving Average Chart. Error: Formula error - There are not enough data points for the Period

廉价感情. 提交于 2019-12-08 05:06:39
问题 You cannot vote on your own post 0 I am trying to create a stock candle with MA(15) on daily data. I can create a chart with OHLC bar without any problem. But when I started usingDataManipulator.FinancialFormula for MA, I keep getting errors of "Formula error - There are not enough data points for the Period." Can someone help me out on this? Thanks Here is the code. DataSet ds = new DataSet(); SqlConnection connection = new SqlConnection(); connection.ConnectionString = @"Data Source=XXX

Window moving average in sql server

╄→尐↘猪︶ㄣ 提交于 2019-12-08 05:06:26
问题 I am trying to create a function that computes a windowed moving average in SQLServer 2008 . I am quite new to SQL so I am having a fair bit of difficulty. The data that I am trying to perform the moving average on needs to be grouped by day (it is all timestamped data) and then a variable moving average window needs to be applied to it. I already have a function that groups the data by day (and @id) which is shown at the bottom. I have a few questions: Would it be better to call the grouping

Average on overlapping windows in Python

旧城冷巷雨未停 提交于 2019-12-08 02:45:11
问题 I'm trying to compute a moving average but with a set step size between each average. For example, if I was computing the average of a 4 element window every 2 elements: data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] This should produce the average of [1, 2, 3, 4], [3, 4, 5, 6], [5, 6, 7, 8], [7, 8, 9, 10]. window_avg = [2.5, 4.5, 6.5, 8.5] My data is such that the ending will be truncated before processing so there is no problem with the length with respect to window size. I've read a bit about how