xts

R xts: query both date and time

坚强是说给别人听的谎言 提交于 2019-12-11 18:52:07
问题 I can't query xts for subsets including both a date and time range. For example: > head(myxts['2012-01-06 9:30:00/2012-01-06 10:00:00'], 1) Symbol 2012-01-03 09:30:00 "AA" > tail(myxts['2012-01-06 9:30:00/2012-01-06 10:00:00'], 1) Symbol 2012-01-06 10:00:00 "AA" Here the first row is 2012-01-03. Why not 2012-01-06? EDIT I've also tried to extract a single date first to a new variable, then query by time. In this case the date timeseries are extracted correctly but the time subset will not

Beta loop that allows for segmented time-series frequency

試著忘記壹切 提交于 2019-12-11 18:05:26
问题 I'm trying to run the LM function to collect the full output (summary) over a fairly large xts series (etfadj3) of different securities' returns. Currently, I can calculate a beta and capture all the regression outputs for the first column's return series against each column (security's) return series that follows - this is what I want. However, I would like to be able to modify this script so that I can vary the frequency of the regression to see a monthly/quarterly/yearly result. Is there a

Reading CSV in R with zoo

别来无恙 提交于 2019-12-11 12:54:20
问题 I have a CSV in the following format: TICKER,PER,DATE,TIME,CLOSE SYMBOL,1,20160104,1002,14180.0000000 SYMBOL,1,20160104,1003,14241.0000000 I would like to read it into a time series: f <- function(a, b) { c <- paste(a, b) return(strptime(c, format = "%Y%m%d %H%M")) } d <- read.zoo("test.csv", FUN = f, index.column = list("DATE", "TIME")) And what I get is index does not match data . Why? 回答1: You need to specify header = TRUE and sep = "," , since they are not the defaults for read.zoo like

R xts::plot.xts multi.panel doesn't produce data

倾然丶 夕夏残阳落幕 提交于 2019-12-11 12:22:28
问题 R's xtsExtra::plot.xts no longer supports nc and auto.grid . I'm trying to use xts::plot.xts's multi.panel but the first problem is that all panels are blank: $ svn checkout --revision 875 svn://svn.r-forge.r-project.org/svnroot/xts/ $ R ... install.packages("xts/pkg/xts", repos=NULL, type="source") library(zoo) library(xts) timezone = "UTC" Sys.setenv(TZ=timezone) sampleData = "Time (UTC),CPU,Runqueue,Blocked,MemoryFree,PageIns,ContextSwitches,Wait,Steal 2014-10-15 16:12:11,20,0,0,12222172,0

split up xts-dataframe into several groups, collapse to weekly data and keep the time index

血红的双手。 提交于 2019-12-11 11:11:44
问题 I am a total newbie to R so I apologize if the answer to my question is too obvious. I a data set of the following form: Date, V1,V...,VN,Land,Nace 22/03/1995 23:01:12,1,3,2,15,A 21/03/1995 21:01:12,3,3,1,9,C 1/04/1995 17:01:06,3,2,1,3,B I would like to analyze the data in the data.frame by Land, NACE (it's an industry code), Date (I would like to collapse the whole think to weekly data) and by the three different answering options {1,2,3} in V1...VN. This is a sample of my data: example <-

Merge or cbind xts object with dataframe

こ雲淡風輕ζ 提交于 2019-12-11 10:30:51
问题 I have a dataframe with monthly time series (various financial and economic variables), something like this: var1 <- c('1','2','3') var2 <- c('1','2','3') Date <- as.Date(c('1995-11-1','1995-12-1','1996-1-1')) df <- data.frame(Date, var1, var2) and I would like to add a number of further variables which I am downloading from FRED, like this: library('quantmod') y<-getSymbols('T10Y2Y',src='FRED', auto.assign=FALSE) y2<-to.monthly(y) y is an "xts" "zoo" object. Now, y2 is of a different length

R special data frame

好久不见. 提交于 2019-12-11 09:43:03
问题 I'm asking a question follwing the one I asked yesterday in this post : Random Forests for Variables selection. I managed to find out for each quarter the most significant technical trading rules. I've built a data frame to put the names of these TTR. Here is it, I've got with one column for quarter. 1 2 3 4 5 6 7 8 9 10 11 1 RSI2 RSI3 RSI2 RSI10 RSI2 RSI2 RSI2 RSI2 RSI2 RSI2 RSI2 2 RSI3 RSI4 RSI3 RSI20 RSI3 RSI3 RSI3 RSI4 RSI4 RSI3 RSI3 3 RSI4 RSI5 RSI4 EMA5 RSI4 RSI4 RSI5 RSI5 RSI5 RSI4

Removing dates with less than Full observations

为君一笑 提交于 2019-12-11 09:32:35
问题 I have an xts object that covers 169 days of high frequency 5 minute regular observations, but on some of the days there are missing observations, i.e less than 288 data points. How do I remove these so to have only days with full data points? find days in data ddx = endpoints(dxts, on="days"); days = format(index(dxts)[ddx], "%Y-%m-%d"); for (day in days) { x = dxts[day]; cat('', day, "has", length(x), "records...\n"); } I tried RTAQ::exchangeHoursOnly(dxts, daybegin = "00:00:00", dayend =

How can I convert a matrix of strings into a tibble?

北城以北 提交于 2019-12-11 06:28:54
问题 I'm given some data in an .rData file. The format is an xts object in character mode. (I realise this is an unusual format, but I have no control over it) > head(trades) SYMBOL EX PRICE SIZE COND BID BIDSIZ OFR 2012-05-04 09:30:00 "BAC" "T" "7.89" "38538" "F" "7.89" "523" "7.9" 2012-05-04 09:30:01 "BAC" "Z" "7.885" "288" "@" "7.88" "61033" "7.9" 2012-05-04 09:30:03 "BAC" "X" "7.89" "1000" "@" "7.88" "1974" "7.89" 2012-05-04 09:30:07 "BAC" "T" "7.89" "19052" "F" "7.88" "1058" "7.89" 2012-05-04

How to index one minute intraday data in xts?

烂漫一生 提交于 2019-12-11 05:33:01
问题 I have worked with daily stock data using quantmod. Quantmod automatically dowloads data from google/yahoo finance sites and convert automatically to a xts object as date as the index. AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted 2014-10-01 100.59 100.69 98.70 99.18 51491300 97.09741 2014-10-02 99.27 100.22 98.04 99.90 47757800 97.80230 2014-10-03 99.44 100.21 99.04 99.62 43469600 97.52818 2014-10-06 99.95 100.65 99.42 99.62 37051200 97.52818 2014-10-07 99.43 100.12 98.73