I wrote a bunch of DateTime methods like FirstTradingDateOfTheWeek, FirstTradingDateOfTheMonth, TradingDateOnOrAfter (which returns the specified date if it is a trading day or, if not, the next trading date). They are all pretty simple, but if you're interested, I'd be happy to share.
Here you are, Eugene. The last one is based on your code, but I included it, because it is used by the other ones.
Don't hesitate to let me know if you see any errors in any of them.
Size:
Color:
Thanks Kurt. Nice effort. Reviewed the code quickly and found one issue:
While such functions are going to work with the U.S. date format or the like, they will return incorrect dates for countries where regional settings assume an order different than M/d/yyyy (e.g. dd.MM.yyyy). The correct way is to not make such assumptions or WLD users may get 10 October as the first trading date of October, for example:
CODE:
Please log in to see this code.
CODE:
Please log in to see this code.
(Wikipedia:
Date format by country)
And a couple of functions look like duplicates:
* LastTradingDayOfTheMonth =
IsLastTradingDayOfMonth has been part of WealthLab.Rules.DateRules (WS Programming Guide > WealthLab.Rules Classes > DateRules)
* NextTradingDate = GetNextTradingDate in C.Components
Size:
Color:
Consequently, here's a fix so that the methods would apply globally:
CODE:
Please log in to see this code.
CODE:
Please log in to see this code.
CODE:
Please log in to see this code.
Size:
Color:
Convert.ToDateTime is rather computationally expensive, so here is a faster LastTradingDayOfTheMonth, which eliminates the unnecessary Convert:
CODE:
Please log in to see this code.
Size:
Color:
Also, your FirstTradingDateOfTheYear returns an error message for me. I think it should be:
CODE:
Please log in to see this code.
Size:
Color:
QUOTE:
I think it should be:
Yes, that's how it is. With the "..." in my post #3 I just skipped some unchanged code.
Size:
Color:
Thanks Kurt, the methods you submitted here are now part of Community Components v2018.12.
Size:
Color: