I live in Europe. Week starts on Monday and ends on Sunday.
Today is Friday, the 5th day of the week.
https://1drv.ms/x/s!AncAhUkdErOkgqR6jJ76GcWrCJozpQ?e=mRH7Ab
=Weekday(Today();2)
shows Thursday as weekday, not friday.
Why?
And why shows Returntype 1 (or omitted) Friday, it should show Saturday (6th day of the week)?
And what is the difference between Returntype 2 and 11?
WEEKDAY is returning the correct result in that cell - i.e. 5.
If you format 5 as ddd, you are actually formatting the date 5 days after 31.12.1899 which is the 5th Jan 1900, which was a Thursday.
For a backtesting trading system, I need to rotation my positions every 2 weeks, BUT if the day is a Saturday or Sunday, I need to take the Friday.
Semi-Monthly updates are made twice a month; mid-month and month end.
Mid-month updates are on the 15th calendar day of each month. Should the 15th be a weekend or holiday, the update will occur on the last trading day prior to the 15th.
For example, if the 15th is a Saturday then the update will occur on the close of Friday the 14th.
I need to return a list of dates of rotation based on a start date and end date.
Let's say, I need every 15 days from January 1st 2018 to 31st December 2018, it should return only the valid dates based on the rules described above.
The formula should be for Google Sheet or Excel.
I tried the following:
It is not returning exactly what I need, since the google sheet googlefinance formula allows to use daily and weekly intervals (1 or 7). See below the googlefinance definition (https://support.google.com/docs/answer/3093281?hl=en):
"interval - [ OPTIONAL ] - The frequency of returned data; either "DAILY" or "WEEKLY".
interval can alternatively be specified as 1 or 7. Other numeric values are disallowed."
You need to be more precise in your specifications. You've provided multiple inconsistent intervals. eg: Two weeks (which would be every 14 days and will always fall on the same weekday); every 15 days (which will NOT be mid-month and EOM over most time periods); mid-month and end-of-month.
I suggest developing formulas for each of your desired intervals.
Once you have developed those relevant formulas, depending on your desired interval, to avoid a date falling on a weekend (or holiday if required for your system), you can use the WORKDAY function:
=WORKDAY(computedDate+1,-1, [holiday])
If your computedDate is on a Saturday, or Sunday; by adding 1 day and then subtracting to the previous workday, Friday will result.
If your trading interval is every Two weeks, you only need to ensure that the First date is not on a Saturday or Sunday. For other intervals, you may have to apply the formula to every computedDate.
I need to figure out how to get the dates for both the Tuesday and Thursday in the next week.
I'm currently getting the week number by using: =WEEKNUM(NOW(),)+1
I'm not sure where to go from here, please help me out.
You could use the following for Tuesday:
=NOW()+9-WEEKDAY(NOW(),2)
9 because 1 week is 7 days, then Tuesday is day 2 of the week, so 7+2=9.
For Thursday:
=NOW()+11-WEEKDAY(NOW(),2)
Same reasoning as above with Thursday being 4, so 7+4=11.
The formula basically takes the current date, adds a week (7) and then adjusts for the weekday considering today's weekday.
I'm trying to figure out how to calculate the past/future Canadian federal holiday dates to use the NETWORKDAYS function in the cell. Because the dates of the holidays change every year, is there a function or VBA code that I can use to calculate this?
For example, I have a 10 year project and I want to calculate the variance between the beginning date and the end date, excluding the weekends and holidays.
Like, Civic holiday is on the 1st Monday of August. It was on the 1st in 2011, but in 2012 it was on the 6th.
Easter Monday was on the 25th in 2011, but on the 9th in 2012.
Becuase NETWORKDAYS need exact date of the holidays in order to work, I need to calculate the future holiday dates (10-15years into the future)
I hope this makes sense...
You can make a list quite easily with a formula approach e.g.for Labour Day list years only in A2 down and in another column in row 2 use this formula
=DATE(A2,9,8)-WEEKDAY(DATE(A2,9,6))
that will give the date of First Monday in September for the relevant year - copy formula down column
Edit: Here's a workbook with all holidays calculated from 2000 to 2099 as per your rules, I think. If you want dates before 2000 then just change the years in column A and the dates will change automatically
I would add a couple of blank columns to the range, e.g. make C2:M101 = holidays, then you can use that named range in any NETWORKDAYS/WORKDAY function - the extra columns would allow you to enter any "ad hoc" holidays
I know I'm a little late to the thread but for some reason the link to your file doesn't open. I would love to see how you calculate the Canadian holidays. I have found solutions for: Labour Day, Easter, Good Friday and Victoria Day but still looking for the rest.
Labour Day
=DATE(A2,9,8)-WEEKDAY(DATE(A2,9,6))
Easter
=FLOOR("5/"&DAY(MINUTE(A2/38)/2+56)&"/"&A2,7)-34
Good Friday
=FLOOR(DATE(A2,5,DAY(MINUTE(A2/38)/2+56)),7)-36
Victoria Day
=DATE(A2,5,25)-WEEKDAY(DATE(A2,5,25),3)-(7*(WEEKDAY(DATE(A2,5,25),3)=0))
* 4 digit year must be in A2 *
The working days are from Monday to Friday, excluding the holidays.
Some holidays taking place during weekend should be moved to next Monday (e.g. Canada Day, Boxing Day, New Year), or previous Friday (e.g. Christmas)
The following are the formulas for the holidays in the province of Ontario, Canada, if the fiscal year is in FYear
Holyday Formula
New Year =WORKDAY(DATE(FYear,1,0),1)
Family Day =DATE(FYear,2,22)-WEEKDAY(DATE(FYear,2,6))
Good Friday =FLOOR(DATE(FYear,5,DAY(MINUTE(FYear/38)/2+56)),7)-36
Victoria Day =DATE(FYear,5,25)-WEEKDAY(DATE(FYear,5,23))
Canada Day =DATE(FYear,7,1)+(WEEKDAY(DATE(FYear,7,2))<3)*(3-WEEKDAY(DATE(FYear,7,2)))
CivicDay =DATE(FYear,8,8)-WEEKDAY(DATE(FYear,8,6))
LaborDay =DATE(FYear,9,8)-WEEKDAY(DATE(FYear,9,6))
Thanksgiving =DATE(FYear,10,15)-WEEKDAY(DATE(FYear,10,6))
Christmas =DATE(FYear,12,25)-(WEEKDAY(DATE(FYear,12,26))<3)*WEEKDAY(DATE(FYear,12,26))
Boxing Day =DATE(FYear,12,26)+(WEEKDAY(DATE(FYear,12,27))<3)*(3-WEEKDAY(DATE(FYear,12,27)))
Next New Year =WORKDAY(DATE(FYear+1,1,0),1)
I found this page very useful, but I have a couple of additions. My use case is that I want to know when a stat holiday occurs even when it moves to a different day like Friday or Monday. These formulas apply to a table where #Year contains the year as a simple number.
U.S. Independence day behaves differently. If July 4 is a Saturday then the holiday is on 3 July. If July 4 is a Sunday then the holiday is 5 July. I found writing these as nested IF statements more straightforward:
=IF(WEEKDAY(DATE([#Year],7,4))=7, DATE([#Year],7,3), IF(WEEKDAY(DATE([#Year],7,4))=1,DATE([#Year],7,5),DATE([#Year],7,4)))
Next, the formulas above don't work for years like 2021 where Christmas and Boxing Day were a Saturday and Sunday. Again I think nested IFs work better.
We know that if Christmas Day (Dec 25) is on a Saturday, then the stat holiday is on Dec 27, and if it is on a Sunday then the stat holiday is Dec 26. =IF(WEEKDAY(DATE([#Year],12,25))=7,DATE([#Year],12,27),IF(WEEKDAY(DATE([#Year],12,25))=1,DATE([#Year],12,26),DATE([#Year],12,25)))
Similarly, we know that if Boxing Day is on either a Saturday or a Sunday (meaning Christmas was Saturday), then the stat is on Dec 28. And if it falls on a Monday (meaning Christmas was Sunday), then it moves to Dec 27.
=IF(OR(WEEKDAY(DATE([#Year],12,26))=7,WEEKDAY(DATE([#Year],12,26))=1),DATE([#Year],12,28), IF(WEEKDAY(DATE([#Year],12,26))=2, DATE([#Year],12,27), DATE([#Year],12,26)))