p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

access thread: Daily Compounding---Date Calculation


Message #1 by rick.dolson@n... on Fri, 28 Jun 2002 16:33:51
I am having a difficult time writing a procedure or function that will 
accomplish the following:

1.  Say your time period is 06/30/2003 to 12/31/2006.
    First, you break it up to 4 periods:
    6/30/2003 to 01/01/2004 = 185 days
    01/01/04 to 01/01/05 = 366 days
    01/01/05 to 01/01/06 = 365 days
    01/01/06 to 12/31/06 = 364 days

2.  Now, divide by the actual # of days in that year to get your true 
fraction of a year:
    6/30/2003 to 01/01/2004 = 185 days/365 = .5068493150687930
    01/01/04 to 01/01/05 = 366 days/366 = 1
    01/01/05 to 01/01/06 = 365 days/365 = 1
    01/01/06 to 12/31/06 = 364 days/365 = .9972602739726030

3.  Now, take your actual total # of days (185+366+365+364) = 1280
    and Divide them by your exact total of #2 (.506849315068793 + 1 + 1 
+.9972602739726030) = 3.5041095890411

    1280/3.5041095890411 = 365.285379202502

4.  So, what i envision is having a function, name say avgyear.  Then, I 
could use this function, such that, i could type in 2 dates and it would 
give me the number calculated in 3 above.
i.e, avgyear(start date, end date) = avg # of days in a year
     avgyear(06/30/03,12/31/06) = 365.285379202502

5.  Thank you for any help or ideas you may have.  I have a database I 
need to do daily compounding of interest in, and of course, the leap year 
thing puts a kink in that.  
    

  Return to Index