Questions tagged [xts]
xts is an R package that contains an eXtensible Time Series class and methods. xts extends and behaves like zoo.
1,987
questions
2
votes
2
answers
39
views
How to create a variable based on a given growth rate using xts?
I want to create a variable based on a given growth rate, which is in another variable, starting from a base of 1. Below is an example. I tried two methods, either applying growth rate to lagged value ...
0
votes
1
answer
95
views
How do I debug for different inputs in R when dput() results are seemingly identical?
I've been wrangling data in Python to comply with the documentation for the "BGVAR" package in R.
It states that for the bgvar class I need to input Data as a list of dataframes where each ...
1
vote
3
answers
69
views
How to round trip (to and from a .csv file) with an xts object?
Trying to do a round trip (write/read) with an xts object. read.zoo() returns a data frame! Converting this to an xts fails.
How do I make it an xts object?
library(quantmod)
from <- "2016-01-...
2
votes
1
answer
40
views
Data table output looks very different than xts output
I'm having trouble viewing a data table in a tabular format. If I use the PCRA package and export a dataset as an xts object (see the minimal example below), the xts object resembles a table:
class(...
0
votes
0
answers
35
views
Calculate Return with R
I'm a new to R. I have an Excel file called "bitcoin" which contains two columns: "date" and "BTC.Close". I've imported the data into R and transformed it into an xts ...
2
votes
3
answers
75
views
How to access xts column by name in a function in R?
How would I access an xts column by name in a function? The code below returns NULL.
#m(list=ls())
#dev.off(dev.list()["RStudioGD"])
getSymbols("^GSPC",src="yahoo",from=&...
1
vote
1
answer
55
views
how to shift an xts time series to the left in r?
I am trying to shift one column of an xts time series to the left in R (please see the code below). The lag shifts nicely to the right, but I want it to line up with the rolling mean. Using a negative ...
0
votes
2
answers
42
views
Period apply after filtering missing data
I have a large xts of 10 minute data that I am trying to average hourly. The data also has some missing data within it. I want to average all of the hours that have >50% data completeness but ...
0
votes
1
answer
47
views
Matching R time series class between input and output
I have an R function that analyzes regular time series, originally written by assuming the data were just a vector, say of length N. It outputs a list of vectors that are either of length N or length ...
2
votes
2
answers
42
views
display format of xts when time is 00:00
How can I change the format of the return value of last if the time of that time step is 00:00?
Here is an example
I have two xts objects containing hourly observations with different end times that I ...
0
votes
1
answer
20
views
Cannot Create xts Object from Data.Frame that has Properly Formatted Date Index
frame that should be properly formatting with a date index that's properly formatted to be an .xts. However, I cannot complete the conversion to an xts object and receive the following error:
Error ...
0
votes
1
answer
22
views
How to split xts OHLC data by the specified number of candles
I have candle data
len <- 10000
times <- seq(as.POSIXct("2016-01-01 00:00:00"), length = len, by = "sec")
prices <- cumsum(rnorm(len))+1000
library(xts)
xp <- xts(x = ...
2
votes
2
answers
60
views
How to divide the columns in a time series by their first value in R?
I have the code below working. But there must be a better way.
file <- "http://s3.amazonaws.com/assets.datacamp.com/production/course_1127/datasets/tmp_file.csv"
x <- read.csv(file = ...
0
votes
1
answer
64
views
Take every Xth value of an xts object
I've got an xts object that contains data in a temporal resolution of seconds. For instance:
times <- seq.POSIXt(from=as.POSIXct("2023-04-01 00:00:00"), to=as.POSIXct("2023-04-04 00:...
0
votes
1
answer
12
views
can't draw "chart_Series" graph in loop "quantmod package"
I just installed the latest version of R and installed the latest version of Rstudio and ran into an interesting problem.
It turned out that I can draw one graph
library(quantmod)
library(xts)
...
0
votes
0
answers
25
views
How can I split an xts object into chunks of similar size, but continuously not randomly?
I did this but split the series into random chunks: chunks <- split(GC, f = 1:3)
I need continuous chunks, taking into account the date that is in the index.
0
votes
3
answers
66
views
Aggregating by multiple variables including time
I'm new to programming in R (and for that matter, programming at all...) and I'm trying to do some data analysis for a project for my class. I have some data that looks like this:
Id
Time
Heartrate
...
0
votes
2
answers
59
views
How to loop through a time series in R and identify a specific pattern?
I've imported price data for the S&P500 for the last 20 years and created a separate XTS containing only the close price for each day. I now need to create a loop that goes through the data and ...
0
votes
1
answer
65
views
How can I interpolate my time series to have the same size (for clustering purpose)?
I have a list (df_list) of 40 time series (class "xts" "zoo") with different lengths and would like to interpolate them against the time series with the longest length to obtain ...
1
vote
1
answer
77
views
Save quantmod::getSymbols output to csv file and then read csv as a xts object
What the easy way to save download stock symbol data (by quantmod) in csv file and read with original xts format?
getSymbols("000001.SZ", from = "1990-10-01", auto.assign = TRUE)
...
1
vote
2
answers
31
views
Add missing data xts and match them with a 0 value
I have problems with missing data, there are missing some minute values as you can see below...I use as.POSIXct to set the date as an index. How to add the missing Date to get a full ts and match them ...
2
votes
3
answers
103
views
failed when I was trying to use defuse-inject pattern in dplyr group_map function
Following is an example of what I am trying to achieve.
library(dplyr)
tbl.data <- tidyquant::tq_get(c("GS", "C", "BAC"))
to.xts <- function(group, group_key, ...
1
vote
3
answers
91
views
Why are daily returns all zeros using Quantmod?
I used the following code:
getSymbols(c("TSLA", "AAPL", "CSCO", "IBM"))
tsla<-TSLA['2022-01-03::2023-01-03']
aapl=AAPL['2022-01-03::2023-01-03']
csco=CSCO['...
2
votes
2
answers
62
views
Find the average of a number on a per minute basis
I've got a data frame with the following:
Id final_date_time Speed
2022484408 2016-04-12 07:21:00 97
2022484405 2016-04-12 07:21:05 102
2022484402 2016-04-12 07:21:10 105
2022484407 ...
0
votes
0
answers
27
views
Transform data frame to XTS object changes all numeric columns to character
I have a large dataframe (6,300 columns * 5,480 rows) of daily prices of stocks.
The data frame looks like this:
All the columns are marked numeric in the data frame (except the first one "Date&...
0
votes
0
answers
35
views
Calculating forward returns of an XTS object
I have a standard XTS stock price object. I would like to add a column that consists of the forward one year return. So, if the row I’m evaluating is 2019-03-01, I would like the return of 2019-03-...
6
votes
2
answers
196
views
Moving from a normal bar chart to a stacked bar on dygraphs
I've got an xts df of the following format:
structure(c("May 2022", "Jun 2022", "Jul 2022", "Aug 2022", "Sep 2022",
"Oct 2022", "Nov ...
2
votes
3
answers
48
views
Pivot Wider causing issues when as.yearmon is used
I have the following code:
library(zoo)
library(xts)
df1<-structure(list(Date = structure(c(13523, 13532, 13539, 13551,
13565, 13567, 13579, 13588, 13600, 13607, ...
1
vote
1
answer
310
views
Plot multiple series on a dygraph
I'm trying to plot multiple series on a dygraph line chart.
The df is of this structure:
structure(list(Date = structure(c(4216, 4216, 4217, 4217, 4218,
4218, 4219, 4219, 4220, 4220, 4221, 4221, 4222,...
0
votes
1
answer
40
views
Combine multiple xts-objects into a array with considering of the columns
Hi guys i'm wondering if there is a possibility to add multiple xts-objects into a 3-D-Array.
I want to put multiple Stock-Data from quantmod together in an (n x m x 4) array. the 4 is for respective ...
2
votes
2
answers
84
views
Time series - aggregate by a custom period of time
New to zoo/xts. I'm trying to go from monthly values to quarterly aggregates, defined as the sum of monthly values over a 3-month period ending on the last available month.
Reproducible example:
...
0
votes
2
answers
156
views
reading daily time series data in R using xts, error message
Dear Stackoverflow community,
I have been trying to read these set of daily stock market data using xts object and been getting different types of error messages, listed below.
The dataset contains ...
1
vote
2
answers
59
views
Is it possible to get the specific index of occurence when working with period.apply?
Assuming I worked with meteorological observations and wanted to know not only the daily maximum value but also the relevant timestamp, describing when this value was observed, is it possible to ...
0
votes
1
answer
27
views
How can I exclude file rows that are non numerical for use by XTS in R?
I have a reactive dataframe that reads a file that updates with new data. Occasionally the data in the file will have error messages or other non numeric lines and will break the order.by XTS function....
2
votes
1
answer
145
views
Is there a way to use a variable to get the last X observations of an XTS dataframe in R?
I'm trying to average the last X minutes of a dataset using a variable in R, I also do not know how to set my start date to today at midnight, so I've just plugged in 24 hrs from the enddate instead:
...
1
vote
1
answer
36
views
Indexing a collection of xts timeseries
I have a big xts timeseries file called 'data_ts'. Plotting
plot(data_ts)
all works fine. With {t1,t2} within bounds, I can also plot the subset:
plot(data_ts[t1:t2))
However, having 5 subsets I try ...
0
votes
0
answers
50
views
subscript out of bounds error when using ifelse function in R
I am trying to get a signal using ifelse in R, but , when comparing two xts objects, I get a subscript out of bounds error, even though they have the same number of rows and columns, and don't contain ...
0
votes
0
answers
163
views
Error in tk_xts(.) : could not find function "tk_xts" - Error when trying to convert a dataframe of stock returns into a time series object
I have a dataset of five stocks and their returns that I'm trying to modify the dataset and eventually create a covariance matrix. I've been trying the function below to convert the dataset into a ...
1
vote
0
answers
63
views
How to use own data with quantstrat and quantmod?
I am learning quantstrat and is working on a project where I use a local csv file which I exported from metatrader5. I managed to load the data into an xts object and called it fulldata_xts of which I ...
1
vote
1
answer
155
views
Merge multiple xts objects with matching or nearest dates
I have two xts files with daily data (The data is only one date for a month).
The first file is this: - The dates in this xts are typically end of the month trading dates in a given month.
structure(c(...
0
votes
1
answer
109
views
R/zoo: duplicate index entries in ‘order.by’ are not unique
I have an excel file containing 3 columns of data against a column of time at one hour interval. I tried to convert the data into a zoo object. But everytime i tried to that there is an error that ...
0
votes
1
answer
39
views
Window.xts in parallel
Why does window.xts not work in parLapply? The below code gives me error:
"Error in checkForRemoteErrors(val) :
8 nodes produced errors; first error: invalid time / time based class"
library(...
1
vote
2
answers
108
views
How to remove all "xts" "zoo" object from R environment?
I need help on removing all "xts" "zoo" object from R (global)environment.
I learned that I can remove dataframes by using the following:
rm(list=ls(all=TRUE)[sapply(mget(ls(all=...
-1
votes
1
answer
30
views
Changing a list of XTS elements to data frame. How?
I'm reading in a bunch of data which is in XTS format,
from a list of tags. After reading them in, I want to convert each one toa data frame in a loop for further
processing. So...I have something ...
1
vote
1
answer
86
views
R apply.hourly endpoints xts
I have a data.frame with weather data. The observations have a resolution of 15 minutes and each timestamp is in the following format: %Y-%m-%d %H:%M:%S.
I am working on a Shiny application where I ...
0
votes
1
answer
118
views
Finding the maximum in an xts column within the last X hrs
I have a dataset within a reactive dygraph that looks like this:
data()$data.o
date
data.o
2022-07-21 12:10 AM
400.1
2022-07-21 12:11 AM
33.9
2022-07-21 12:12 AM
32.5
2022-07-21 12:13 AM
35.1
...
0
votes
1
answer
397
views
Did quandl end cme data on June 30th 2022?
library(Quandl)
library(xts)
Quandl.api_key("your_api_key")
cl <- Quandl("CME/CLU2022", type = "xts")
This data ends on June 30th 2022. As of today 7/14/2022, it ...
0
votes
0
answers
91
views
How to transpose a xts Matrix? xts(); as.xts()
how can I transpose a xts Matrix?
I do this before
M<-Z
d <- as.Date(1:nrow(M))
M<- xts(M, order.by=d)
class(M)
[1] "xts" "zoo"
# Matrix M has size 700x70 as xts format. ...
0
votes
1
answer
34
views
Join a xts object and a data frame by date, one day forward, in R
I have the following xts object and data frame in R.
xts:
data frame:
I need to join them by date, the date in the xts object being one workday forward the date in the data frame, for each record ...
0
votes
1
answer
147
views
XTS in R studio
I'm reading a binary output file of a program using a R package. When I executed the below line of code I see a data structure as shown in the snapshot under the 'Environment' tab of R Studio.
output &...