Additional DateTime Functions
Author: Panache
Creation Date: 10/31/2018 5:02 PM
profile picture

Panache

#1
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.
profile picture

Eugene

#2
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
profile picture

Eugene

#3
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.
profile picture

Panache

#4
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.

profile picture

Panache

#5
Also, your FirstTradingDateOfTheYear returns an error message for me. I think it should be:
CODE:
Please log in to see this code.
profile picture

Eugene

#6
QUOTE:
I think it should be:

Yes, that's how it is. With the "..." in my post #3 I just skipped some unchanged code.
profile picture

Eugene

#7
Thanks Kurt, the methods you submitted here are now part of Community Components v2018.12.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).