xts

R XTS to.minutes5(), is not converting as “I” expected

那年仲夏 提交于 2019-12-10 10:08:58
问题 Hi i'm converting some 1 min data to 5 min data, and i'm finding it does 4 mins for the first increment, then goes on to do 5 min increments after that. I've tried messing around with all the "indexAt" parameters but none give me what i want, which is starting from 5, then 10, 15, 20 etc. i've tried x5 <- to.minutes5(x) AND x <- to.period(x, period = 'minutes', k = 5, OHLC = TRUE) 1 min data Open High Low Close Volume 2013-01-16 00:01:00 93.55 93.60 93.54 93.58 5 2013-01-16 00:02:00 93.59 93

Extracting the numerical values of a xts object

*爱你&永不变心* 提交于 2019-12-10 03:14:51
问题 I want to extract the numerical values of a xts object. Let's look at an example data <- new.env() starting.date <- as.Date("2006-01-01") nlookback <- 20 getSymbols("UBS", env = data, src = "yahoo", from = starting.date) Reg.curve <- rollapply(Cl(data$UBS), nlookback, mean, align="right") The Reg.cuve is still a xts object but actually I'm just interested in the running means. How can I modify Reg.curve to get a numerical vector? 回答1: Use coredata : reg.curve.num <- coredata(Reg.curve) # or,

Write xts/zoo object to csv with index

微笑、不失礼 提交于 2019-12-10 02:41:54
问题 > library(PerformanceAnalytics) > data(managers) > class(managers) [1] "xts" "zoo" > head(managers) HAM1 HAM2 HAM3 HAM4 HAM5 HAM6 EDHEC LS EQ SP500 TR US 10Y TR US 3m TR 1996-01-31 0.0074 NA 0.0349 0.0222 NA NA NA 0.0340 0.00380 0.00456 1996-02-29 0.0193 NA 0.0351 0.0195 NA NA NA 0.0093 -0.03532 0.00398 1996-03-31 0.0155 NA 0.0258 -0.0098 NA NA NA 0.0096 -0.01057 0.00371 1996-04-30 -0.0091 NA 0.0449 0.0236 NA NA NA 0.0147 -0.01739 0.00428 1996-05-31 0.0076 NA 0.0353 0.0028 NA NA NA 0.0258 -0

Creating daily OHLC with custom starting time

本秂侑毒 提交于 2019-12-09 19:57:46
问题 I have 15-minute OHLC data and want to convert to daily OHLC but with the start of the day at 17:00:00. This way, the resulting daily bar should span from 17:00:00 to 17:00:00, not from 00:00:00 to 00:00:00 _ x <- zoo(runif(25), order.by=seq( as.POSIXct("2010-05-03 17:00:00"), as.POSIXct("2010-05-06 17:00:00"), by="15 min" ) ) _ head(x) 2010-05-03 17:00:00 0.9788685 2010-05-03 17:15:00 0.5414294 2010-05-03 17:30:00 0.8435366 2010-05-03 17:45:00 0.3064713 2010-05-03 18:00:00 0.1395849 2010-05

Rolling regression over multiple columns

拥有回忆 提交于 2019-12-09 11:57:48
问题 I have an issue finding the most efficient way to calculate a rolling linear regression over a xts object with multiple columns. I have searched and read several previously questions here on stackoverflow. This question and answer comes close but not enough in my opinion as I want to calculate multiple regressions with the dependent variable unchanged in all the regressions. I have tried to reproduce an example with random data: require(xts) require(RcppArmadillo) # Load libraries data <-

Animate map in R with leaflet and xts

☆樱花仙子☆ 提交于 2019-12-09 06:43:00
问题 I would like to build an animated map with a time cursor in R. I have time series (xts) that I would like to represent on map. library(xts) library(leaflet) date<-seq(as.POSIXct("2015-01-01"), as.POSIXct("2015-01-10"), by=86400) a<-xts(1:10,order.by=date) b<-xts(5:14,order.by=date) df = data.frame(Lat = 1:10, Long = rnorm(10),Id=letters[1:10]) leaflet() %>% addCircles(data = df,popup =df$Id) #popup =paste(df$Id, xts value) time cursor on the map Is there a way to do this with the leaflet

Converting data.frame to xts order.by requires an appropriate time-based object

北战南征 提交于 2019-12-08 23:53:41
问题 I have this following data frame: > head(table,10) Date Open High Low Close Volume Adj.Close 1 2014-04-11 32.64 33.48 32.15 32.87 28040700 32.87 2 2014-04-10 34.88 34.98 33.09 33.40 33970700 33.40 3 2014-04-09 34.19 35.00 33.95 34.87 21597500 34.87 4 2014-04-08 33.10 34.43 33.02 33.83 35440300 33.83 5 2014-04-07 34.11 34.37 32.53 33.07 47770200 33.07 6 2014-04-04 36.01 36.05 33.83 34.26 41049900 34.26 7 2014-04-03 36.66 36.79 35.51 35.76 16792000 35.76 8 2014-04-02 36.68 36.86 36.56 36.64

CAPM.beta rollapply

喜欢而已 提交于 2019-12-08 13:31:41
问题 I have already successfully calculated my rolling correlations in my xts object with x <- cbind(market_return,stock_returns) rollcor_3year <- rollapplyr( x, width=width_cor,function(x) cor(x[,1],x[,-1], use="pairwise.complete.obs"),by.column=FALSE) The correlation was later used to calculate rolling Betas. Now I found the function CAPM.beta from the PerformanceAnalytics package and I wonder why I cannot use beta <- rollapplyr(x,width=width_cor,function(x) CAPM.beta(x[,1],x[,-1]),by.column

R - How to read multiple files from a folder, convert them in xts and do some data analysis on them?

六眼飞鱼酱① 提交于 2019-12-08 12:59:45
问题 I have a folder with 199 files (from blah-001-a.exp to blah-199-a.exp ) I want to do something like this for every file: DF<- read.csv("D:/ebook/myfolder/blah-001-a.exp", sep=";") xts<-xts(x=DF[,-c(1,13)], order.by = as.Date(x=DF$DATA,format="%d.%m.%Y")) #other codes and report pdf file... I tried some code like this but it only reads the files without trasform them into xts: folder <- "D:/ebook/myfolder/" filenames <- list.files(path=folder) for (i in 1:length(filenames)){ assign(filenames[i

How to create time series with missing datetime values

若如初见. 提交于 2019-12-08 10:12:13
问题 I have csv file with data. Link is here. Granularity of time series is 5 min for year 2013. However, values are missing for some time stamps. I want to create a time series with 5 minute interval with value zero for time stamps which are missing. Please advise how to do this either in Pandas or R 回答1: This should work # partial old data used for example timedata<- read.table(header = TRUE, sep =",", text = " timestamp, value 01/01/2013 00:00:10,10 01/01/2013 00:00:25,6 01/01/2013 00:00:40,10