// 4.2.js // 2024-09-03 // $Id: 4.2.js 1.1 2024/10/26 13:57:12 s Exp $ // s, current spot rate curve // s2, next year's spot rate curve 'use strict' // function const f_1 = function (j){ // forward rate, i = 1 return ((1 + s[j]) ** j / (1 + s[1])) ** (1 / (j - 1)) - 1; } // input const s_percent = [0, 5.0, 5.3, 5.6, 5.8, 6.0, 6.1]; // calculating const s = s_percent.map(x => x / 100); const sd1 = (((1 + s[2]) ** 2 / (1 + s[1])) ** (1 / (2-1)) - 1) * 100; const sd2 = (((1 + s[3]) ** 3 / (1 + s[1])) ** (1 / (3-1)) - 1) * 100; const sd3 = (((1 + s[4]) ** 4 / (1 + s[1])) ** (1 / (4-1)) - 1) * 100; const sd4 = (((1 + s[5]) ** 5 / (1 + s[1])) ** (1 / (5-1)) - 1) * 100; const sd5 = (((1 + s[6]) ** 6 / (1 + s[1])) ** (1 / (6-1)) - 1) * 100; const sd = [sd1, sd2, sd3, sd4, sd5]; let s2 = [0]; for(let j = 2; j < s.length; j++ ){ s2[j - 1] = f_1(j); } // output console.log('4.2.js'); console.log("current spot rate curve"); console.log("s=", ...s_percent.map(x => x.toFixed(1))); console.log("next year's spot rate curve"); console.log("calculating without function"); console.log(...sd.map(x => x.toFixed(1))); console.log("calculating with function"); console.log(...s2.map(x => (x * 100).toFixed(1))); // end // reference // David Flanagan著 『JavaScript 第7版』(オライリー・ジャパン) 2022-09-13. // ... : p.215. // ** : p.80. // => : p.202. // console.log() : p.630. // const : p.57. // length : p.176. // let : p.57. // map() : p.182. // toFixed() : p.51. // use strict : p.134. // end reference