I am working with dates in the format m-d-yyyy for the purpose of computing the average stock return between two such dates. But when it comes to dividing the total return by the number of days between the two dates, I hit a problem.
How do I find the difference between two dates, and then use the derived number to divide the total return, thus finding the average return per day?
Something like this would work
42.42/(today() - Date(2021, 1, 1)).value
# - 0.53025
(today() - Date(2021, 1, 1)).value
While the above works, depending on your application you might want to ensure that you are dividing by the number of trading days rather than calendar days, cf the discussion here: Getting the third Friday of the month - #4 by lungben