Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Business Days...
#1
I need to calculate funds that will be available a certain number of business days (Mon-Fri and non-holidays)

I guess the business days would be easy to figure out if SYSTEMTIME st.wDayOfWeek does not equal 0 or 6...but holidays? I figure a list would of dates would work...is there a database or something that has US Bank holidays?

What would be the best way to go about this?

Essentially I'll be calculating available funds deposited based on different types of payment types Cash=0 business days, Checks=5 business days, and Credit Cards=3 business days. That way I'll be able to click a button in my program and get how much I have available right now and how much I have pending. It will save me a phone call to the bank everytime I want to put in an order with a distributor.

Thanks,
Jimmy Vig
#2
Is there a better way than this?
Function Business_Days_Add
Code:
Copy      Help
out
DATE d.getclock
SYSTEMTIME st
int Days=8
rep Days
,;Run
,d=d+1
,d.tosystemtime(st)
,if st.wDayOfWeek=0
,,goto Run
,if st.wDayOfWeek=6
,,goto Run
out "%i-%i-%i" st.wMonth st.wDay st.wYear
#3
Function IsTodayHoliday
Code:
Copy      Help
;/
function!

;Returns 1 if today is a holiday (Sunday, Saturday, etc), 0 if not.
;Uses "$my qm$\nbd.ini" that is created using macro "Create Holidays File". Error if the file does not exist.

;EXAMPLE
;if IsTodayHoliday
;,out "holiday"


str inifile="$my qm$\nbd.ini"
if(!dir(inifile)) mes- "File not found:[]%s[][]Read macro 'Create Holidays File'." "" "x" inifile

DATE d.getclock
SYSTEMTIME st
d.tosystemtime(st)
str s1 s2(st.wDay) s3.format("%i-%i" st.wYear st.wMonth)
ret rget(s1 s2 s3 inifile)

Macro Create Holidays File
Code:
Copy      Help
;This macro creates ini file containing sundays and saturdays of next 10 years and of the remainder of this year.
;Run this macro. Then edit the file: add other holidays and possibly remove sun/saturdays that aren't holidays. For each day, use format daynumber=anything or just daynumber=.
;The file later will be used by IsTodayHoliday.


str inifile.expandpath("$my qm$\nbd.ini")
if(dir(inifile))
,mes- "The file already exists. Overwrite?" "" "OC!"
,mes- "Are you sure?" "" "OC!"
int nyears=10 ;;you can change this; it is number of years not including this year

str ini
DATE d.getclock
SYSTEMTIME st
int y ymax month
rep
,d.tosystemtime(st)
,
,if(st.wYear!=y)
,,y=st.wYear
,,if(!ymax) ymax=y+nyears
,,if(y>ymax) break
,
,if(st.wMonth!=month) month=st.wMonth; ini.formata("[%i-%i][]" y month) ;;write year and month as ini section
,
,sel st.wDayOfWeek
,,case [0,6] ini.formata("%i=%s[]" st.wDay iif(st.wDayOfWeek "sat" "sun")) ;;write sundays and saturdays
,
,;other (or some of other) holidays can be added/removed here instead of editing the ini file. Example:
,sel st.wMonth
,,case 1 sel(st.wDay) case 1 ini.formata("%i=%s[]" st.wDay "New Year")
,,;and so on
,
,d=d+1

;out; out ini
ini.setfile(inifile)
inifile-"''"; inifile+"''"
run "notepad.exe" inifile ;;open for editing
#4
That's pretty good!

I need to be able to send a date to IsTodayHoliday...So that I can count back from d.getclock a certain number of non-holidays.

The only thing is that it creates the Holidays on the same day for each reoccurring year. I need the holidays to be the observed US Bank Holidays which are generally like 3rd monday in January (Martin Luther King's Birthday)

Here's a link for US Bank Holidays: http://www.buyusa.gov/uk/en/us_bank_holidays.html

This will work so far, I'll just have to run it every year...and if I forget...that's trouble.
#5
The macro adds sundays and saturdays for next 10 years. Then open the ini file in notepad and add other holidays for all 10 years. When creating the macro i did not know where to find us bank holidays.
#6
Changed the example too...

Function IsTodayHoliday
Code:
Copy      Help
function DATE&d
;Returns 1 if today is a holiday (Sunday, Saturday, etc), 0 if not.
;Uses "$my qm$\nbd.ini" that is created using macro "Create Holidays File". Error if the file does not exist.

;EXAMPLE
;DATE d="12/25/09"
;if IsTodayHoliday(d)
,;out "Holiday"


str inifile="$my qm$\nbd.ini"
if(!dir(inifile)) mes- "File not found:[]%s[][]Read macro 'Create Holidays File'." "" "x" inifile

SYSTEMTIME st
d.tosystemtime(st)
str s1 s2(st.wDay) s3.format("%i-%i" st.wYear st.wMonth)
ret rget(s1 s2 s3 inifile)
#7
Bank Holidays are kind of a pain in the neck.

Most of them are a certain Monday in a month, some of them are fixed, and some are the closest weekday...such as Independence Day July 4th
#8
Sorry about posting so much...

Here's a better link: http://www.opm.gov/Operating_Status_Sche...l/2008.asp

Here is a list:
United States Holidays

FIXED HOLIDAYS*

New Year’s Day - January 1
Independence Day - July 4
Veterans Day - November 11
Christmas Day - December 25

ROTATING HOLIDAYS

Birthday of Martin Luther King, Jr. - 3rd Monday in January
Washington’s Birthday - 3rd Monday in February
Memorial Day - Last Monday in May
Labor Day - 1st Monday in September
Columbus Day - 2nd Monday in October
Thanksgiving Day - 4th Thursday in November

*If on a Saturday - Holiday observed on Friday. If on a Sunday - Holiday observed on Monday
#9
Messed with some code today. It works, its a bit clunky and I need to incorporate it into the IsHoliday macro to populate the ini file.
Here's what I got so far:

Function US_Holiday
Code:
Copy      Help
function [YearDate]

;Example:
;US_Holiday 1999

;Outputs:
;1/1/1999
;1/18/1999
;2/15/1999
;5/31/1999
;9/6/1999
;10/11/1999
;11/11/1999
;11/25/1999

;Just US_Holiday on it's own will output US holidays for the current year


if YearDate=0
,_s.time("yyyy")
,YearDate=val(_s)
_s.format("01/01/%i" YearDate)
DATE d=_s
DATE d2
int i=1
int Month=1
SYSTEMTIME st st1
d.tosystemtime(st)
int Year=st.wYear
int yCounter wCounter
for yCounter 0 48 1
,;Run
,for wCounter 0 7 1
,,d.tosystemtime(st)
,,int month=st.wMonth
,,str Fixed.format("%i/%i" st.wMonth st.wDay)
,,if(month>Month) Month+1;i=1;goto Run
,,_s.format("%i:%i:%i" st.wMonth st.wDayOfWeek i)
,,sel(_s)case ["1:1:3","2:1:3","9:1:1","10:1:2","11:4:4"] ;out d
,,sel(_s)case "5:1:4" d2=d;case "5:1:5" d2=d;case "6:1:1";out d2
,,sel(Fixed)case ["1/1","7/4","11/11","12/25"]
,,,sel(st.wDayOfWeek)case 0 d2=d-1;case 6 d2=d+1;case [1,2,3,4,5] d2=d;out d2
,,d=d+1
,i+1

Thanks again for all your help!!
Jimmy Vig


Forum Jump:


Users browsing this thread: 1 Guest(s)