I'm usin R language and working with time series daily stock index from differents countries. In order to make comparisons between of differents indexes,(like correletaion, causality etc..) I need that all the series have the same number of lines, but because diferents holidays in diferents countries, the number of lines in each series change.
I'm working with extracted files from yahoo finance, with format .csv, like...
> head(sp)
> Date Open High Low Close Volume Adj.Close
>1288 2010-01-04 1116.56 1133.87 1116.56 1132.99 3991400000 1132.99
>1287 2010-01-05 1132.66 1136.63 1129.66 1136.52 2491020000 1136.52
>1286 2010-01-06 1135.71 1139.19 1133.95 1137.14 4972660000 1137.14
I need... for example, suppose that day 2010-01-07 is a holiday, in this case, the next line (line 1285) in the file is the day 2010-01-08:
> head(sp)
> Date Open High Low Close Volume Adj.Close
>1288 2010-01-04 1116.56 1133.87 1116.56 1132.99 3991400000 1132.99
>1287 2010-01-05 1132.66 1136.63 1129.66 1136.52 2491020000 1136.52
>1286 2010-01-06 1135.71 1139.19 1133.95 1137.14 4972660000 1137.14
>1285 2010-01-08 1140.52 1145.39 1136.22 1144.98 4389590000 1144.98
In need fill the gap in 2010-01-07 with the previus day data, like :
> head(sp)
> Date Open High Low Close Volume Adj.Close
>1288 2010-01-04 1116.56 1133.87 1116.56 1132.99 3991400000 1132.99
>1287 2010-01-05 1132.66 1136.63 1129.66 1136.52 2491020000 1136.52
>1286 2010-01-06 1135.71 1139.19 1133.95 1137.14 4972660000 1137.14
>1285 2010-01-07 1135.71 1139.19 1133.95 1137.14 4972660000 1137.14
>1284 2010-01-08 1140.52 1145.39 1136.22 1144.98 4389590000 1144.98
How I can do this ???
My code is (look all the library that I tried using for solve my problem kkk)
>library(PerformanceAnalytics)
>library(tseries)
>library(urca)
>library(zoo)
>library(lmtest)
>library(timeDate)
>library(timeSeries)
>setwd("C:/Users/Fatima/Documents/R")
>sp = read.csv("SP500.csv", header = TRUE, stringsAsFactors = FALSE)
>sp$Date = as.Date(sp$Date)
>sp = sp[order(sp$Date), ]
Sorry about my bad english