How do i manage the following problem:
Say i have a daily strategy and want to buy every month on the 10th or the next trading day in case the 10th is a holiday/weekend. In the datafeed of the security the non-tradingday simply do not exist. So if the 10th is for example a sunday the datafeed jumps from friday 8th directly to monday 11th.
Any ideas how i can accomblish this conveniently?
I coded something similar recently for Doctrading, about finding the last day of month: https://www.prorealcode.com/topic/astuce-dernier-jour-du-mois/page/2/
At the beginning of the thread, you can find this code snippet that will give you the day of the week number by looking with its date:
//find the day number with a date
myYear=2017
myMonth=2
myDay=13
if myMonth >= 3 then
D = (((23*myMonth)/9) + myDay + 4 + myYear + (myYear/4) - (myYear/100) + (myYear/400) - 2) mod 7
else
z = myYear - 1
D = (((23*myMonth)/9) + myDay + 4 + myYear + (z/4) - (z/100) + (z/400) ) mod 7
endif
return D
It’s the Keith algorithm. So if the D value is a Sunday for the 10th day of the month you look at, then you know you have to adapt the strategy to trade the next day.. Hope I’m clear 🙂