xts

irregular time series data- can I make it regular? in r

放肆的年华 提交于 2019-12-06 06:07:41
I have data that was programmed to acquire information every 5 hours which means multiple data points per day. The problem is sometimes the data logger fails or batteries die or whatever and there are missing data or failed attempts. All of my analysis I do is based upon these dates. I need to sort and filter and select everything based on this date/time stamp. As of right now I am going through "long winded" scripts just to select and subset my data. Additionally I have several data loggers (individuals) so I am also batch processing. For instance, I want to subset and use only one data point

Rolling list over unequal times in XTS

佐手、 提交于 2019-12-06 06:00:47
I have stock data at the tick level and would like to create a rolling list of all ticks for the previous 10 seconds. The code below works, but takes a very long time for large amounts of data. I'd like to vectorize this process or otherwise make it faster, but I'm not coming up with anything. Any suggestions or nudges in the right direction would be appreciated. library(quantmod) set.seed(150) # Create five minutes of xts example data at .1 second intervals mins <- 5 ticks <- mins * 60 * 10 + 1 times <- xts(runif(seq_len(ticks),1,100), order.by=seq(as.POSIXct("1973-03-17 09:00:00"), as

How do I extract / subset day+0 to day+1 index times from minutely data via xts in R?

眉间皱痕 提交于 2019-12-06 04:42:45
问题 I'm trying to generate cross-day, sub-settable timeseries in XTS. For example, let's say I have a minutely timeseries ( mts ) that is generated 24 hours a day over 10 years. I want to extract, say, every (08:30am on t+0 to 13:30 t+1) period for every 'day' in the timeseries. To do this from 08:30 to, say, 16:00 on the same day with xts is trivial and well addressed on StackExchange: ie mts["T08:29:59/T16:01:00"] But how do i write the equivalent where the endpoint of the timeseries to be

R: Why an xts object becomes a zoo object after calling transform()?

社会主义新天地 提交于 2019-12-06 04:29:25
transform() removes the class "xts" qualifier from my xts object: > class(myxts) [1] "xts" "zoo" > myxts = transform(myxts, ABC = 1) > class(myxts) [1] "zoo" Why is that? There's no xts method for transform , so the zoo method is dispatched. The zoo method explicitly creates a new zoo object. > zoo:::transform.zoo function (`_data`, ...) { if (is.null(dim(coredata(`_data`)))) warning("transform() is only useful for matrix-based zoo series") zoo(transform.data.frame(data.frame(coredata(`_data`)), ...), index(`_data`), attr(`_data`, "frequency")) } <environment: namespace:zoo> You could simply

Applying models to multiple time-series

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 04:14:28
问题 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

R quantmod:getFinancials

依然范特西╮ 提交于 2019-12-06 03:37:52
I'm trying to import the financials statements of all the companies listed on the NYSE whose market cap is in greater than the first quartile of the sample. Here is my code : require(TTR) require(quantmod) data.init="2013/01/01" start.date <- as.numeric(gsub("/", "",data.init)) nyse.symbols <- stockSymbols("NYSE")[,-c(3,5)] nyse.symbols <- na.omit(nyse.symbols[which(nyse.symbols[,"MarketCap"]>0),]) ######## Selection Criteria # Filter 1 : stock mkt cap > 1st quartile --> remove the less liquid stocks mktcap.filter <- quantile(nyse.symbols[,"MarketCap"],0.25) nyse.symbols <- nyse.symbols[which

plotting multiple xts objects in one window

╄→гoц情女王★ 提交于 2019-12-06 02:51:22
问题 I have found some answers to this online but for some reason am interpreting incorrectly because I cannot get it to work. My goal is to simply use the xts plotting feature (with the the way it creates the axis, gridlines,etc.) to plot multiple plots: x <- xts(data.frame(a=1:100, b=100:1),seq(from=as.Date("2010-01-01"), by="days", len=100)) > plot(x, screens=1) Warning messages: 1: In plot.xts(x, screens = 1) : only the univariate series will be plotted 2: In plot.window(...) : "screens" is

Text not appearing on XTS plot

南楼画角 提交于 2019-12-06 02:42:24
I'm having trouble adding some text to an plot of time series data in R using xts . I've produced a simple example of the problem. My text() command seems to do nothing, whereas I can add a points to the plot. I've tried to keep the code simple by using defaults where possible require(quantmod) # fetch the data and plot it using default options getSymbols('MKS.L') plot(MKS.L$MKS.L.Close) # try to add text - doesn't appear text(as.Date('2012-01-01'),y=500,"wobble", cex=4) # add a point - this does appear testPos <- xts(600, as.Date('2012-01-01')) points( testPos, pch = 3, cex = 4, col = "red" )

XTS dates from different sources. Using R to calculate beta

喜欢而已 提交于 2019-12-06 02:25:44
问题 I'm somewhat new to R. I imagine my error will be trivial to the experienced. I'm attempting to write an R program that will calculate beta for a number of stocks. The stock symbols are read from Input.csv , and the data is downloaded from yahoo. The code then loops through a beta calculation for each stock and outputs a csv summarizing the regressions. I got the code to work when a single risk free rate was assumed in all periods, but I believe I may need to use the actual risk free rate in

xts merge odd behaviour

送分小仙女□ 提交于 2019-12-06 01:46:34
I have 3 xts objects all of whose indicies are 'Date' objects: > a a 1995-01-03 1.76 1995-01-04 1.69 > b b 1995-01-03 1.67 1995-01-04 1.63 > c c 1995-01-03 1.795 1995-01-04 1.690 To verify the indices are the same: > index(a) == index(b) [1] TRUE TRUE > index(a) == index(c) [1] TRUE TRUE Now I'm seeing this odd behaviour: > merge.xts(a,b) a b 1995-01-03 NA 1.67 1995-01-03 1.76 NA 1995-01-04 NA 1.63 1995-01-04 1.69 NA While the following merge works fine: > merge.xts(a,c) a c 1995-01-03 1.76 1.795 1995-01-04 1.69 1.690 I can't figure out what could possibly be going on here. Any idea? Update: >