New functions to convert day count convention and end of month rules to strings

This commit is contained in:
Sudhir Shenoy 2017-07-15 08:38:26 +09:00
parent 2942e2934e
commit f6dd1f2d90
2 changed files with 26 additions and 2 deletions

View file

@ -43,6 +43,8 @@
:date->local-time ; to local time zone :date->local-time ; to local time zone
:month->string ; full name of month :month->string ; full name of month
:dow->string ; day of week as string :dow->string ; day of week as string
:day-count->string
:eom-rule->string
;; Special dates for given year ;; Special dates for given year
:easter-day ; easter day :easter-day ; easter day
:vernal-equinox ; spring equinox date-time :vernal-equinox ; spring equinox date-time
@ -66,8 +68,7 @@
:last-day-of-prev-month ; last calendar day in previous month :last-day-of-prev-month ; last calendar day in previous month
:date+ :date- ; add/subtract days to date :date+ :date- ; add/subtract days to date
:add-months ; add/subtract months to date :add-months ; add/subtract months to date
:add-years ; convenience function
:diff-days ; absolute number of days between two dates :diff-days ; absolute number of days between two dates
:diff-years ; years between dates using day count conventions :diff-years ; years between dates using day count conventions
)) ))

View file

@ -121,3 +121,26 @@
(defparameter +date-words+ '(("today" . 0) ("tomorrow" . 1) ("yesterday" . -1))) (defparameter +date-words+ '(("today" . 0) ("tomorrow" . 1) ("yesterday" . -1)))
(defun str-to-relative-date (str) (defun str-to-relative-date (str)
(cdr (find str +date-words+ :test #'string-equal :key #'car))) (cdr (find str +date-words+ :test #'string-equal :key #'car)))
(defun day-count->string (day-count-convention)
(case day-count-convention
((:actual-actual-fixed :act-act-fixed) "Actual/Actual (Fixed)")
((:actual-actual :act-act :actual-365 :act-365) "Actual/Actual (ISDA)")
((:actual-actual-isma :act-act-isma) "Actual/Actual (ISMA)")
((:actual-actual-afb :act-act-afb) "Actual/Actual (AFB)")
((:actual-365-l :act-365-l) "Actual/365L")
((:actual-365-nl :act-365-nl :nl-365 :actual-365-jgb :act-365-jgb) "NL/365")
((:actual-360 :act-360) "Actual/360")
((:30a-360 :30-360-isda :30-360-muni :bond-basis :360-360) "30A/360")
((:30e-360 :30-360-isma) "30E/360")
(:30e+-360 "30E+/360")
((:30e-360-isda :30-360-german) "30/360 (German)")
((:30u-360 :30-360-us) "30/360 (US)")
(otherwise (concatenate 'string "Unknown day count convention: " (string day-count-convention)))))
(defun eom-rule->string (rule)
(case rule
(:eom-normal "EOM")
(:eom-no-leap-day "EOM (No Leap)")
(otherwise "")))