xts

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

风格不统一 提交于 2019-12-01 06:44:50
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]]][[1]] p3<-data[tmp_triple[[3]]][[1]] data.merge <- merge(p1,p2,p3,all=FALSE) } Here, the merge

rpy2 importr failing with xts and quantmod

落花浮王杯 提交于 2019-12-01 06:09:41
问题 I'm new to rpy2 and am having trouble using importr to import the R packages 'xts' and 'quantmod' Code is: from rpy2.robjects.packages import importr xts = importr('xts') quantmod = importr('quantmod') Errors are: LibraryError: Conflict when converting R symbol in the package "xts" to a Python symbol (.subset.xts -> _subset_xts while there is already _subset_xts) LibraryError: Conflict when converting R symbol in the package "quantmod" to a Python symbol (skeleton.TA -> skeleton_TA while

xts comparison to another xts object does not work

Deadly 提交于 2019-12-01 06:08:11
问题 this = structure(c(-0.012, -0.028, -0.044, -0.033, -0.039, -0.042), .Dim = c(3L, 2L), .Dimnames = list(NULL, c("one", "two")), index = structure( c(1313643600, 1313730000, 1313816400), tzone = "", tclass = "Date"), .indexCLASS = "Date", .indexTZ = "", class = c("xts", "zoo")) m1=last(this$one) - last(this$two) m2=first(last(this$one,n=2)) - first(last(this$two,n=2)) m1 > 0 #returns a TRUE OR FALSE m1 > m2 #breaks I know I can use coredata to extract and then compare. I wasn't sure if this is

Decompose xts hourly time series

本秂侑毒 提交于 2019-12-01 05:02:42
问题 I want to decompose hourly time series with decompose , ets , or stl or whatever function. Here is an example code and its output: require(xts) require(forecast) time_index1 <- seq(from = as.POSIXct("2012-05-15 07:00"), to = as.POSIXct("2012-05-17 18:00"), by="hour") head(time_index1 <- format(time_index1, format="%Y-%m-%d %H:%M:%S", tz="UTC", usetz=TRUE) # [1] "2012-05-15 05:00:00 UTC" "2012-05-15 06:00:00 UTC" # [3] "2012-05-15 07:00:00 UTC" "2012-05-15 08:00:00 UTC" # [5] "2012-05-15 09:00

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

与世无争的帅哥 提交于 2019-12-01 04:35:44
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(TICK.NYSE)), order.by = index(TICK.NYSE))) Error in xts(rep(0, NROW(TICK.NYSE)), order.by = index(TICK

zoo/xts - can't do math on 1-cell subsets? R hangs

喜夏-厌秋 提交于 2019-12-01 03:55:30
问题 I'm using latest version of R/xts/zoo on Windows: R 2.15, xts 0.8-6, zoo 1.7-7 I'm seeing the following bizarre behavior, which was not the case with prior versions: library(xts) data(sample_matrix) sample.xts <- as.xts(sample_matrix) sample.xts[1, 2] - sample.xts[2,2] # results in numeric(0)?!?!?! (sample.xts[ 1, 2] - sample.xts[2,2])/sample.xts[3,1] # if I run this twice R locks up Here I have subset an XTS object to a single cell. Subtraction no longer works. Also, division causes R to

na.locf but don't do trailing NAs

这一生的挚爱 提交于 2019-12-01 03:51:36
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 4 2011-09-08 4 2011-09-09 6 2011-09-10 7 2011-09-11 8 2011-09-12 NA 2011-09-13 NA I dont want last

Pull Return from first business day of the month from XTS object using R

痞子三分冷 提交于 2019-12-01 03:29:21
I am very new to R so apologies if I get any of the terminology wrong when I explain this problem. I have a set of daily returns data in a csv file that I have managed to convert to an xts object. The data is in the format: HighYield..EUR. MSCI.World..EUR. 2002-01-31 0.0144 0.0031 2002-02-01 0.0056 -0.0132 2002-02-02 0.0373 0.0356 2002-02-03 -0.0167 -0.0644 2002-02-04 -0.0062 -0.0332 2002-02-05 -0.0874 -0.1112 ... I want to create a script that will find the first business day of the month (from the range of values in the index) and then create a new xts object with these returns in it. For

Linear Interpolation using dplyr

被刻印的时光 ゝ 提交于 2019-12-01 03:16:03
问题 I'm trying to use the na.approx() function from the zoo library (in conjunction with xts ) to interpolate missing values from repeated measures data for multiple individuals with multiple measurements. Sample data... event.date <- c("2010-05-25", "2010-09-10", "2011-05-13", "2012-03-28", "2013-03-07", "2014-02-13", "2010-06-11", "2010-09-10", "2011-05-13", "2012-03-28", "2013-03-07", "2014-02-13") variable <- c("neck.bmd", "neck.bmd", "neck.bmd", "neck.bmd", "neck.bmd", "neck.bmd", "wbody.bmd

data.table time subset vs xts time subset

穿精又带淫゛_ 提交于 2019-11-30 21:31:51
Hi I am looking to subset some minutely data by time. I normally use xts doing something like: subset.string <- 'T10:00/T13:00' xts.min.obj[subset.string] to get all the rows which are between 10am and 1pm (inclusive) EACH DAY and have the output as an xts format. But is a bit slow for my purposes...e.g j <- xts(rnorm(10e6),Sys.time()-(10e6:1)) system.time(j['T10:00/T16:00']) user system elapsed 5.704 0.577 17.115 I know that data.table is v fast and at subsetting large datasets so am wondering if in conjunction with the fasttime package to deal with fast POSIXct creations, if it would be