moving-average

Apply sum product on columns of a dataframe in rolling windows

浪尽此生 提交于 2020-01-06 05:25:23
问题 I have a set of defined weights and I want to calculate the weighted sum of returns in rolling windows on a time series dataframe. I believe we would use rollapplyr here, but I am unsure how to perform rolling window function across each row of the dataframe. Find below dput output of a sample of the data: tempVar <- structure(c(NA, -0.0081833512947922, 0.00508150903899551, -0.0072202479734873, 0.00345258369231161, NA, 0, -0.00847462699097257, -0.00794638265247283, 0.00445091892889238, NA, NA

How do I perform a moving average in panda with a column that needs to be unique?

非 Y 不嫁゛ 提交于 2020-01-05 03:56:27
问题 I have a data frame like the one below: index Player Team Matchup Game_Date WL Min PTS FGM FGA FG% 3PM 3PA 3P% FTM FTA FT% OREB DREB REB AST STL BLK TOV PF Plus_Minus Triple_Double Double_Double FPT 2PA 2PM 2P% Home_Away 276100 1 John Long TOR TOR @ BOS 04/20/1997 W 6.0 0.0 0.0 3.0 0.0 0.0 1.0 0.0 0.0 0.0 0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 2.0 0.0 0.0 1.50 2.0 0.0 0.000000 Away 276101 2 Walt Williams TOR TOR @ BOS 04/20/1997 W 29.0 7.0 3.0 9.0 33.3 1.0 2.0 50.0 0.0 0.0 0 3.0 3.0 3.0 2.0 2.0 1

Filtering compass readings

随声附和 提交于 2020-01-01 05:40:12
问题 I'm using compass heading to rotate an MKMapView. The rotation was a bit jerky so I'm trying to filter it like Google Maps on the iphone does (or appears to do some trickery). I'm trying to filter the reading from the iphone compass using a moving average formula but it fails on the crossover between 359 adn 0 becuase it starts to average backwards from 35x to 0 and causes the map to rotate backwards as it approaches north from the west. Any ideas what the best way is to filter this data so

pyspark: rolling average using timeseries data

烈酒焚心 提交于 2019-12-29 03:15:27
问题 I have a dataset consisting of a timestamp column and a dollars column. I would like to find the average number of dollars per week ending at the timestamp of each row. I was initially looking at the pyspark.sql.functions.window function, but that bins the data by week. Here's an example: %pyspark import datetime from pyspark.sql import functions as F df1 = sc.parallelize([(17,"2017-03-11T15:27:18+00:00"), (13,"2017-03-11T12:27:18+00:00"), (21,"2017-03-17T11:27:18+00:00")]).toDF(["dollars",

Add Moving average plot to time series plot in R

≡放荡痞女 提交于 2019-12-28 05:10:47
问题 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,

Does Pandas calculate ewm wrong?

霸气de小男生 提交于 2019-12-28 02:04:21
问题 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 *

Moving Average by Unique Date with multiple observations per date

天涯浪子 提交于 2019-12-25 07:42:55
问题 I have a dataset that may contain MULTIPLE observations per date. So there could be 5 observations on date1, 2 observations on date2, and 1 observation on group3. I want to calculate the moving average - by date - and importantly while not summarising/reducing' the number of rows. That is In this example above, I would still have 8 rows of data, and in a column next to it I would have that date's rolling average price I find this challenging because when I use a typical rolling function from

Grouped Rolling Average by Date

对着背影说爱祢 提交于 2019-12-25 03:56:17
问题 I have data at a Day Level. Each day always has more than 1 value, and the days are not necessarily in consecutive order. I want to create a calculation for the mean on a particular day and the rolling 14 day mean. I have tried doing this in R but I am not having much luck. I think I am close though. Basically rolling mean and regular mean grouped by date. Thanks so much, I'm going crazy since I think I'm so close! library(plyr) library(zoo) help=ddply(data, .(DATE), roll_avg14 =rollmean

Is there a way to get Pandas ewm to function on fixed windows?

↘锁芯ラ 提交于 2019-12-24 07:45:20
问题 I am trying to use Pandas ewm function to calculating exponentially weighted moving averages. However i've noticed that information seems to carry through your entire time series. What this means is that every data point's MA is dependant on a different number of previous data points. Therefore the ewm function at every data point is mathematically different. I think some here had a similar question Does Pandas calculate ewm wrong? But i did try their method, and i am not getting

Python rolling Sharpe ratio with Pandas or NumPy

丶灬走出姿态 提交于 2019-12-20 16:49:35
问题 I am trying to generate a plot of the 6-month rolling Sharpe ratio using Python with Pandas/NumPy. My input data is below: import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns sns.set_style("whitegrid") # Generate sample data d = pd.date_range(start='1/1/2008', end='12/1/2015') df = pd.DataFrame(d, columns=['Date']) df['returns'] = np.random.rand(d.size, 1) df = df.set_index('Date') print(df.head(20)) returns Date 2008-01-01 0.232794 2008-01-02 0.957157