开发者

Date and financial data

开发者 https://www.devze.com 2023-04-01 01:25 出处:网络
I have a set of one year finacial data. The data is collected in working days. Is there any way in R to assign to each data point a date given that t开发者_开发知识库he first data point was collected

I have a set of one year finacial data. The data is collected in working days. Is there any way in R to assign to each data point a date given that t开发者_开发知识库he first data point was collected for eaxmple on juanari the 3th.


You need to take two steps to get to a solution:

  1. Create a sequence of dates using seq.Date
  2. Use wday to calculate the day of the week and remove all days with value 1 (Sunday) and 7 (Saturday)

The code and results:

startdate <- as.Date("2011-01-03")
dates <- seq(startdate, by="1 day", length.out=15)
dates[wday(dates) != 1 & wday(dates) != 7]
 [1] "2011-01-03" "2011-01-04" "2011-01-05" "2011-01-06" "2011-01-07"
 [6] "2011-01-10" "2011-01-11" "2011-01-12" "2011-01-13" "2011-01-14"
[11] "2011-01-17"

PS. You will have two keep a separate lists of holidays in your region and remove these from the list.


The timeDate package offers functions to extract business days in whatever financial center you happen to favor (there are almost 500 such financialcenters in their classification).

0

精彩评论

暂无评论...
验证码 换一张
取 消