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 5030 observations, from 4/01/2000-22/07/2019.
- I have checked for NAs in the dataset, and there are none
- I have tried changing the format of the dataset from dd/mm/yyyy to yyyy/mm/dd, it doesnt seem to work
- i checked to see if I change it to quarterly and then try to read it if it works, and it does. So I think there is a problem with the code that I am using to read the daily data.
- The dataset is the package
SystemicR
author's dataset calleddata_stock_returns
, and im trying to recreate the results before I try my own dataset. Below is the dataset and the code I tried. Would really appreciate it if someone in the community could help out with this problem. Thank You
Date | SXXP | STJ | ISP | INGA | Index |
---|---|---|---|---|---|
4/01/2000 | 0 | 0 | -0.0209 | -0.0274 | 1 |
5/01/2000 | 0 | -0.02484 | -0.0020 | -0.00854 | 2 |
6/01/2000 | 0 | 0.0995 | -0.0212 | -0.00689 | 3 |
7/01/2000 | 0 | 0.061 | 0.02303 | 0.01961 | 4 |
10/01/2000 | -0.00147 | -0.0456 | -0.0172 | 0.00119 | 5 |
.......... | ........ | ....... | ....... | ........ | .... |
22/07/2019 | 0 | -0.0127 | 0.00124 | 0.0029756 | 5030 |
df_my_data <- read.csv(('C:/Users/s/Desktop/R/intro/data/data_stock_returns.csv'), sep = ";")
str(df_my_data)
'data.frame': 5030 obs. of 74 variables:
$ Index : int 1 2 3 4 5 6 7 8 9 10 ...
$ SXXP : num 0 0 0 0 0 ...
$ STJ : num 0 -0.0248 0.0995 0.0611 -0.0456 ...
$ ISP : num -0.021 -0.0021 -0.0212 0.023 -0.0173 ...
xts(df_my_data, order.by = as.Date(rownames(df_my_data$Date), "%d/%m/%Y"))
df_my_data$Date <- as.Date(df_my_data$Date)
I get the below 2 error message
Error in
$<-.data.frame
(*tmp*
, Date, value = numeric(0)) : replacement has 0 rows, data has 5030
Error in xts(df_my_data, order.by = as.Date(rownames(df_my_data), "%d/%m/%Y")) : 'order.by' cannot contain 'NA', 'NaN', or 'Inf'
df_my_data$Date_xts <- as.xts(df_my_data[, -1], order.by = (df_my_data$Date))
I get another error message
Error in xts(x, order.by = order.by, frequency = frequency, ...) : order.by requires an appropriate time-based object
library(SystemicR)
l_result<- f_CoVaR_Delta_CoVaR_i_q(data_stock_returns)