xts

XTS replacement error NextMethod(.Generic) : number of items to replace

梦想的初衷 提交于 2019-12-20 02:01:51
问题 I'm struggling with xts right now... I have an XTS object, and I am trying to replace a specific date's data with a new set, but I keep running into issues of replacement length, even though I am certain they are the same and no missing data. Any ideas? I made a dummy example to demonstrate my issues: R> test1 = xts(cbind(trade_level = 1, t2 = 3),order.by=as.Date("1991-01-02")) R> test2 = xts(cbind(trade_level = 5, t2 = .053),order.by=as.Date("1991-01-02")) R> first_day = "1991-01-02" R>

barplot for xts objects

落花浮王杯 提交于 2019-12-19 11:18:19
问题 Can I use barplot to plot xts objects? Or is there any similar function that I can use? quantmod is not what I'm talking about since it's not flexible enough and not compatible with other R graphics. 回答1: You can extract the indices and the values of an xts or zoo object with index and coredata : this should suffice to plot it the way you want. # Sample data library(quantmod) getSymbols("^GSPC") x <- Vo( GSPC ) # Base graphics plot( index(x), coredata(x), type="h" ) # ggplot2 d <- data.frame(

Nth day of month in a xts object

佐手、 提交于 2019-12-19 10:26:58
问题 prices is an xts object period.ends = endpoints(prices, 'months',k=1) with this line i find position of the last day of the month in a time series. How to find position of the first day of month (not always 1 of the month)? And the second day? Thank you 回答1: startpoints <- function (x, on = "months", k = 1) { head(endpoints(x, on, k) + 1, -1) } period.starts = startpoints(prices, 'months', k=1) See also: xts:::startof and xts::firstof 来源: https://stackoverflow.com/questions/21858552/nth-day

Error when using %dopar% instead of %do% in R (package doParallel)

瘦欲@ 提交于 2019-12-19 08:56:44
问题 I've come up with a strange error. Suppose I have 10 xts objects in a list called data. I now search for every three combinations using data_names <- names(data) combs <- combn(data_names, 3) My basic goal is to do a PCA on those 1080 triples. To speed things up I wanted do use the package doParallel . So here is the snippet shortened till the point where the error occurs: list <- foreach(i=1:ncol(combs)) %dopar% { tmp_triple <- combs[,i] p1<-data[tmp_triple[[1]]][[1]] p2<-data[tmp_triple[[2]

get xts objects from within an environment

依然范特西╮ 提交于 2019-12-19 08:39:31
问题 I have stored xts objects inside an environment. Can I subset these objects while they are stored in an environment, i.e. act upon them "in-place"? Can I extract these objects by referring to their colname ? Below an example of what I'm getting at. # environment in which to store data data <- new.env() # Set data tickers of interest tickers <- c("FEDFUNDS", "GDPPOT", "DGS10") # import data from FRED database library("quantmod") dta <- getSymbols( tickers , src = "FRED" , env = data , adjust =

xts error - order.by requires an appropriate time-based object

怎甘沉沦 提交于 2019-12-19 06:19:12
问题 I can not resolve why error in simple creation of xts object xts(rep(0, NROW(TICK.NYSE)), order.by = index(TICK.NYSE)) Error in xts(rep(0, NROW(TICK.NYSE)), order.by = index(TICK.NYSE)) : order.by requires an appropriate time-based object appeared while this was working perfectly 14 days ago when I last used the same code (since then the only difference is that TICK.NYSE grow in length since data was added since then). More details below: > Sys.getenv("TZ") [1] "EST" > tail(xts(rep(0, NROW

Aggregate daily level data to weekly level in R

拜拜、爱过 提交于 2019-12-19 05:01:19
问题 I have a huge dataset similar to the following reproducible sample data. Interval value 1 2012-06-10 552 2 2012-06-11 4850 3 2012-06-12 4642 4 2012-06-13 4132 5 2012-06-14 4190 6 2012-06-15 4186 7 2012-06-16 1139 8 2012-06-17 490 9 2012-06-18 5156 10 2012-06-19 4430 11 2012-06-20 4447 12 2012-06-21 4256 13 2012-06-22 3856 14 2012-06-23 1163 15 2012-06-24 564 16 2012-06-25 4866 17 2012-06-26 4421 18 2012-06-27 4206 19 2012-06-28 4272 20 2012-06-29 3993 21 2012-06-30 1211 22 2012-07-01 698 23

R : Tick data adding value when tick data is missing

我怕爱的太早我们不能终老 提交于 2019-12-19 04:07:52
问题 I'm working on tick data and want to aggregate my xts irregularly spaced series into a 1 second homogeneous one. I thus use the xts package function to.period : price_1m <-to.period(price,period="seconds",k=1,OHLC=FALSE) here is what I get : 2010-02-02 08:00:03 2787 2010-02-02 08:00:04 2786 2010-02-02 08:00:05 2787 2010-02-02 08:00:06 2787 2010-02-02 08:00:07 2786 2010-02-02 08:00:08 2786 2010-02-02 08:00:09 2786 2010-02-02 08:00:10 2787 2010-02-02 08:00:11 2786 2010-02-02 08:00:14 2786 2010

Load multiple symbols using csv with quantmod

会有一股神秘感。 提交于 2019-12-19 02:40:12
问题 I am trying to load multiple symbols using a csv file rather than downloading from Yahoo. The original code works great and uses load.packages('quantmod') tickers = spl('TLT,IWM,GLD') data <- new.env() getSymbols(tickers, src = 'yahoo', from = '1980-01-01', env = data, auto.assign = T) when I try using the code below, however, it results in "subscript out of bounds" errors later in the script: load.packages('quantmod') tickers = spl('TLT,IWM,GLD') data <- new.env() getSymbols(tickers, src=

What does useMethod mean here?

大兔子大兔子 提交于 2019-12-18 12:19:44
问题 One of the kool things about R is if I type the function name I get to see the implementation. But this one is confusing me, recursively: > library(xts) > align.time function (x, ...) { UseMethod("align.time") } <environment: namespace:xts> x is an XTS object, so doesn't that mean it will call the XTS align.time method... but that is what I'm looking at! (Typing xts::align.time gives exactly the same response.) 回答1: The short answer is that you are looking for the function xts:::align.time