PureBytes Links
Trading Reference Links
|
If you're getting beat up like I am this week, you might have
wondered if your system would do better if you didn't trade at all
around holidays. I wondered that, so I wrote a function to detect
when we're near a holiday so I could backtest it.
If you try the same experiment, you might be surprised. I found my
system actually performs BETTER in the few days before a holiday!
Here's the function. I entered the holidays for the last 3 years,
but I'm not 100% certain I have them all right. (I lost my holiday
lists when I re-installed NT & TS last January.) If someone would
like to check them, I'd appreciate it.
Pass the function the date you want to test, or Date if you want to
test the current date. The Before and After params specify how many
trading days before/after the holiday you want to detect. Returns 0
if you're not near a holiday, or <>0 if you are. See the comments
for more details.
Gary
{ FUNCTION HolidayBlackout
Checks to see whether you are within Before trading days before a
holiday,
or After trading days after it.
Returns the # of days before (negative) or after (positive).
Since you never have data on holidays, 0 means "not near a holiday."
Before and After must be >= 0 and <= 5.
The code assumes that there are no holidays within a week of your holiday,
so Saturday/Sunday are the only non-trading days within 1 week.
Gary Fritz 8/30/2000
}
inputs: Dat(NumericSimple), Before(NumericSimple), After(NumericSimple);
vars: Init(0), MaxHoliday(0), HolIdx(0), NextHol(0);
vars: Delta(0), DeltaBefore(0), DeltaAfter(0), DatOffset(0);
arrays: Holidays[40](0);
{ Set up the holiday array }
if Init = 0 then begin
Holidays[0] = 960101;
Holidays[1] = 960527;
Holidays[2] = 960704;
Holidays[3] = 960902;
Holidays[4] = 961128;
Holidays[5] = 961225;
Holidays[6] = 970101;
Holidays[7] = 970217;
Holidays[8] = 970526;
Holidays[9] = 970704;
Holidays[10] = 970901;
Holidays[11] = 971127;
Holidays[12] = 971225;
Holidays[13] = 980101;
Holidays[14] = 980216;
Holidays[15] = 980525;
Holidays[16] = 980704;
Holidays[17] = 980907;
Holidays[18] = 981126;
Holidays[19] = 981225;
Holidays[20] = 990101;
Holidays[21] = 990118;
Holidays[22] = 990215;
Holidays[23] = 990402;
Holidays[24] = 990531;
Holidays[25] = 990705;
Holidays[26] = 990906;
Holidays[27] = 991125;
Holidays[28] = 991224;
Holidays[29] = 991231;
Holidays[30] = 1000117;
Holidays[31] = 1000221;
Holidays[32] = 1000421;
Holidays[33] = 1000529;
Holidays[34] = 1000704;
Holidays[35] = 1000904;
Holidays[36] = 1001123;
Holidays[37] = 1001225;
MaxHoliday = 37;
Init = 1;
end;
{ Find the next holiday that is no more than 7 days before Dat }
DatOffset = JulianToDate(DateToJulian(Dat) - 7);
NextHol = Holidays[0];
HolIdx = 0;
while DatOffset > NextHol and HolIdx < MaxHoliday begin
HolIdx = HolIdx + 1;
NextHol = Holidays[HolIdx];
end;
{ Calculate # trading days between Dat and the holiday,
adjusting for weekends. Delta < 0 when Dat is before the holiday. }
Delta = DateToJulian(Dat)- DateToJulian(NextHol) ;
if Delta < 0 and DayOfWeek(Dat) >= DayOfWeek(NextHol) then Delta = Delta + 2;
if Delta > 0 and DayOfWeek(Dat) <= DayOfWeek(NextHol) then Delta = Delta - 2;
{ Return Delta if we're within Before/After trading days }
if (Delta < 0 and Delta >= -Before) or (Delta > 0 and Delta <= After)
then HolidayBlackout = Delta
else HolidayBlackout = 0;
Attachment Converted: "c:\program files\qualcomm\eudora\attach\HolBlkout.ela"
|