I am doing a multi period-period analysis and iI need to extract values between two dates from a table based on results.
The values are in a time series xtsan xts object. i will call this named data.
The start and beginningend of my calculation lies between those dates. These same dates are used as rownames somewhere in the xtsa data.frame named dataresults file.
start_date <- head(rownames(results), n=1)
end_date <- tail(rownames(results), n=1)
I also identify the colcolumn names with this vector:
>col_names> col_names
[1] "Stock1", "Stock2", "Stock3"
what I need to do is callextract the valuesobservations in the data file which lie atobject in the columns in col_names and between start_date and end_date
EDIT
I thank akrun for the code bellow. It provides part of the solution to my problem.
some data:
library(xts)
data(sample.xts)
start_date <- '2007-01-02'
end_date <- '2007-01-05'
col_names <- c('Open', 'High')
The code bellow grabs the values within that range.
sample.xts[paste(start_date, end_date, sep="/"), col_names]
What i really need is the next 5 values for example. so akrun suggested this:
sample.xts[paste(as.Date(start_date) + 5, as.Date(end_date) + 5, sep="/"), col_names]
The problem is that i have trading days so that excludes not only weekends but also holidays etc.. so i would like to make the above arbitrary of calendar days which is the format of as.Date. I need the next 10 values from that table rather than the next 10 calendar days.