Hi,
Is there any chance to visualize (or have access to) the internal code of function @TRADEDAY??
Regards
How visualize functions?
It's relatively straightforward once you have a perpetual calendar. This maps year,month,day to a sequential day number in the Gregorian calendar. (Our calculations all assume that dates back to Jan 1, 1 A.D. are kept under the Gregorian calendar).
#define LEAPYEAR(y) (!((y)%4)&&((y)%100||!((y)%400)))
#define PREJAN1(y) (365L*((y)-1)+((y)-1)/4-((y)-1)/100+((y)-1)/400)
#define DAYOFF1900 6
extern CTAG JULIANDATE YMDToJulian(YMDTYPE year,YMDTYPE month,YMDTYPE day)
/*
** Returns the number of days (based at 1) since Jan 1 of the base
** year (0001) or (1901), using the Gregorian calendar.
*/
{
SMALLINT dayOfYear,i;
/*
** If needed, normalize year and month
*/
if (month > 12)
year += (month - 1) / 12 , month = (month - 1) % 12 + 1;
AdjustFebruary(year);
dayOfYear = day;
for (i = 1 ; i < month ; i++)
dayOfYear += mday[i-1];
return PREJAN1(year)+dayOfYear;
}
extern CTAG INTEGER TradingDayCount(INTEGER number,INTEGER request,DATEINFO DATA *base)
/*
** Returns the number of "trading days" in entry "number" in "base". The
** request is 1=Mondays,2=Tuesdays,...,7=Sundays.
*/
{
YMDINFO dateYMD;
PANELSELECTOR indiv;
INTEGER length;
SMALLINT day,daygap;
REALTYPE begin,end;
if (request <0> 7)
return 0;
/*
** Figure out the number of days covered by the entry
*/
EntryToFullDate(number,base,&dateYMD,&indiv);
DateToJulianRange(&dateYMD,base,&begin,&end);
length = (INTEGER) (end - begin);
/*
** Figure out which day (1=Monday,...,7=Sunday) marks the start of the
** entry.
*/
day = ((INTEGER) begin + DAYOFF1900) % 7 + 1;
/*
** Determine the number of the "request" days. This is the length/7 plus
** one extra if the requested day of the week is close enough to the
** start day to be covered to the excess days.
*/
daygap = request - day;
if (daygap <0> daygap);
}
#define LEAPYEAR(y) (!((y)%4)&&((y)%100||!((y)%400)))
#define PREJAN1(y) (365L*((y)-1)+((y)-1)/4-((y)-1)/100+((y)-1)/400)
#define DAYOFF1900 6
extern CTAG JULIANDATE YMDToJulian(YMDTYPE year,YMDTYPE month,YMDTYPE day)
/*
** Returns the number of days (based at 1) since Jan 1 of the base
** year (0001) or (1901), using the Gregorian calendar.
*/
{
SMALLINT dayOfYear,i;
/*
** If needed, normalize year and month
*/
if (month > 12)
year += (month - 1) / 12 , month = (month - 1) % 12 + 1;
AdjustFebruary(year);
dayOfYear = day;
for (i = 1 ; i < month ; i++)
dayOfYear += mday[i-1];
return PREJAN1(year)+dayOfYear;
}
extern CTAG INTEGER TradingDayCount(INTEGER number,INTEGER request,DATEINFO DATA *base)
/*
** Returns the number of "trading days" in entry "number" in "base". The
** request is 1=Mondays,2=Tuesdays,...,7=Sundays.
*/
{
YMDINFO dateYMD;
PANELSELECTOR indiv;
INTEGER length;
SMALLINT day,daygap;
REALTYPE begin,end;
if (request <0> 7)
return 0;
/*
** Figure out the number of days covered by the entry
*/
EntryToFullDate(number,base,&dateYMD,&indiv);
DateToJulianRange(&dateYMD,base,&begin,&end);
length = (INTEGER) (end - begin);
/*
** Figure out which day (1=Monday,...,7=Sunday) marks the start of the
** entry.
*/
day = ((INTEGER) begin + DAYOFF1900) % 7 + 1;
/*
** Determine the number of the "request" days. This is the length/7 plus
** one extra if the requested day of the week is close enough to the
** start day to be covered to the excess days.
*/
daygap = request - day;
if (daygap <0> daygap);
}