xts

Why is this xts frequency always 1?

旧街凉风 提交于 2019-12-30 10:20:12
问题 I'm creating an xts object with a weekly (7 day) frequency to use in forecasting. However, even when using the frequency=7 argument in the xts call, the resulting xts object has a frequency of 1. Here's an example with random data: > values <- rnorm(364, 10) > days <- seq.Date(from=as.Date("2014-01-01"), to=as.Date("2014-12-30"), by='days') > x <- xts(values, order.by=days, frequency=7) > frequency(x) [1] 1 I have also tried, after using the above code, frequency(x) <- 7 . However, this

na.locf but don't do trailing NAs

假装没事ソ 提交于 2019-12-30 08:23:57
问题 I have the following time series > y<- xts(1:10, Sys.Date()+1:10) > y[c(1,2,5,9,10)] <- NA > y [,1] 2011-09-04 NA 2011-09-05 NA 2011-09-06 3 2011-09-07 4 2011-09-08 NA 2011-09-09 6 2011-09-10 7 2011-09-11 8 2011-09-12 NA 2011-09-13 NA A straight na.locf give me this: > na.locf(y) [,1] 2011-09-04 NA 2011-09-05 NA 2011-09-06 3 2011-09-07 4 2011-09-08 4 2011-09-09 6 2011-09-10 7 2011-09-11 8 2011-09-12 8 2011-09-13 8 how do i get to this? [,1] 2011-09-04 NA 2011-09-05 NA 2011-09-06 3 2011-09-07

Keeping Character Types/Names in xts object in R

萝らか妹 提交于 2019-12-25 08:56:41
问题 Okay so this is probably a really dumb question, but I've check around and couldn't find anything on it so I thought I'd ask here. I'm looking at stock prices for a range of different stocks and I would like to use the xts package, but the problem is that xts removes names/character data types from datasets, such that a dataframe such as this: TIME | STOCK | PRICE ----------------------------- ..... | QQQQ | ..... ..... | WWWW | ..... ..... | EEEE | ..... gets converted into an xts object,

Aggregating 10 minute data to hourly mean with the hourly.apply function fails

不羁岁月 提交于 2019-12-25 02:53:39
问题 I have a file with date/time data and its measured values for said date and time. The values were measured every ten minutes for the course of one month, and I am attempting to do a time series analysis eventually. Before that however, I wanted to aggregate the 10 minute intervals to hourly intervals by calculating the mean measurement of every 60 minutes. Here is a sample of my data(a total of 4319 observations): Date/Time Value 2013-01-01 00:00:00 31,439999 2013-01-01 00:10:00 33,439999

create an index for aggregating daily data to match periodic data

◇◆丶佛笑我妖孽 提交于 2019-12-25 01:09:37
问题 I have daily measurements prec.d and periodic measurements prec.p . The periodic measurements (3-12 days apart) are roughly the sum of the daily measurements between the start and end dates, and I need to compare prec in the two data frames. I have so far manually created an index week that represents the time span of each periodic measurement, but it would be great to make week in a reproducible fashion. data.frame prec.d day week prec 6/20/2013 1 0 6/21/2013 1 0 6/22/2013 1 0 6/23/2013 1 0

Xts conversion fails on update from xts 0.9.7 to 0.10.0

感情迁移 提交于 2019-12-24 20:15:33
问题 Dataframe to xts conversion fails on update from xts 0.9.7 to 0.10.0. #THIS WORKS (uses xts 0.9.7): library(xts) DFX <- structure(list(DateTime = structure(list(sec = c(0, 0, 0), min = c(10L, 0L, 5L), hour = c(17L, 18L, 18L), mday = c(24L, 24L, 24L), mon = c(5L, 5L, 5L), year = c(114L, 114L, 114L), wday = c(2L, 2L, 2L), yday = c(174L, 174L, 174L), isdst = c(1L, 1L, 1L), zone = c("EDT", "EDT", "EDT"), gmtoff = c(NA_integer_, NA_integer_, NA_integer_)), .Names = c("sec", "min", "hour", "mday",

Generate time sequence of a day with a minute difference in R

天大地大妈咪最大 提交于 2019-12-24 17:45:59
问题 I want to generate time sequence of a day by a minute difference using R like 00:00, 00:01, 00:02, ..., 23:59 For the same, I am using timeBasedSeq function of xts package with following lines of code timerange1<- paste('T00:00','/','T23:59',' 12:00',sep="") timeBasedSeq(timerange1) But, I am not able to generate the sequence with this. Also, I do not understand what 12:00 mean in first line of code, i.e., how does it relate to minutes or hours or seconds. Any help will be appreciated. 回答1:

Using QuantMod/tseries monthlyReturn with dividend

放肆的年华 提交于 2019-12-24 10:49:24
问题 Is there are way using Monthly Return function to factor in dividends into the monthlyReturn? I have my an xts object with price and dividend columns. 回答1: You can use TTR::adjRatios directly to calculate the adjustment ratios necessary to create a "total-return" price series. Then you can calculate the monthly return using the adjusted series. Note that you might also need to adjust for splits. library(quantmod) # create sample data SPY.Close <- Cl(getSymbols("SPY", auto.assign=FALSE)) SPY

Using Rollapply on two columns

痴心易碎 提交于 2019-12-24 03:08:40
问题 I'm trying to do something similar I was asking for here and unfortunately I cannot work it out. This is my data frame (data), a time series of prices: Date Price Vol 1998-01-01 200 0.3 1998-01-02 400 0.4 1998-01-03 600 -0.2 1998-01-04 100 0.1 ... 1998-01-20 100 0.1 1998-01-21 200 -0.4 1998-01-21 500 0.06 .... 1998-02-01 100 0.2 1998-02-02 200 0.4 1998-02-03 500 0.3 1998-02-04 100 0.1 etc. I would like to tell R, to take the 1st value of "Vol" and divide it by the 20th value of "Price", then

Using Rollapply on two columns

十年热恋 提交于 2019-12-24 03:08:21
问题 I'm trying to do something similar I was asking for here and unfortunately I cannot work it out. This is my data frame (data), a time series of prices: Date Price Vol 1998-01-01 200 0.3 1998-01-02 400 0.4 1998-01-03 600 -0.2 1998-01-04 100 0.1 ... 1998-01-20 100 0.1 1998-01-21 200 -0.4 1998-01-21 500 0.06 .... 1998-02-01 100 0.2 1998-02-02 200 0.4 1998-02-03 500 0.3 1998-02-04 100 0.1 etc. I would like to tell R, to take the 1st value of "Vol" and divide it by the 20th value of "Price", then