Dividing a number by the number of days between dates

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

because

 (today() - Date(2021, 1, 1)).value

gives 80.

3 Likes

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

3 Likes