0

Dear Stackoverflow Community,

I am working on the codes by https://rpubs.com/rsayed/573439 to "measure the volatility spillovers and connectedness" using Diebold-Yilmaz Methodology (https://github.com/rhameysayed/Spillovers-and-Connectedness/blob/master/Connected__Spillover.Rmd).

QUESTION

  1. But I am facing a problem with the code when I use my dataset, it says I have incorrect number of dimensions (below).
vol.fn <- function(history){asinh(sqrt(252*0.361*log(history[,3]/lag(history[,2]))^2))}
  1. The author uses this code for data pulled from quantmod and also states that the above code follows these equations and I am completely lost as to how to fix it.
\begin{equation}
  \label{eq:variance}
  \sigma^2_{it} = 0.361[ln(P^{max}_{i,t}) - ln(P^{min}_{i,t-1}))]^2 
\end{equation} 

\begin{equation} 
  \sigma_{it} = sinh^{-1}(\sqrt{252*\sigma^2_{it}})
  \label{eq:stdev}
\end{equation}

Do you think its a problem with my dataset? or the code needs to be changed to fit to my dataset?

  1. I am still relatively new to stackoverflow, so I am not sure if i used the dput function to show my data correctly, but please find my dataset in the NOTE section (Note 1: Dataset).
  2. Would really appreciate it if someone in the community could help out with this problem or give some light on how to fix it Thank You Very Much!

CODE

df_my_data <- read.csv('C:/Users/s/Desktop/R/intro/data/data_stock_returns.csv')
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 ...

library(kableExtra)
vol.fn <- function(history){asinh(sqrt(252*0.361*log(history[,3]/lag(history[,2]))^2))}
vol1 <- lapply(df_my_data,vol.fn)

Error in history[, 3] : incorrect number of dimensions Called from: FUN(X[[i]], ...)>

vol.data <- Reduce(merge.all,vol1)
vol.data <- na.omit(vol.data)

NOTE 1:DATASET

df_my_data<- structure(list(Date = c("4/1/2000","5/1/2000","6/1/2000","7/1/2000","10/1/2000","11/1/2000","12/1/2000",
"13/01/2000","14/01/2000","17/01/2000","18/01/2000","19/01/2000","20/01/2000",
"21/01/2000","24/01/2000","25/01/2000","26/01/2000","27/01/2000","28/01/2000","31/01/2000"), 
SXXP = c(0,0,0,0,0,-0.0014,-5.99E-06,0.0011,0.0051,0.00148,-0.0045,-0.0010,-0.00055,-0.00060,0.00108,
-0.0037,0.0024,0.0028,-0.0003,-0.0044),STJ = c(0,-0.024,0.09950.061052,-0.045,-0.0166,0.004,
-0.0505,0.0665,0.0083,-0.041,-0.0387,0.040,0,-0.004,-0.05183,-0.01366,
0.0623,-0.0326,-0.0494),ISP = c(-0.0209,-0.0020,-0.021220.0230,-0.0172,0.004,
-0.0076,-0.011,0.0143,-0.0327,-0.0173,-0.0299,0.0115,0.0345,
-0.0231,-0.0186,0.0244,-0.0354,-0.0174,-0.0225),
INGA = c(-0.0274,-0.00854, -0.00689,0.01961,0.00119,-0.01190,-0.03115,
-0.0108,0.02370,-0.00701,
-0.01059,0.00428,-0.0163,-0.00669,-0.03093,-0.00713,0.000566,0.0126,-0.00335,-0.0335)),
class = "data.frame", row.names = c(NA, -20L))

df_my_data

   Date         SXXP          STJ          ISP         INGA
1    4/1/2000  0.000000000  0.000000000 -0.020981703 -0.027431486
2    5/1/2000  0.000000000 -0.024830700 -0.002098372 -0.008543926
3    6/1/2000  0.000000000  0.099537037 -0.021224101 -0.006897636
4    7/1/2000  0.000000000  0.061052632  0.023030650  0.019615734
5   10/1/2000  0.000000000 -0.045634921 -0.017276138  0.001192973
6   11/1/2000 -0.001466894 -0.016632017  0.004786734 -0.011902231
7   12/1/2000 -0.000005990  0.004228330 -0.007684673 -0.031156279
8  13/01/2000  0.001141502 -0.050526316 -0.011744871 -0.010836622
9  14/01/2000  0.005177323  0.066518847  0.014313391  0.023706947
10 17/01/2000  0.001487096  0.008316008 -0.032755573 -0.007018666
11 18/01/2000 -0.004585252 -0.041237113 -0.017359781 -0.010597812
12 19/01/2000 -0.001014728 -0.038709677 -0.029994001  0.004283601
13 20/01/2000 -0.000557140  0.040268456  0.011564626 -0.016357380
14 21/01/2000 -0.000600562  0.000000000  0.034572354 -0.006690365
15 24/01/2000  0.001081653 -0.004301075 -0.023193973 -0.030932722
16 25/01/2000 -0.003745210 -0.051835853 -0.018663037 -0.007136289
17 26/01/2000  0.002465556 -0.013667426  0.024473692  0.000566533
18 27/01/2000  0.002832696  0.062355658 -0.035412342  0.012663463
19 28/01/2000 -0.000399600 -0.032608696 -0.017498440 -0.003359653
20 31/01/2000 -0.004428694 -0.049438202 -0.022540398 -0.033524404

0 Answers0