[R-SIG-Finance] Help with date arithmetic

Joe W. Byers Joe-Byers at utulsa.edu
Sat Oct 21 21:30:43 CEST 2006

All here is what I came up with to increment over non-business days and 
NYSE holidays.  I would appreciate any help in refining this code to be 
more generic for use with vectors, more date formats, and other 
holidays.  It is extremely slow to run this function over a large time 
sequence.  I think I could change the code from using fCalendar 
timesequence() to using the date.mdy()$year for part of the code, but I 
am still learning these things in R.

#function call

# Created by: Joe W. Byers
# Date: 10/20/06
#Method to increment a give date to the next business day given 
holidayNYSE() holidays
	#need to add date coersion if data numeric
	# need to add ability to perform over a vector and return all increments
	# need to add ability to perform with different holidays beside NYSE
	Loop=T; # set loop test
		if (t1==T) {Loop=F}
		else {ans<-format.Date(as.date(ans,order='mdy')+inc,format)}
Thank you

Joe W. Byers wrote:
> I have the following day
> dts<-('02/08/2002');
> I want to return a vector of character dates by adding 1 to the current 
> day and adding the number of non business days for a weekend and/or 
> holiday if they occur to get the following results
> should.be.results<-('02/09/2002','02/12/2002');
> I can handle the first calculation but I can not find how to increment 
> the date for non business days.
> results<-c(format.Date(as.date(dts,order='mdy')+1,'%m/%d/%Y'),
> 	I need help  here);
> I have review the fCalendar docs and others.  I have also created a time 
> sequence for this project where I removed the non-business days using 
> the isBizday method.  Any help is greatly appreciated.
> Thank you
> Joe

More information about the R-SIG-Finance mailing list