#] #] ********************* #] loaddefs link d_Qndfs 'semi-log formula.ndf' # www.BillHowell.ca 15Sep2020 initial # view this file in a text editor, with [constant width font, tab = 3 spaces], no line-wrap f_semiLog := 'semi-log formula.ndf' ; loaddefs_start f_semiLog ; #**************************** # List of operators, generated with : # $ cat "$d_Qndfs""semi-log formula.ndf" | grep "^#]" | sed 's/^#\]/ /' # ********************* loaddefs link d_Qndfs 'semi-log formula.ndf' year_frac IS OP str_ddmmmyyy - cheap inaccurate estimate of fraction of year that has passed setup_semilog IS OP xStr xEnd yStart yEnd - get_yEnd IS OP xVal - write_summary IS OP testName params dateStrs y_standards - test_SP500_1871_1926 IS - test_SP500_1926_2020 IS - #***************************************************** # Main program monthList := 'Jan' 'Feb' 'Mar' 'Apr' 'May' 'Jun' 'Jul' 'Aug' 'Sep' 'Oct' 'Nov' 'Dec' ; IF flag_debug THEN write 'loading year_frac' ; ENDIF ; #] year_frac IS OP str_ddmmmyyy - cheap inaccurate estimate of fraction of year that has passed year_frac IS OP str_ddmmmyyy { LOCAL day month year monthNum ; day month year := (0 1) (2 3 4) (5 6 7 8) EACHLEFT choose str_ddmmmyyy ; monthNum := find_Howell month monthList ; day year := EACH execute day year ; year + [( (monthNum * 30.5) + (day - 1) ) / 365.25] } # EACH year_frac '01Feb1871' '01Feb1923' '01Apr1926' '01Jan1941' '01Sep2020' IF flag_debug THEN write 'loading setup_semilog' ; ENDIF ; #] setup_semilog IS OP xStr xEnd yStart yEnd - setup_semilog IS OP xStr xEnd yStart yEnd { LOCAL log_yEnd ; NONLOCAL xStart log_yStart slope ; xStart := xStr ; log_yStart log_yEnd := EACH log yStart yEnd ; slope := (log_yEnd - log_yStart) / (xEnd - xStart) ; } IF flag_debug THEN write 'loading get_yEnd' ; ENDIF ; #] get_yEnd IS OP xVal - get_yEnd IS OP xVal { NONLOCAL xStart log_yStart slope ; power 10 (log_yStart + (slope*(xVal - xStart))) } # EACH get_yEnd 1871.08 1923.08 1926.25 1941. 2020.67 IF flag_debug THEN write 'loading write_summary' ; ENDIF ; #] write_summary IS OP testName params dateStrs y_standards - write_summary IS OP testName params dateStrs y_standards { LOCAL y_fracs ; NONLOCAL xStart xEnd yStart yEnd log_yStr slope ; setup_semilog xStart xEnd yStart yEnd ; EACH write '' '********' testName ; write (3 4 reshape (link ('parameter : ' 'xStart' 'yStart' 'semi-log slope' ) (link (solitary 'standard : ') params ) ('calculated : ' xStart yStart slope ) ) ) ; y_fracs := EACH year_frac dateStrs ; write (4 4 reshape (link (link (solitary 'dateStrings' ) dateStrs ) (link (solitary 'years' ) y_fracs ) (link (solitary 'standard : ' ) y_Standards ) (link (solitary 'calculated : ' ) (link EACH get_yEnd y_fracs) ) ) ) ; } IF flag_debug THEN write 'loading test_SP500_1871_1926' ; ENDIF ; #] test_SP500_1871_1926 IS - test_SP500_1871_1926 IS { NONLOCAL xStart xEnd yStart yEnd ; xStart xEnd := EACH year_frac '01Feb1871' '01Apr1926' ; yStart yEnd := 6.09 6.20 ; write_summary 'test_SP500_1871_1926' (1871.08 6.09 0.000140925) ('01Feb1871' '01Feb1923' '01Apr1926') (6.09 6.19363 6.20) ; } IF flag_debug THEN write 'loading test_SP500_1926_2020' ; ENDIF ; #] test_SP500_1926_2020 IS - test_SP500_1926_2020 IS { NONLOCAL xStart xEnd yStart yEnd ; xStart xEnd := EACH year_frac '01Apr1926' '01Sep2020' ; yStart yEnd := 6.20 3361.99 ; write_summary 'test_SP500_1871_1926' (1926.25 6.20 0.0289587) ('01Apr1926' '01Jan1941' '01Sep2020') (6.20 13.34 3361.99) ; } loaddefs_ended f_semiLog ; # enddoc