@travishorn/financejs 1.19.0 → 1.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travishorn/financejs",
3
- "version": "1.19.0",
3
+ "version": "1.19.1",
4
4
  "description": "Modern JavaScript time value of money and cash-flow financial formulas with Excel-style behavior.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/coupdaybs.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import {
2
- coupdaybs as coupdaybsUtil,
2
+ actualDays,
3
+ days360Eu,
4
+ days360Us,
3
5
  getCouponBounds,
4
6
  toUtcDate,
5
7
  } from "./util.js";
@@ -60,5 +62,13 @@ export function coupdaybs(settlement, maturity, frequency, basis = 0) {
60
62
  monthsPerCoupon,
61
63
  );
62
64
 
63
- return coupdaybsUtil(previousCouponDate, settlementDate, normalizedBasis);
65
+ if (normalizedBasis === 0) {
66
+ return days360Us(previousCouponDate, settlementDate);
67
+ }
68
+
69
+ if (normalizedBasis === 4) {
70
+ return days360Eu(previousCouponDate, settlementDate);
71
+ }
72
+
73
+ return actualDays(previousCouponDate, settlementDate);
64
74
  }
package/src/coupdays.js CHANGED
@@ -1,8 +1,4 @@
1
- import {
2
- coupdays as coupdaysUtil,
3
- getCouponBounds,
4
- toUtcDate,
5
- } from "./util.js";
1
+ import { actualDays, getCouponBounds, toUtcDate } from "./util.js";
6
2
 
7
3
  /**
8
4
  * Returns the number of days in the coupon period that contains the settlement
@@ -60,10 +56,13 @@ export function coupdays(settlement, maturity, frequency, basis = 0) {
60
56
  monthsPerCoupon,
61
57
  );
62
58
 
63
- return coupdaysUtil(
64
- previousCouponDate,
65
- nextCouponDate,
66
- frequency,
67
- normalizedBasis,
68
- );
59
+ if (normalizedBasis === 0 || normalizedBasis === 2 || normalizedBasis === 4) {
60
+ return 360 / frequency;
61
+ }
62
+
63
+ if (normalizedBasis === 3) {
64
+ return 365 / frequency;
65
+ }
66
+
67
+ return actualDays(previousCouponDate, nextCouponDate);
69
68
  }
package/src/coupdaysnc.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import {
2
- coupdaysnc as coupdaysncUtil,
2
+ actualDays,
3
+ days360Eu,
4
+ days360Us,
3
5
  getCouponBounds,
4
6
  toUtcDate,
5
7
  } from "./util.js";
@@ -59,5 +61,13 @@ export function coupdaysnc(settlement, maturity, frequency, basis = 0) {
59
61
  monthsPerCoupon,
60
62
  );
61
63
 
62
- return coupdaysncUtil(settlementDate, nextCouponDate, normalizedBasis);
64
+ if (normalizedBasis === 0) {
65
+ return days360Us(settlementDate, nextCouponDate);
66
+ }
67
+
68
+ if (normalizedBasis === 4) {
69
+ return days360Eu(settlementDate, nextCouponDate);
70
+ }
71
+
72
+ return actualDays(settlementDate, nextCouponDate);
63
73
  }
package/src/price.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  actualDays,
3
- coupdaybs,
4
- coupdays,
5
- coupdaysnc,
6
3
  couponsRemaining,
7
4
  getCouponBounds,
8
5
  normalizeZero,
9
6
  toUtcDate,
10
7
  } from "./util.js";
8
+ import { coupdaybs } from "./coupdaybs.js";
9
+ import { coupdays } from "./coupdays.js";
10
+ import { coupdaysnc } from "./coupdaysnc.js";
11
11
 
12
12
  /**
13
13
  * Calculates the price per $100 face value of a security that pays periodic
@@ -107,14 +107,14 @@ export function price(
107
107
  monthsPerCoupon,
108
108
  );
109
109
 
110
- const a = coupdaybs(previousCouponDate, settlementDate, normalizedBasis);
111
- let dsc = coupdaysnc(settlementDate, nextCouponDate, normalizedBasis);
112
- let e = coupdays(
113
- previousCouponDate,
114
- nextCouponDate,
110
+ const a = coupdaybs(settlementDate, maturityDate, frequency, normalizedBasis);
111
+ let dsc = coupdaysnc(
112
+ settlementDate,
113
+ maturityDate,
115
114
  frequency,
116
115
  normalizedBasis,
117
116
  );
117
+ let e = coupdays(settlementDate, maturityDate, frequency, normalizedBasis);
118
118
 
119
119
  if (normalizedBasis === 2) {
120
120
  e = actualDays(previousCouponDate, nextCouponDate);
package/src/util.js CHANGED
@@ -204,96 +204,6 @@ export function couponsRemaining(
204
204
  return n;
205
205
  }
206
206
 
207
- /**
208
- * Computes days from settlement to next coupon date (`DSC`) by day-count basis.
209
- *
210
- * Basis mapping:
211
- * - `0`: US (NASD) 30/360
212
- * - `1`: Actual/actual
213
- * - `2`: Actual/360
214
- * - `3`: Actual/365
215
- * - `4`: European 30/360
216
- *
217
- * @param {Date} settlementDate - Settlement date.
218
- * @param {Date} nextCouponDate - Next coupon date.
219
- * @param {0|1|2|3|4} basis - Day-count basis code.
220
- * @returns {number} Days between settlement and next coupon under `basis`.
221
- *
222
- * @example
223
- * coupdaysnc(new Date("2024-01-15"), new Date("2024-04-15"), 0);
224
- */
225
- export function coupdaysnc(settlementDate, nextCouponDate, basis) {
226
- if (basis === 0) {
227
- return days360Us(settlementDate, nextCouponDate);
228
- }
229
-
230
- if (basis === 4) {
231
- return days360Eu(settlementDate, nextCouponDate);
232
- }
233
-
234
- return actualDays(settlementDate, nextCouponDate);
235
- }
236
-
237
- /**
238
- * Computes days from previous coupon date to settlement (`A`) by day-count
239
- * basis.
240
- *
241
- * Basis mapping:
242
- * - `0`: US (NASD) 30/360
243
- * - `1`: Actual/actual
244
- * - `2`: Actual/360
245
- * - `3`: Actual/365
246
- * - `4`: European 30/360
247
- *
248
- * @param {Date} previousCouponDate - Coupon date immediately before settlement.
249
- * @param {Date} settlementDate - Settlement date.
250
- * @param {0|1|2|3|4} basis - Day-count basis code.
251
- * @returns {number} Days between previous coupon and settlement under `basis`.
252
- *
253
- * @example
254
- * coupdaybs(new Date("2023-10-15"), new Date("2024-01-15"), 1);
255
- */
256
- export function coupdaybs(previousCouponDate, settlementDate, basis) {
257
- if (basis === 0) {
258
- return days360Us(previousCouponDate, settlementDate);
259
- }
260
-
261
- if (basis === 4) {
262
- return days360Eu(previousCouponDate, settlementDate);
263
- }
264
-
265
- return actualDays(previousCouponDate, settlementDate);
266
- }
267
-
268
- /**
269
- * Computes total days in the coupon period (`E`) by basis and payment
270
- * frequency.
271
- *
272
- * For 30/360 bases (`0` and `4`), period length is fixed at `360/frequency`.
273
- * For basis `3` (Actual/365), period length is fixed at `365/frequency`.
274
- * Otherwise, calendar days between coupon boundaries are used.
275
- *
276
- * @param {Date} previousCouponDate - Coupon date before settlement.
277
- * @param {Date} nextCouponDate - Coupon date after settlement.
278
- * @param {number} frequency - Coupon payments per year.
279
- * @param {0|1|2|3|4} basis - Day-count basis code.
280
- * @returns {number} Coupon period length in days.
281
- *
282
- * @example
283
- * coupdays(new Date("2024-01-01"), new Date("2024-07-01"), 2, 3); // 182.5
284
- */
285
- export function coupdays(previousCouponDate, nextCouponDate, frequency, basis) {
286
- if (basis === 0 || basis === 2 || basis === 4) {
287
- return 360 / frequency;
288
- }
289
-
290
- if (basis === 3) {
291
- return 365 / frequency;
292
- }
293
-
294
- return actualDays(previousCouponDate, nextCouponDate);
295
- }
296
-
297
207
  /**
298
208
  * Converts a `Date` to a UTC-midnight date-only representation.
299
209
  *
package/src/yield_.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  actualDays,
3
- coupdaybs,
4
- coupdays,
5
- coupdaysnc,
6
3
  couponsRemaining,
7
4
  getCouponBounds,
8
5
  normalizeZero,
9
6
  toUtcDate,
10
7
  } from "./util.js";
8
+ import { coupdaybs } from "./coupdaybs.js";
9
+ import { coupdays } from "./coupdays.js";
10
+ import { coupdaysnc } from "./coupdaysnc.js";
11
11
 
12
12
  /**
13
13
  * Calculates the yield on a security that pays periodic interest. Use to
@@ -107,14 +107,14 @@ export function yield_(
107
107
  monthsPerCoupon,
108
108
  );
109
109
 
110
- const a = coupdaybs(previousCouponDate, settlementDate, normalizedBasis);
111
- let dsc = coupdaysnc(settlementDate, nextCouponDate, normalizedBasis);
112
- let e = coupdays(
113
- previousCouponDate,
114
- nextCouponDate,
110
+ const a = coupdaybs(settlementDate, maturityDate, frequency, normalizedBasis);
111
+ let dsc = coupdaysnc(
112
+ settlementDate,
113
+ maturityDate,
115
114
  frequency,
116
115
  normalizedBasis,
117
116
  );
117
+ let e = coupdays(settlementDate, maturityDate, frequency, normalizedBasis);
118
118
 
119
119
  if (normalizedBasis === 2) {
120
120
  e = actualDays(previousCouponDate, nextCouponDate);