xts

How to transform xts to lower frequency in a cumulative way

馋奶兔 提交于 2019-12-05 03:30:39
问题 I am trying to convert xts time series data to lower periodicity in a cumulative way. For example, using to.weekly on sample data (sample_matrix) from xts package I get this: library(xts) data(sample_matrix) to.weekly(as.xts(sample_matrix), name="") > to.weekly(as.xts(sample_matrix), name="") .Open .High .Low .Close 2007-01-08 50.03978 50.42188 49.95041 49.98806 2007-01-15 49.99489 50.68583 49.80454 50.48912 ..... I would like to be able to use a slightly different function to.weekly

Write xts/zoo object to csv with index

别说谁变了你拦得住时间么 提交于 2019-12-05 02:45:15
> 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.00543 0.00443 1996-06-30 -0.0039 NA -0.0303 -0.0019 NA NA NA 0.0038 0.01507 0.00412 When I try to

How to compute the daily avg correlation on intraday data using the xts package?

陌路散爱 提交于 2019-12-05 02:31:33
问题 I have intra-day history for a bunch of stocks. I am trying to compute the 1-minute correlation between stocks on a daily basis. My aim is to use the daily average per pair over a period to identify optimal pairs for a specific trading strategy. My idea is to loop through the trading days, compute intra-day 1-minute correlation, compute avg over all trading days, next pair. However, I am getting stuck at looping through the trading days. my.xts.A <- xts(A_Frame[,-1], order.by=A_Frame[,1]) my

Rolling regression return multiple objects

允我心安 提交于 2019-12-04 19:17:45
I am trying to build a rolling regression function based on the example here , but in addition to returning the predicted values, I would like to return the some rolling model diagnostics (i.e. coefficients, t-values, and mabye R^2). I would like the results to be returned in discrete objects based on the type of results. The example provided in the link above sucessfully creates thr rolling predictions, but I need some assistance packaging and writing out the rolling model diagnostics: In the end, I would like the function to return three (3) objects: Predictions Coefficients T values R^2

Creating daily OHLC with custom starting time

感情迁移 提交于 2019-12-04 17:37:24
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-03 18:15:00 0.9916730 Using xts : Changing the periodicity from 15m to 60m works nicely: x_agg <- to

xts's hourly endpoints and daylight savings

。_饼干妹妹 提交于 2019-12-04 15:28:32
I have an irregular time series and am using xts 's endpoints to get hourly indices of my time series. endpoints(data, on="hours") I am using this in order to calculate hourly in such fashion period.apply(data, INDEX=endpoints(data, on="hours"), FUN=mean) The problem, however, is that function endpoints returns two consecutive indices (thus for the same hour). > endpoints(data, on="hours")[7201:7220] [1] 87077 87078 87089 87101 87113 87125 87137 87149 87162 87175 87187 87199 87211 87223 87235 87247 87259 87271 87283 87295 If we take a look which datetimes they represent: data[endpoints(data,

Plot value over hour of day with xts/zoo R

a 夏天 提交于 2019-12-04 14:54:52
I do have a time-series looking like this (minute values): "timestamp", value "2012-04-09 05:03:00",2 "2012-04-09 05:04:00",4 "2012-04-09 05:05:00",5 "2012-04-09 05:06:00",0 "2012-04-09 05:07:00",0 "2012-04-09 05:08:00",3 "2012-04-09 05:09:00",0 "2012-04-09 05:10:00",1 Is there an easy way to plot these values over the hour of the day: X-Axis from 1 to 24 hours (or 0 and 23). So - all values between 5:00 and 5:59 over the 5th hour etc. It doesn't depend wich date, I am just interested in the houers of the day. Thank you! Additional Question: Can I plot this as a boxplot? Right now it's plot(df

R xts object subseting xts object with multiple days of intraday data for certain hours

纵然是瞬间 提交于 2019-12-04 14:20:24
Is there a way in xts object to do the same as below but for xts object with multiple days of intraday data? The below works like a clock but for one day of data. If I pass xts from 22nd to 26th it does not. It seems like subseting intraday data in xts across multiple days is not possible to be done in one go but rather need to first split data per each day and then use this xts functionality. Is this correct? indexTZ(tdata) = "GMT" plotdata= tdata['20110822 10:00:00/20110822 12:00:00'] > plotdata= tdata['10:00:00/12:00:00'] works like swiss clock > tail(plotdata) SYMBOL EX PRICE SIZE COND

R Generating a 1 min spaced time sequence

不羁岁月 提交于 2019-12-04 13:56:01
I would like to generate a 1 min spaced time sequence to paste then to a xts object. Basically, I've got a tick-by-tick dateTime object like that : [1] "2010-02-02 08:00:03 CET" "2010-02-02 08:00:04 CET" "2010-02-02 08:00:04 CET" "2010-02-02 08:00:04 CET" "2010-02-02 08:00:04 CET" [6] "2010-02-02 08:00:04 CET" "2010-02-02 08:00:04 CET" "2010-02-02 08:00:05 CET" "2010-02-02 08:00:05 CET" "2010-02-02 08:00:05 CET" I'm aggregating my xts series (by previous tick) to get a 1 min (equally)-spaced time series using an RTAQ package function : price_1m<-aggregatets(price,FUN="previoustick",k=1,on=

Applying models to multiple time-series

落爺英雄遲暮 提交于 2019-12-04 12:52:14
Let's say I have multiple time series for which I want forecasts. If I have the appropriate time-series object for each, I could fit (for the sake of example) an ARIMA model and so on. But, I know there must be an easy way to automate this process when all of the series are in one xts object (leaving aside the fact that different variables might require different ARIMA models; that's probably a question for another time). Some sample data as an xts object (daily revenue for six different businesses): library(xts) ts <- structure(c(534L, 549L, 636L, 974L, 848L, 895L, 1100L, 1278L, 1291L, 1703L,