xts

Reformat daily stock and return data to weekly/monthly

旧城冷巷雨未停 提交于 2021-01-29 07:04:10
问题 I have some stock data together with some returns that are presented below. Now I would like to coerce both the daily price changes (open, high, low, close, volume, adj. close) and the returns given to weekly or monthly values. I know that the weekly prices can be obtained by xts::to.weekly() , but this drops the return. I don't know the exact mechanism behind the to.weekly function, but the returns need to be summarized with the sum function (I'm thinking of using xts::apply.weekly() ), but

R / Time Series: What's the lag unit for autocorrelation function (acf)?

…衆ロ難τιáo~ 提交于 2021-01-28 23:09:02
问题 I have an XTS time series object which shows a value on the first of each month (representing an aggregated sum for the whole month) during four years. When I run the stats::acf() function on it, I get a plot with lag (x axis) units in the hundreds of thousands. How can that be if I only have 48 values in my time series? If it is a time unit, then which one, and how can I change it? Example code: library(dplyr) library(lubridate) library(xts) set.seed(100) test <- data.frame(y = c(rep(2012,

R / Time Series: What's the lag unit for autocorrelation function (acf)?

非 Y 不嫁゛ 提交于 2021-01-28 22:50:49
问题 I have an XTS time series object which shows a value on the first of each month (representing an aggregated sum for the whole month) during four years. When I run the stats::acf() function on it, I get a plot with lag (x axis) units in the hundreds of thousands. How can that be if I only have 48 values in my time series? If it is a time unit, then which one, and how can I change it? Example code: library(dplyr) library(lubridate) library(xts) set.seed(100) test <- data.frame(y = c(rep(2012,

Date in dygraph (using R and xts) shows one day earlier than data

五迷三道 提交于 2021-01-28 08:01:16
问题 This is my first stackoverflow question, so apologies in advance for any lapses in etiquette or presentation. I am using the dygraphs() package in R (3.3.3 on a Mac running Mavericks, using RStudio) to graph a time series of box-office receipts from an 18th-century theater. The dates run from 1789-04-14 to 1791-03-07. I'm using the newest version of the xts package (0.10-0), but the problem was identical in the previous version. As an xts object the data looks like this: head(receipts.xts) kr

merge.xts not merging all data using R

坚强是说给别人听的谎言 提交于 2021-01-28 03:55:21
问题 I am trying to reclass the following xts series since columns 1-8 are character and are suppose to be numeric, columns 9-10 are character as they are suppose to be..... # data x <- structure(c(NA, NA, "41.95", "30.55", "29.05", "23.71", NA, "23.80", NA, NA, "18.67", NA, "16.90", "17.10", "14.90", "13.64", "12.70", "11.65", "10.75", " 9.75", " 9.05", " 7.95", " 6.70", " 6.02", " 5.05", NA, NA, " 0.00", " 0.00", " 0.28", "-0.29", NA, " 0.00", NA, NA, "-1.28", NA, "-1.10", " 0.00", "-0.30", "-1

Group by period.apply() in xts

一笑奈何 提交于 2021-01-27 18:23:36
问题 Hi i have an xts object with 4 variables (2 id vars and 2 measures): > head(mi_xts) squareId country smsIN smsOUT 2013-12-01 00:00:00 9999 39 0.4953734 0.93504713 2013-12-01 00:10:00 9999 39 0.1879042 0.50057622 2013-12-01 00:20:00 9996 39 0.5272736 0.25643745 2013-12-01 00:30:00 9996 39 0.0965593 0.25249854 2013-12-01 00:40:00 9999 39 1.2104980 0.49123277 2013-12-01 00:50:00 9999 39 0.4756599 0.09913715 i'd like to use a period.apply that returns the mean of smsIN and smsOUT group by

Rbind with XTS. How to stack without sorting by index date

北战南征 提交于 2021-01-04 02:41:41
问题 I am using quantmod which generates XTS objects with ticker info, and I am looking to compile/stack a bunch of XTS documents on top of each other to process code. Using Rbind with XTS I find that it does not stack XTS on top of each other, rather it merges and sorts by date: x <- xts(1:10, Sys.Date()+1:10) x [,1] 2014-07-10 1 2014-07-11 2 2014-07-12 3 2014-07-13 4 2014-07-14 5 2014-07-15 6 2014-07-16 7 2014-07-17 8 2014-07-18 9 2014-07-19 10 y <- xts(rep(2,3), Sys.Date()+c(1,2,3)) y [,1] 2014

Rbind with XTS. How to stack without sorting by index date

痴心易碎 提交于 2021-01-04 02:40:53
问题 I am using quantmod which generates XTS objects with ticker info, and I am looking to compile/stack a bunch of XTS documents on top of each other to process code. Using Rbind with XTS I find that it does not stack XTS on top of each other, rather it merges and sorts by date: x <- xts(1:10, Sys.Date()+1:10) x [,1] 2014-07-10 1 2014-07-11 2 2014-07-12 3 2014-07-13 4 2014-07-14 5 2014-07-15 6 2014-07-16 7 2014-07-17 8 2014-07-18 9 2014-07-19 10 y <- xts(rep(2,3), Sys.Date()+c(1,2,3)) y [,1] 2014

How to loop through objects in the global environment - R

和自甴很熟 提交于 2021-01-03 06:59:50
问题 I have looked far and wide for a solution to this issue, but I cannot seem to figure it out. I do not have much experience working with xts objects in R. I have 40 xts objects (ETF data) and I want to run the quantmod function WeeklyReturn on each of them individually. I have tried to refer to them by using the ls() function: lapply(ls(), weeklyReturn) I have also tried the object() function lapply(object(), weeklyReturn) I have also tried using as.xts() in my call to coerce the ls() objects

How to loop through objects in the global environment - R

纵饮孤独 提交于 2021-01-03 06:59:15
问题 I have looked far and wide for a solution to this issue, but I cannot seem to figure it out. I do not have much experience working with xts objects in R. I have 40 xts objects (ETF data) and I want to run the quantmod function WeeklyReturn on each of them individually. I have tried to refer to them by using the ls() function: lapply(ls(), weeklyReturn) I have also tried the object() function lapply(object(), weeklyReturn) I have also tried using as.xts() in my call to coerce the ls() objects