From 2942e2934e810f385a287826a91648ca8df29942 Mon Sep 17 00:00:00 2001 From: Sudhir Shenoy Date: Thu, 13 Jul 2017 07:09:37 +0900 Subject: [PATCH] New tests for day basis computations in diff-year --- test-dates.lisp | 74 +++++++++++++++++++++++++++++++++++++++++++++++-- test-main.lisp | 12 ++++---- 2 files changed, 78 insertions(+), 8 deletions(-) diff --git a/test-dates.lisp b/test-dates.lisp index f7f5090..887b4dd 100644 --- a/test-dates.lisp +++ b/test-dates.lisp @@ -32,12 +32,11 @@ (= (ymd->date 2017 2 5) 2457789.5) (= (ymd->date 1959 12 29) 2436931.5) (= (ymd->date 1959 12 29 18 12 26.3) 2436932.2586376667d0) - (equal '(2017 2 5 0 0 0.0d0) - (multiple-value-call #'list (date->ymd 2457789.5))) + (equal '(2017 2 5) (multiple-value-call #'list (date->ymd 2457789.5))) (= (ymd->date 1600 2 29) 2305506.5) (= (ymd->date 1600 2 29 9 31 23.5) 2305506.896799773d0) (equal '(1600 2 29 9 31 23.500385284423828d0) - (multiple-value-call #'list (date->ymd 2305506.896799773d0))) + (multiple-value-call #'list (date->ymd 2305506.896799773d0 :want-time t))) (= (date->javascript-time (ymd->date 2017 6 18)) 1497744000000) (= (jday-number (ymd->date 2017 6 18)) 2457923))) @@ -126,3 +125,72 @@ (ymd->date 1959 9 23 19 8 29.363870322704315D0)) (= (winter-solstice 1959) (ymd->date 1959 12 22 14 34 33.68946969509125d0)))) + +(deftest date-arith-360 () + (format t "Checking 30/360 and Actual/360 day basis computations~%") + (let ((test-cases + ;; Start date End Date Bond Basis 30E/360 30E/360 ISDA Act/360 + '(("2007-01-15" "2007-01-30" 0.041666667 0.041666667 0.041666667 0.041666667) + ("2007-01-15" "2007-02-15" 0.083333333 0.083333333 0.083333333 0.086111111) + ("2007-01-15" "2007-07-15" 0.5 0.5 0.5 0.502777778) + ("2007-09-30" "2008-03-31" 0.5 0.5 0.5 0.508333333) + ("2007-09-30" "2007-10-31" 0.083333333 0.083333333 0.083333333 0.086111111) + ("2007-09-30" "2008-09-30" 1 1 1 1.016666667) + ("2007-01-15" "2007-01-31" 0.044444444 0.041666667 0.041666667 0.044444444) + ("2007-01-31" "2007-02-28" 0.077777778 0.077777778 0.083333333 0.077777778) + ("2006-08-31" "2007-02-28" 0.494444444 0.494444444 0.5 0.502777778) + ("2007-02-28" "2007-08-31" 0.508333333 0.505555556 0.5 0.511111111) + ("2007-02-14" "2007-02-28" 0.038888889 0.038888889 0.044444444 0.038888889) + ("2007-02-26" "2008-02-29" 1.008333333 1.008333333 1.011111111 1.022222222) + ("2008-02-29" "2009-02-28" 0.997222222 0.997222222 0.994444444 1.013888889) + ("2008-02-29" "2008-03-30" 0.086111111 0.086111111 0.083333333 0.083333333) + ("2008-02-29" "2008-03-31" 0.088888889 0.086111111 0.083333333 0.086111111) + ("2007-02-28" "2007-03-05" 0.019444444 0.019444444 0.013888889 0.013888889) + ("2007-10-31" "2007-11-28" 0.077777778 0.077777778 0.077777778 0.077777778) + ("2007-08-31" "2008-02-29" 0.497222222 0.497222222 0.5 0.505555556) + ("2008-02-29" "2008-08-31" 0.505555556 0.502777778 0.5 0.511111111) + ("2008-08-31" "2009-02-28" 0.494444444 0.494444444 0.494444444 0.502777778) + ("2009-02-28" "2009-08-31" 0.508333333 0.505555556 0.5 0.511111111))) + (term-date (ymd->date 2009 2 28))) + (labels ((a= (a b) + (< (abs (- a b)) 0.000001))) + (dolist (test test-cases) + (let ((d1 (string->date (first test))) + (d2 (string->date (second test))) + (bond-basis (third test)) + (euro-basis (fourth test)) + (german (fifth test)) + (actual (sixth test))) + (check + (a= (diff-years d1 d2 :30a-360) bond-basis) + (a= (diff-years d1 d2 :30e-360) euro-basis) + (a= (diff-years d1 d2 :30e-360-isda :termination-date term-date) german) + (a= (diff-years d1 d2 :act-360) actual))))))) + +(deftest date-arith-act-act () + (format t "Checking Actual/Actual day basis computations~%") + (let ((test-cases + (list + ;; Start End Date F LC AFB ISDA ISMA + (list "2003-11-01" "2004-05-01" 2 nil 182/366 (+ 61/365 121/366) (/ 182 (* 2 182))) + (list "1999-02-01" "1999-07-01" 1 nil 150/365 150/365 (/ 150 (* 1 365))) + (list "1999-07-01" "2000-07-01" 1 nil 1 (+ 184/365 182/366) (/ 366 (* 1 366))) + (list "2002-08-15" "2003-07-15" 2 nil 334/365 334/365 (+ (/ 181 (* 2 181)) + (/ 153 (* 2 184)))) + (list "2003-07-15" "2004-01-15" 2 nil 184/365 (+ 170/365 14/366) (/ 184 (* 2 184))) + (list "1999-07-30" "2000-01-30" 2 t 184/365 (+ 155/365 29/366) (/ 184 (* 2 184))) + (list "2000-01-30" "2000-06-30" 2 t 152/366 152/366 (/ 152 (* 2 182))) + (list "1999-11-30" "2000-04-30" 4 t 152/366 (+ 32/365 120/366) (+ (/ 91 (* 4 91)) + (/ 61 (* 4 92))))))) + (dolist (test test-cases) + (let ((d1 (string->date (first test))) + (d2 (string->date (second test))) + (freq (third test)) + (last-cpn (fourth test)) + (afb (fifth test)) + (isda (sixth test)) + (isma (seventh test))) + (check + (= (diff-years d1 d2 :act-act-afb) afb) + (= (diff-years d1 d2 :act-act) isda) + (= (diff-years d1 d2 :act-act-isma :frequency freq :is-last-coupon last-cpn) isma)))))) diff --git a/test-main.lisp b/test-main.lisp index bca835a..788c427 100644 --- a/test-main.lisp +++ b/test-main.lisp @@ -77,11 +77,13 @@ (*failed-tests* 0) (*verbose-results* verbose) (status (combine-results - (julian) - (misc-fns) - (special-dates) - (print-fns) - (parse-dates)))) + (julian) + (misc-fns) + (special-dates) + (date-arith-360) + (date-arith-act-act) + (print-fns) + (parse-dates)))) (unless (zerop *total-tests*) (format t "~d tests executed - ~d passed (~,2f%)~%" *total-tests* (- *total-tests* *failed-tests*)