How to avoid bank holidays in trading system?
Forums › ProRealTime English forum › ProOrder support › How to avoid bank holidays in trading system?
- This topic has 14 replies, 1 voice, and was last updated 1 year ago by SkippyTrader.
-
-
07/05/2018 at 5:04 PM #7537507/05/2018 at 5:08 PM #7537807/05/2018 at 6:38 PM #7539207/05/2018 at 6:48 PM #75394
Beyond noting the date of each bank holiday that you want to avoid and then including it in a IF THEN condition within or surrounding your strategy I can not think of another way to do what you want. Creating a back test to prove whether this is worth doing would be quite labour intensive.
07/05/2018 at 6:49 PM #7539507/05/2018 at 7:17 PM #7539807/05/2018 at 7:32 PM #75399I guess that if there is a holiday that is on exactly the same date every year then you could do this:
123456fixeddate1 = 0105 //1st Maydate1 = (openyear * 10000) + fixeddate1if opendate <> date1 then(your strategy)endifYou could also I guess code something to work out if the fixed date falls on a weekend and then move it to the Monday but I will leave that one to you as I’m not sure that the effort is worth the benefit. 🙂
1 user thanked author for this post.
07/06/2018 at 7:03 AM #75415You can find the day of the week number with this code snippet:
1234567891011121314//find the day number with a datemyYear=YearmyMonth=MonthmyDay=Dayif myMonth >= 3 thenD = (((23*myMonth)/9) + myDay + 4 + myYear + (myYear/4) - (myYear/100) + (myYear/400) - 2) mod 7elsez = myYear - 1D = (((23*myMonth)/9) + myDay + 4 + myYear + (z/4) - (z/100) + (z/400) ) mod 7endifreturn dReplace myYear,myMonth and myDay with YYYY, MM, DD number format. In this example it basically returns the day of the week of the current day.
3 users thanked author for this post.
07/06/2018 at 8:32 AM #75424Isn’t that what (OPEN)DAYOFWEEK does?
07/06/2018 at 8:45 AM #75428Yes, but how do you know what opendayofweek was the 12th September 2002? This is the purpose of this snippet.
07/06/2018 at 8:46 AM #75429Isn’t that what (OPEN)DAYOFWEEK does?
Yes – but it isn’t such a good party trick. Memorise the above calculation and amaze your friends at every party by telling them what day of the week any date in history was!
07/06/2018 at 9:15 AM #75432What use is knowing what day of the week was July 4th (for Usa) or June 2nd (for Italy) or Christmas?
It was a Holiday for sure, this year, last year as well as many years ago!
So, once you hard code a holiday in your strategy, that’s all
123If Month = 7 and Day = 4 then //July 4th// it’s holiday, no matter if monday or sundayEndifIn some countries, mostly christian/latin countries, Easter is a holiday AND it always occur on a sunday. In these countries (Italy, Spain, France…) the day following Easter (Monday) is a holiday, but since Easter is a mobile holiday you have to calculate it to know the following day will be a holiday. To calculate Easter, you can find formulas over the internet.
That’s what I meant, any calculation is necessary only for mobile holidays.
@nicolas thanks to that snippet I know I was born on a Sunday… many… many seasons ago!07/06/2018 at 9:33 AM #75433In the UK bank holidays are always on a Monday. So for example there is always a bank holiday on the first Monday in May. In 2019 this will be on the 6th May. So if the OP wants to avoid trading on those days in other markets that are still open then he will need to calculate the first Monday in May every year. I think there are four bank holidays like this each year.
Easter in Greece is rarely the same as Easter in other countries as it is calculated using a different calender – but then I guess the Greek Easter will have little effect on markets. 🙂
07/06/2018 at 9:39 AM #75435Got it. Thanks!
01/07/2023 at 1:37 AM #206935[Old but just adding another way, if anyone interested]
The other way would be download the “CSV” of dates & times of holidays from any public government database, this would already be formatted in the tidy data style that aligns with PRT date and time formats, so just need to copy+paste it into your strategies code [For PRT people they have API’s for updating in real-time, if ever consider implementing holidays as function within PRT].
Most governments provide these on some public database site, for example data.gov.au for Australia would show all the full and half-day trading holidays for the upcoming years.
And regarding this using the earlier methods:
You could also I guess code something to work out if the fixed date falls on a weekend and then move it to the Monday
I assume something like this would work to move the holiday to the Monday or Friday:
123456789101112131415161718192021222324252627282930fixeddate1 = 0105 //1st Maydate1 = (openyear * 10000) + fixeddate1//find the day number with a datemyYear=OpenYearmyMonth=OpenMonthmyDay=OPenDayif myMonth >= 3 thenD = (((23*myMonth)/9) + myDay + 4 + myYear + (myYear/4) - (myYear/100) + (myYear/400) - 2) mod 7elsez = myYear - 1D = (((23*myMonth)/9) + myDay + 4 + myYear + (z/4) - (z/100) + (z/400) ) mod 7endif// Holiday Dates:fixeddate1 = 0105 //1st Maydate1 = (openyear * 10000) + fixeddate1IF d >= 1 AND d<= 5 THENHoliday = date1Elsif d < 1 THENHoliday = date1+1Elsif d > 5 THENHoliday = date1-1ENDIFif opendate <> Holiday then(your strategy)endif2 users thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on