moneyfunx 3.0.2 → 3.0.7

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.
Files changed (86) hide show
  1. package/build/index.d.ts +18 -0
  2. package/build/index.d.ts.map +1 -0
  3. package/build/index.js +14 -0
  4. package/build/lib/constants.d.ts.map +1 -0
  5. package/build/{src/lib → lib}/debt/loan.d.ts +1 -1
  6. package/build/lib/debt/loan.d.ts.map +1 -0
  7. package/build/{src/lib → lib}/debt/loan.js +2 -2
  8. package/build/lib/debt/paymentTypes.d.ts.map +1 -0
  9. package/build/{src/lib → lib}/debt/payments.d.ts +2 -2
  10. package/build/lib/debt/payments.d.ts.map +1 -0
  11. package/build/{src/lib → lib}/debt/payments.js +1 -1
  12. package/build/lib/errors.d.ts.map +1 -0
  13. package/build/lib/investment/contributionTypes.d.ts.map +1 -0
  14. package/build/{src/lib → lib}/investment/contributions.d.ts +2 -2
  15. package/build/lib/investment/contributions.d.ts.map +1 -0
  16. package/build/{src/lib → lib}/investment/instrument.d.ts +1 -1
  17. package/build/lib/investment/instrument.d.ts.map +1 -0
  18. package/build/{src/lib → lib}/investment/instrument.js +2 -2
  19. package/build/{src/lib → lib}/investment/strategies.d.ts +2 -2
  20. package/build/lib/investment/strategies.d.ts.map +1 -0
  21. package/build/{src/lib → lib}/investment/strategies.js +2 -2
  22. package/build/lib/investment/withdrawalTypes.d.ts.map +1 -0
  23. package/build/{src/lib → lib}/investment/withdrawals.d.ts +2 -2
  24. package/build/lib/investment/withdrawals.d.ts.map +1 -0
  25. package/build/{src/lib → lib}/investment/withdrawals.js +2 -2
  26. package/build/lib/shared/primitives.d.ts.map +1 -0
  27. package/build/lib/shared/sorting.d.ts.map +1 -0
  28. package/package.json +6 -4
  29. package/build/src/index.d.ts +0 -17
  30. package/build/src/index.d.ts.map +0 -1
  31. package/build/src/index.js +0 -16
  32. package/build/src/lib/constants.d.ts.map +0 -1
  33. package/build/src/lib/debt/loan.d.ts.map +0 -1
  34. package/build/src/lib/debt/paymentTypes.d.ts.map +0 -1
  35. package/build/src/lib/debt/payments.d.ts.map +0 -1
  36. package/build/src/lib/errors.d.ts.map +0 -1
  37. package/build/src/lib/investment/contributionTypes.d.ts.map +0 -1
  38. package/build/src/lib/investment/contributions.d.ts.map +0 -1
  39. package/build/src/lib/investment/instrument.d.ts.map +0 -1
  40. package/build/src/lib/investment/strategies.d.ts.map +0 -1
  41. package/build/src/lib/investment/withdrawalTypes.d.ts.map +0 -1
  42. package/build/src/lib/investment/withdrawals.d.ts.map +0 -1
  43. package/build/src/lib/shared/primitives.d.ts.map +0 -1
  44. package/build/src/lib/shared/sorting.d.ts.map +0 -1
  45. package/build/tests/debt/loan.test.d.ts +0 -2
  46. package/build/tests/debt/loan.test.d.ts.map +0 -1
  47. package/build/tests/debt/loan.test.js +0 -87
  48. package/build/tests/debt/payments.test.d.ts +0 -2
  49. package/build/tests/debt/payments.test.d.ts.map +0 -1
  50. package/build/tests/debt/payments.test.js +0 -91
  51. package/build/tests/debt/sorting.test.d.ts +0 -2
  52. package/build/tests/debt/sorting.test.d.ts.map +0 -1
  53. package/build/tests/debt/sorting.test.js +0 -43
  54. package/build/tests/index.test.d.ts +0 -2
  55. package/build/tests/index.test.d.ts.map +0 -1
  56. package/build/tests/index.test.js +0 -66
  57. package/build/tests/investment/contributions.test.d.ts +0 -2
  58. package/build/tests/investment/contributions.test.d.ts.map +0 -1
  59. package/build/tests/investment/contributions.test.js +0 -113
  60. package/build/tests/investment/instrument.test.d.ts +0 -2
  61. package/build/tests/investment/instrument.test.d.ts.map +0 -1
  62. package/build/tests/investment/instrument.test.js +0 -57
  63. package/build/tests/investment/strategies.test.d.ts +0 -2
  64. package/build/tests/investment/strategies.test.d.ts.map +0 -1
  65. package/build/tests/investment/strategies.test.js +0 -15
  66. package/build/tests/investment/withdrawals.test.d.ts +0 -2
  67. package/build/tests/investment/withdrawals.test.d.ts.map +0 -1
  68. package/build/tests/investment/withdrawals.test.js +0 -66
  69. package/build/tests/shared/primitives.test.d.ts +0 -2
  70. package/build/tests/shared/primitives.test.d.ts.map +0 -1
  71. package/build/tests/shared/primitives.test.js +0 -76
  72. /package/build/{src/lib → lib}/constants.d.ts +0 -0
  73. /package/build/{src/lib → lib}/constants.js +0 -0
  74. /package/build/{src/lib → lib}/debt/paymentTypes.d.ts +0 -0
  75. /package/build/{src/lib → lib}/debt/paymentTypes.js +0 -0
  76. /package/build/{src/lib → lib}/errors.d.ts +0 -0
  77. /package/build/{src/lib → lib}/errors.js +0 -0
  78. /package/build/{src/lib → lib}/investment/contributionTypes.d.ts +0 -0
  79. /package/build/{src/lib → lib}/investment/contributionTypes.js +0 -0
  80. /package/build/{src/lib → lib}/investment/contributions.js +0 -0
  81. /package/build/{src/lib → lib}/investment/withdrawalTypes.d.ts +0 -0
  82. /package/build/{src/lib → lib}/investment/withdrawalTypes.js +0 -0
  83. /package/build/{src/lib → lib}/shared/primitives.d.ts +0 -0
  84. /package/build/{src/lib → lib}/shared/primitives.js +0 -0
  85. /package/build/{src/lib → lib}/shared/sorting.d.ts +0 -0
  86. /package/build/{src/lib → lib}/shared/sorting.js +0 -0
@@ -0,0 +1,18 @@
1
+ /**
2
+ * MoneyFunx
3
+ * * mek it funx up
4
+ */
5
+ export { MAX_DURATION_YEARS, TOTALS, } from './lib/constants.js';
6
+ export { ILoan, Loan } from './lib/debt/loan.js';
7
+ export { determineExtraPayment, amortizePayments, payLoans, } from './lib/debt/payments.js';
8
+ export { PaymentRecord, LoansPaymentSchedule, LoanPrincipals, PaymentSchedule, } from './lib/debt/paymentTypes.js';
9
+ export { NegativeContributionError, PaymentTooLowError, NegativeWithdrawalError } from './lib/errors.js';
10
+ export { amortizeContributions, contributeInstruments, determineExtraContribution, } from './lib/investment/contributions.js';
11
+ export { ContributionRecord, ContributionSchedule, InstrumentsContributionSchedule, } from './lib/investment/contributionTypes.js';
12
+ export { IInstrument, Instrument } from './lib/investment/instrument.js';
13
+ export { calculateAmortizedWithdrawal, drawdownInstruments, } from './lib/investment/withdrawals.js';
14
+ export { WithdrawalRecord, WithdrawalSchedule, InstrumentsWithdrawalSchedule, } from './lib/investment/withdrawalTypes.js';
15
+ export { performWaterfallDrawdown, } from './lib/investment/strategies.js';
16
+ export { calculatePeriodicAmount, calculateBalanceRemaining, calculatePeriodsToZero, calculateInterestOverPeriods, } from './lib/shared/primitives.js';
17
+ export { HasRateAndBalance, snowball, avalanche, sortWith } from './lib/shared/sorting.js';
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,kBAAkB,EAClB,MAAM,GACP,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,QAAQ,GACT,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,eAAe,GAChB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAEzG,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,+BAA+B,GAChC,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,EACL,4BAA4B,EAC5B,mBAAmB,GACpB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,GAC9B,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EACL,wBAAwB,GACzB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC"}
package/build/index.js ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * MoneyFunx
3
+ * * mek it funx up
4
+ */
5
+ export { MAX_DURATION_YEARS, TOTALS, } from './lib/constants.js';
6
+ export { Loan } from './lib/debt/loan.js';
7
+ export { determineExtraPayment, amortizePayments, payLoans, } from './lib/debt/payments.js';
8
+ export { NegativeContributionError, PaymentTooLowError, NegativeWithdrawalError } from './lib/errors.js';
9
+ export { amortizeContributions, contributeInstruments, determineExtraContribution, } from './lib/investment/contributions.js';
10
+ export { Instrument } from './lib/investment/instrument.js';
11
+ export { calculateAmortizedWithdrawal, drawdownInstruments, } from './lib/investment/withdrawals.js';
12
+ export { performWaterfallDrawdown, } from './lib/investment/strategies.js';
13
+ export { calculatePeriodicAmount, calculateBalanceRemaining, calculatePeriodsToZero, calculateInterestOverPeriods, } from './lib/shared/primitives.js';
14
+ export { snowball, avalanche, sortWith } from './lib/shared/sorting.js';
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,MAAM,WAAW,CAAC;AAG/B,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,eAAO,MAAM,iBAAiB,IAAI,CAAC;AACnC,eAAO,MAAM,gBAAgB,OAAO,CAAC"}
@@ -2,7 +2,7 @@
2
2
  * Represents a financial loan and provides methods for amortization and
3
3
  * interest calculations.
4
4
  */
5
- import { HasRateAndBalance } from '@/lib/shared/sorting';
5
+ import { HasRateAndBalance } from '../shared/sorting.js';
6
6
  export interface ILoan extends HasRateAndBalance {
7
7
  id: string;
8
8
  name: string;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loan.d.ts","sourceRoot":"","sources":["../../../src/lib/debt/loan.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,MAAM,WAAW,KAAM,SAAQ,iBAAiB;IAC9C,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,qBAAa,IAAK,YAAW,KAAK;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;;;;;OASG;gBAED,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,cAAc,CAAC,EAAE,MAAM,EACvB,IAAI,CAAC,EAAE,MAAM;IAef;;;;;;OAMG;IACH,eAAe,CAAC,aAAa,GAAE,MAAwB,GAAG,MAAM;IAYhE;;;OAGG;IACH,mBAAmB,IAAI,MAAM;IAQ7B;;;;;OAKG;IACH,cAAc,CAAC,aAAa,GAAE,MAA4B,GAAG,MAAM;IAInE;;;;;;OAMG;IACH,iBAAiB,CACf,aAAa,GAAE,MAAwB,EACvC,aAAa,GAAE,MAA4B,GAC1C,MAAM;IAST;;;;;;;OAOG;IACH,kBAAkB,CAChB,cAAc,EAAE,MAAM,EACtB,aAAa,GAAE,MAAwB,EACvC,aAAa,GAAE,MAA4B,GAC1C,MAAM;IAcT;;;;;;;OAOG;IACH,YAAY,CACV,cAAc,EAAE,MAAM,EACtB,aAAa,GAAE,MAAwB,EACvC,aAAa,GAAE,MAA4B,GAC1C,MAAM;CAyBV"}
@@ -2,8 +2,8 @@
2
2
  * Represents a financial loan and provides methods for amortization and
3
3
  * interest calculations.
4
4
  */
5
- import * as errors from '@/lib/errors';
6
- import * as primitives from '@/lib/shared/primitives';
5
+ import * as errors from '../errors.js';
6
+ import * as primitives from '../shared/primitives.js';
7
7
  export class Loan {
8
8
  /**
9
9
  * @constructor
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paymentTypes.d.ts","sourceRoot":"","sources":["../../../src/lib/debt/paymentTypes.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oBAAoB,EAAE,aAAa,EAAE,CAAC;CACvC,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAEnE,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
@@ -3,8 +3,8 @@
3
3
  * This file contains functions for computing detailed information on paying loans
4
4
  *
5
5
  */
6
- import type { ILoan, Loan } from '@/lib/debt/loan';
7
- import type { PaymentRecord, LoansPaymentSchedule } from '@/lib/debt/paymentTypes';
6
+ import type { ILoan, Loan } from '../debt/loan.js';
7
+ import type { PaymentRecord, LoansPaymentSchedule } from '../debt/paymentTypes.js';
8
8
  /**
9
9
  *
10
10
  * Calculates the extra amount in a payment after all loans' minimum payments are met
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../../../src/lib/debt/payments.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EACV,aAAa,EAEb,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,KAAK,EAAE,EACd,OAAO,EAAE,MAAM,GACd,MAAM,CAYR;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,OAAO,GACrB,MAAM,CAOR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GAAC,IAAI,EACpB,WAAW,EAAE,MAAM,GAAC,IAAI,EACxB,WAAW,GAAE,MAAU,EACvB,SAAS,GAAE,MAAU,GACpB,aAAa,EAAE,CA+BjB;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,IAAI,EAAE,EACb,OAAO,EAAE,MAAM,EACf,aAAa,GAAE,OAAe,GAC7B,oBAAoB,CAqItB"}
@@ -3,7 +3,7 @@
3
3
  * This file contains functions for computing detailed information on paying loans
4
4
  *
5
5
  */
6
- import * as errors from '@/lib/errors';
6
+ import * as errors from '../errors.js';
7
7
  /**
8
8
  *
9
9
  * Calculates the extra amount in a payment after all loans' minimum payments are met
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,OAAO,EAAE,MAAM;CAK5B"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contributionTypes.d.ts","sourceRoot":"","sources":["../../../src/lib/investment/contributionTypes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,kBAAkB,EAAE,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AAEnF,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAExD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
@@ -3,8 +3,8 @@
3
3
  * This file containts functions for computing detailed information on contributing to investments
4
4
  *
5
5
  */
6
- import type { Instrument } from '@/lib/investment/instrument';
7
- import { ContributionRecord, InstrumentsContributionSchedule } from '@/lib/investment/contributionTypes';
6
+ import type { Instrument } from '../investment/instrument.js';
7
+ import { ContributionRecord, InstrumentsContributionSchedule } from '../investment/contributionTypes.js';
8
8
  /**
9
9
  *
10
10
  * @param {IInstrument[]} instruments The instruments to allocate maximum contributions
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contributions.d.ts","sourceRoot":"","sources":["../../../src/lib/investment/contributions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EACL,kBAAkB,EAClB,+BAA+B,EAGhC,MAAM,oCAAoC,CAAC;AAE5C;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,UAAU,EAAE,EACzB,YAAY,EAAE,MAAM,GACnB,MAAM,CAMR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,MAAM,EACpB,WAAW,GAAE,MAAU,EACvB,wBAAwB,GAAE,OAAc,GACvC,kBAAkB,CAgBpB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EACxB,WAAW,GAAE,MAAU,EACvB,wBAAwB,GAAE,OAAc,GACvC,kBAAkB,EAAE,CAkBtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,UAAU,EAAE,EACzB,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EACxB,wBAAwB,GAAE,OAAc,GACvC,+BAA+B,CA6FjC"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Represents a financial instrument for investments and drawdowns.
3
3
  */
4
- import { HasRateAndBalance } from '@/lib/shared/sorting';
4
+ import { HasRateAndBalance } from '../shared/sorting.js';
5
5
  export interface IInstrument extends HasRateAndBalance {
6
6
  id: string;
7
7
  name: string;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrument.d.ts","sourceRoot":"","sources":["../../../src/lib/investment/instrument.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGzD,MAAM,WAAW,WAAY,SAAQ,iBAAiB;IACpD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,UAAW,YAAW,WAAW;IAC5C,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;;;;OAOG;gBAED,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,MAAM,EACZ,WAAW,GAAE,MAAU;IAWzB;;;;;;;OAOG;IACH,oBAAoB,CAAC,YAAY,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,GAAG,MAAM;IAmBlF;;;;;;OAMG;IACH,oBAAoB,CAClB,wBAAwB,EAAE,MAAM,EAChC,aAAa,GAAE,MAA4B,GAC1C,MAAM;IAQT;;;;;;OAMG;IACH,sBAAsB,CACpB,sBAAsB,EAAE,MAAM,EAC9B,aAAa,GAAE,MAA4B,GAC1C,MAAM;IAQT;;;;OAIG;IACH,oBAAoB,IAAI,MAAM;IAI9B;;;;;OAKG;IACH,cAAc,CAAC,aAAa,GAAE,MAA4B,GAAG,MAAM;CAGpE"}
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Represents a financial instrument for investments and drawdowns.
3
3
  */
4
- import * as errors from '@/lib/errors';
5
- import * as primitives from '@/lib/shared/primitives';
4
+ import * as errors from '../errors.js';
5
+ import * as primitives from '../shared/primitives.js';
6
6
  export class Instrument {
7
7
  /**
8
8
  * @constructor
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * This file contains high-level drawdown strategies for investment portfolios.
3
3
  */
4
- import { Instrument } from '@/lib/investment/instrument';
5
- import { InstrumentsWithdrawalSchedule } from '@/lib/investment/withdrawalTypes';
4
+ import { Instrument } from '../investment/instrument.js';
5
+ import { InstrumentsWithdrawalSchedule } from '../investment/withdrawalTypes.js';
6
6
  /**
7
7
  * Executes a 'Waterfall' drawdown strategy.
8
8
  * Funds are pulled from instruments in the order they appear in the array.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategies.d.ts","sourceRoot":"","sources":["../../../src/lib/investment/strategies.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,OAAO,EACL,6BAA6B,EAE9B,MAAM,kCAAkC,CAAC;AAG1C;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CACtC,oBAAoB,EAAE,UAAU,EAAE,EAClC,uBAAuB,EAAE,MAAM,EAC/B,sBAAsB,EAAE,MAAM,EAC9B,gBAAgB,GAAE,MAAU,GAC3B,6BAA6B,CAsE/B"}
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * This file contains high-level drawdown strategies for investment portfolios.
3
3
  */
4
- import { calculateAmortizedWithdrawal } from '@/lib/investment/withdrawals';
5
- import { TOTALS } from '@/lib/constants';
4
+ import { calculateAmortizedWithdrawal } from '../investment/withdrawals.js';
5
+ import { TOTALS } from '../constants.js';
6
6
  /**
7
7
  * Executes a 'Waterfall' drawdown strategy.
8
8
  * Funds are pulled from instruments in the order they appear in the array.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withdrawalTypes.d.ts","sourceRoot":"","sources":["../../../src/lib/investment/withdrawalTypes.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,gBAAgB,EAAE,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAAG;IAC/E,MAAM,EAAE,kBAAkB,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
@@ -2,8 +2,8 @@
2
2
  * This file contains functions for computing detailed information on drawing
3
3
  * down investment instruments during retirement distribution.
4
4
  */
5
- import { Instrument } from '@/lib/investment/instrument';
6
- import { WithdrawalRecord, InstrumentsWithdrawalSchedule } from '@/lib/investment/withdrawalTypes';
5
+ import { Instrument } from '../investment/instrument.js';
6
+ import { WithdrawalRecord, InstrumentsWithdrawalSchedule } from '../investment/withdrawalTypes.js';
7
7
  /**
8
8
  * Calculates a single period's withdrawal record.
9
9
  *
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withdrawals.d.ts","sourceRoot":"","sources":["../../../src/lib/investment/withdrawals.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAE9B,MAAM,kCAAkC,CAAC;AAE1C;;;;;;;;;;GAUG;AACH,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,UAAU,EACtB,wBAAwB,EAAE,MAAM,EAChC,wBAAwB,EAAE,MAAM,EAChC,oBAAoB,GAAE,MAAU,EAChC,iBAAiB,GAAE,MAAU,EAC7B,sBAAsB,GAAE,OAAc,GACrC,gBAAgB,CAqClB;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,UAAU,EAAE,EACzB,uBAAuB,EAAE,MAAM,EAC/B,sBAAsB,EAAE,MAAM,EAC9B,gBAAgB,GAAE,MAAU,EAC5B,sBAAsB,GAAE,OAAc,GACrC,6BAA6B,CAsE/B"}
@@ -2,8 +2,8 @@
2
2
  * This file contains functions for computing detailed information on drawing
3
3
  * down investment instruments during retirement distribution.
4
4
  */
5
- import { TOTALS } from '@/lib/constants';
6
- import * as errors from '@/lib/errors';
5
+ import { TOTALS } from '../constants.js';
6
+ import * as errors from '../errors.js';
7
7
  /**
8
8
  * Calculates a single period's withdrawal record.
9
9
  *
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../../src/lib/shared/primitives.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,eAAe,EAAE,MAAM,EACvB,oBAAoB,EAAE,MAAM,EAC5B,oBAAoB,EAAE,MAAM,GAC3B,MAAM,CAMR;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CACvC,cAAc,EAAE,MAAM,EACtB,qBAAqB,EAAE,MAAM,EAC7B,oBAAoB,EAAE,MAAM,EAC5B,cAAc,EAAE,MAAM,GACrB,MAAM,CAWR;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,cAAc,EAAE,MAAM,EACtB,qBAAqB,EAAE,MAAM,EAC7B,oBAAoB,EAAE,MAAM,GAC3B,MAAM,CAKR;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,cAAc,EAAE,MAAM,EACtB,qBAAqB,EAAE,MAAM,EAC7B,oBAAoB,EAAE,MAAM,EAC5B,cAAc,EAAE,MAAM,GACrB,MAAM,CAYR"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sorting.d.ts","sourceRoot":"","sources":["../../../src/lib/shared/sorting.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,iBAAiB,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAC;CAAE,CAAC;AAEhF,KAAK,YAAY,GAAG,CAAC,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,iBAAiB,KAAK,MAAM,CAAC;AAEjF;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,iBAAiB,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAE/E;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,iBAAiB,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAE9E;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,iBAAiB,EAClD,QAAQ,EAAE,CAAC,EAAE,EACb,YAAY,EAAE,YAAY,GACzB,CAAC,EAAE,CAEL"}
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "moneyfunx",
3
- "version": "3.0.2",
3
+ "version": "3.0.7",
4
4
  "type": "module",
5
- "main": "./build/index.js",
6
- "types": "./build/index.d.ts",
7
5
  "exports": {
8
6
  ".": {
9
7
  "types": "./build/index.d.ts",
10
- "import": "./build/index.js"
8
+ "import": "./build/index.js",
9
+ "require": "./build/index.cjs"
11
10
  }
12
11
  },
12
+ "main": "./build/index.cjs",
13
+ "module": "./build/index.js",
14
+ "types": "./build/index.d.ts",
13
15
  "files": [
14
16
  "build"
15
17
  ],
@@ -1,17 +0,0 @@
1
- /**
2
- * MoneyFunx
3
- * * mek it funx up
4
- */
5
- export { MAX_DURATION_YEARS, TOTALS, } from '@/lib/constants';
6
- export { ILoan, Loan } from '@/lib/debt/loan';
7
- export { determineExtraPayment, amortizePayments, payLoans, } from '@/lib/debt/payments';
8
- export { PaymentRecord, LoansPaymentSchedule, LoanPrincipals, PaymentSchedule, } from '@/lib/debt/paymentTypes';
9
- export { NegativeContributionError, PaymentTooLowError, NegativeWithdrawalError } from '@/lib/errors';
10
- export { amortizeContributions, contributeInstruments, determineExtraContribution, } from '@/lib/investment/contributions';
11
- export { ContributionRecord, ContributionSchedule, InstrumentsContributionSchedule, } from '@/lib/investment/contributionTypes';
12
- export { IInstrument, Instrument } from '@/lib/investment/instrument';
13
- export { calculateAmortizedWithdrawal, drawdownInstruments, } from '@/lib/investment/withdrawals';
14
- export { WithdrawalRecord, WithdrawalSchedule, InstrumentsWithdrawalSchedule, } from '@/lib/investment/withdrawalTypes';
15
- export { calculatePeriodicAmount, calculateBalanceRemaining, calculatePeriodsToZero, calculateInterestOverPeriods, } from '@/lib/shared/primitives';
16
- export { HasRateAndBalance, snowball, avalanche, sortWith } from '@/lib/shared/sorting';
17
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,kBAAkB,EAClB,MAAM,GACP,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,QAAQ,GACT,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,eAAe,GAChB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEtG,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,+BAA+B,GAChC,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEtE,OAAO,EACL,4BAA4B,EAC5B,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,GAC9B,MAAM,kCAAkC,CAAC;AAM1C,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC"}
@@ -1,16 +0,0 @@
1
- /**
2
- * MoneyFunx
3
- * * mek it funx up
4
- */
5
- export { MAX_DURATION_YEARS, TOTALS, } from '@/lib/constants';
6
- export { Loan } from '@/lib/debt/loan';
7
- export { determineExtraPayment, amortizePayments, payLoans, } from '@/lib/debt/payments';
8
- export { NegativeContributionError, PaymentTooLowError, NegativeWithdrawalError } from '@/lib/errors';
9
- export { amortizeContributions, contributeInstruments, determineExtraContribution, } from '@/lib/investment/contributions';
10
- export { Instrument } from '@/lib/investment/instrument';
11
- export { calculateAmortizedWithdrawal, drawdownInstruments, } from '@/lib/investment/withdrawals';
12
- // export {
13
- // performWaterfallDrawdown,
14
- // } from '@/lib/investment/strategies';
15
- export { calculatePeriodicAmount, calculateBalanceRemaining, calculatePeriodsToZero, calculateInterestOverPeriods, } from '@/lib/shared/primitives';
16
- export { snowball, avalanche, sortWith } from '@/lib/shared/sorting';
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,MAAM,WAAW,CAAC;AAG/B,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,eAAO,MAAM,iBAAiB,IAAI,CAAC;AACnC,eAAO,MAAM,gBAAgB,OAAO,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"loan.d.ts","sourceRoot":"","sources":["../../../../src/lib/debt/loan.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,MAAM,WAAW,KAAM,SAAQ,iBAAiB;IAC9C,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,qBAAa,IAAK,YAAW,KAAK;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;;;;;OASG;gBAED,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,cAAc,CAAC,EAAE,MAAM,EACvB,IAAI,CAAC,EAAE,MAAM;IAef;;;;;;OAMG;IACH,eAAe,CAAC,aAAa,GAAE,MAAwB,GAAG,MAAM;IAYhE;;;OAGG;IACH,mBAAmB,IAAI,MAAM;IAQ7B;;;;;OAKG;IACH,cAAc,CAAC,aAAa,GAAE,MAA4B,GAAG,MAAM;IAInE;;;;;;OAMG;IACH,iBAAiB,CACf,aAAa,GAAE,MAAwB,EACvC,aAAa,GAAE,MAA4B,GAC1C,MAAM;IAST;;;;;;;OAOG;IACH,kBAAkB,CAChB,cAAc,EAAE,MAAM,EACtB,aAAa,GAAE,MAAwB,EACvC,aAAa,GAAE,MAA4B,GAC1C,MAAM;IAcT;;;;;;;OAOG;IACH,YAAY,CACV,cAAc,EAAE,MAAM,EACtB,aAAa,GAAE,MAAwB,EACvC,aAAa,GAAE,MAA4B,GAC1C,MAAM;CAyBV"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"paymentTypes.d.ts","sourceRoot":"","sources":["../../../../src/lib/debt/paymentTypes.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oBAAoB,EAAE,aAAa,EAAE,CAAC;CACvC,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAEnE,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../../../../src/lib/debt/payments.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EACV,aAAa,EAEb,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,KAAK,EAAE,EACd,OAAO,EAAE,MAAM,GACd,MAAM,CAYR;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,OAAO,GACrB,MAAM,CAOR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GAAC,IAAI,EACpB,WAAW,EAAE,MAAM,GAAC,IAAI,EACxB,WAAW,GAAE,MAAU,EACvB,SAAS,GAAE,MAAU,GACpB,aAAa,EAAE,CA+BjB;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,IAAI,EAAE,EACb,OAAO,EAAE,MAAM,EACf,aAAa,GAAE,OAAe,GAC7B,oBAAoB,CAqItB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/lib/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,OAAO,EAAE,MAAM;CAK5B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"contributionTypes.d.ts","sourceRoot":"","sources":["../../../../src/lib/investment/contributionTypes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,kBAAkB,EAAE,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AAEnF,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAExD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"contributions.d.ts","sourceRoot":"","sources":["../../../../src/lib/investment/contributions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EACL,kBAAkB,EAClB,+BAA+B,EAGhC,MAAM,oCAAoC,CAAC;AAE5C;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,UAAU,EAAE,EACzB,YAAY,EAAE,MAAM,GACnB,MAAM,CAMR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,MAAM,EACpB,WAAW,GAAE,MAAU,EACvB,wBAAwB,GAAE,OAAc,GACvC,kBAAkB,CAgBpB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EACxB,WAAW,GAAE,MAAU,EACvB,wBAAwB,GAAE,OAAc,GACvC,kBAAkB,EAAE,CAkBtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,UAAU,EAAE,EACzB,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EACxB,wBAAwB,GAAE,OAAc,GACvC,+BAA+B,CA6FjC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"instrument.d.ts","sourceRoot":"","sources":["../../../../src/lib/investment/instrument.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGzD,MAAM,WAAW,WAAY,SAAQ,iBAAiB;IACpD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,UAAW,YAAW,WAAW;IAC5C,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;;;;OAOG;gBAED,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,MAAM,EACZ,WAAW,GAAE,MAAU;IAWzB;;;;;;;OAOG;IACH,oBAAoB,CAAC,YAAY,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,GAAG,MAAM;IAmBlF;;;;;;OAMG;IACH,oBAAoB,CAClB,wBAAwB,EAAE,MAAM,EAChC,aAAa,GAAE,MAA4B,GAC1C,MAAM;IAQT;;;;;;OAMG;IACH,sBAAsB,CACpB,sBAAsB,EAAE,MAAM,EAC9B,aAAa,GAAE,MAA4B,GAC1C,MAAM;IAQT;;;;OAIG;IACH,oBAAoB,IAAI,MAAM;IAI9B;;;;;OAKG;IACH,cAAc,CAAC,aAAa,GAAE,MAA4B,GAAG,MAAM;CAGpE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"strategies.d.ts","sourceRoot":"","sources":["../../../../src/lib/investment/strategies.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,OAAO,EACL,6BAA6B,EAE9B,MAAM,kCAAkC,CAAC;AAG1C;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CACtC,oBAAoB,EAAE,UAAU,EAAE,EAClC,uBAAuB,EAAE,MAAM,EAC/B,sBAAsB,EAAE,MAAM,EAC9B,gBAAgB,GAAE,MAAU,GAC3B,6BAA6B,CAsE/B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"withdrawalTypes.d.ts","sourceRoot":"","sources":["../../../../src/lib/investment/withdrawalTypes.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,gBAAgB,EAAE,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAAG;IAC/E,MAAM,EAAE,kBAAkB,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"withdrawals.d.ts","sourceRoot":"","sources":["../../../../src/lib/investment/withdrawals.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAE9B,MAAM,kCAAkC,CAAC;AAE1C;;;;;;;;;;GAUG;AACH,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,UAAU,EACtB,wBAAwB,EAAE,MAAM,EAChC,wBAAwB,EAAE,MAAM,EAChC,oBAAoB,GAAE,MAAU,EAChC,iBAAiB,GAAE,MAAU,EAC7B,sBAAsB,GAAE,OAAc,GACrC,gBAAgB,CAqClB;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,UAAU,EAAE,EACzB,uBAAuB,EAAE,MAAM,EAC/B,sBAAsB,EAAE,MAAM,EAC9B,gBAAgB,GAAE,MAAU,EAC5B,sBAAsB,GAAE,OAAc,GACrC,6BAA6B,CAsE/B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../../../src/lib/shared/primitives.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,eAAe,EAAE,MAAM,EACvB,oBAAoB,EAAE,MAAM,EAC5B,oBAAoB,EAAE,MAAM,GAC3B,MAAM,CAMR;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CACvC,cAAc,EAAE,MAAM,EACtB,qBAAqB,EAAE,MAAM,EAC7B,oBAAoB,EAAE,MAAM,EAC5B,cAAc,EAAE,MAAM,GACrB,MAAM,CAWR;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,cAAc,EAAE,MAAM,EACtB,qBAAqB,EAAE,MAAM,EAC7B,oBAAoB,EAAE,MAAM,GAC3B,MAAM,CAKR;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,cAAc,EAAE,MAAM,EACtB,qBAAqB,EAAE,MAAM,EAC7B,oBAAoB,EAAE,MAAM,EAC5B,cAAc,EAAE,MAAM,GACrB,MAAM,CAYR"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"sorting.d.ts","sourceRoot":"","sources":["../../../../src/lib/shared/sorting.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,iBAAiB,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAC;CAAE,CAAC;AAEhF,KAAK,YAAY,GAAG,CAAC,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,iBAAiB,KAAK,MAAM,CAAC;AAEjF;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,iBAAiB,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAE/E;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,iBAAiB,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAE9E;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,iBAAiB,EAClD,QAAQ,EAAE,CAAC,EAAE,EACb,YAAY,EAAE,YAAY,GACzB,CAAC,EAAE,CAEL"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=loan.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"loan.test.d.ts","sourceRoot":"","sources":["../../../tests/debt/loan.test.ts"],"names":[],"mappings":""}
@@ -1,87 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { describe, expect, it } from 'vitest';
11
- import { Loan } from '@/lib/debt/loan';
12
- const Loans = () => [
13
- new Loan(7500, 0.068, 12, 10, 'Student Loan'),
14
- new Loan(150000, 0.0622, 12, 15, 'Mortgage', 75000, 1000),
15
- new Loan(18300, 0, 12, 4, 'Car'),
16
- ];
17
- function expectPaymentTooLow(fn, min, val) {
18
- expect(fn).toThrow(`payment of ${val} cannot be less than ${min}`);
19
- }
20
- describe('loan module', () => {
21
- const [loan1, mortgage, zeroRateLoan] = Loans();
22
- it('creates a Loan with proper attributes', () => __awaiter(void 0, void 0, void 0, function* () {
23
- expect(loan1.name).toBe('Student Loan');
24
- expect(loan1.principal).toBe(7500);
25
- expect(loan1.annualRate).toBe(0.068);
26
- expect(loan1.periodicRate).toBeCloseTo(0.068 / 12);
27
- expect(loan1.periods).toBe(120);
28
- expect(loan1.minPayment).toBeCloseTo(86.310247, 5);
29
- expect(loan1.currentBalance).toBe(7500);
30
- expect(loan1.fees).toBe(0);
31
- }));
32
- it('creates a Loan with working methods', () => __awaiter(void 0, void 0, void 0, function* () {
33
- expect(loan1.numPaymentsToZero()).toBe(120);
34
- expect(loan1.numPaymentsToZero(300)).toBe(28);
35
- expectPaymentTooLow(() => loan1.numPaymentsToZero(30), loan1.minPayment, 30);
36
- expect(loan1.validatePayment(100)).toBe(100);
37
- expect(loan1.validatePayment()).toBeCloseTo(86.310247, 5);
38
- expectPaymentTooLow(() => loan1.numPaymentsToZero(-160), loan1.minPayment, -160);
39
- expect(loan1.principalRemaining(33)).toBeCloseTo(5915.168870, 5);
40
- expect(loan1.principalRemaining(0)).toBe(7500);
41
- expect(loan1.principalRemaining(8, 300)).toBeCloseTo(5398.676996, 5);
42
- expect(loan1.principalRemaining(40, 500)).toBe(0);
43
- expect(loan1.principalRemaining(3, 200, 3000)).toBeCloseTo(2447.883123, 5);
44
- expect(() => {
45
- loan1.principalRemaining(21, 40, 9000);
46
- }).toThrow(`payment of 40 cannot be less than ${loan1.minPayment}`);
47
- expect(loan1.interestPaid(0)).toBe(0);
48
- expect(loan1.interestPaid(22)).toBeCloseTo(875.426397, 5);
49
- expect(loan1.interestPaid(8, 300)).toBeCloseTo(298.676996, 5);
50
- expect(loan1.interestPaid(50, 300)).toBeCloseTo(610.360992, 5);
51
- expectPaymentTooLow(() => loan1.interestPaid(30, 10, 20000), loan1.minPayment, 10);
52
- }));
53
- it('creates a Loan with optional parameters and proper attributes', () => __awaiter(void 0, void 0, void 0, function* () {
54
- expect(mortgage.name).toBe('Mortgage');
55
- expect(mortgage.principal).toBe(150000);
56
- expect(mortgage.annualRate).toBe(0.0622);
57
- expect(mortgage.periodicRate).toBeCloseTo(0.005183, 5);
58
- expect(mortgage.periods).toBe(180);
59
- expect(mortgage.minPayment).toBeCloseTo(1283.683005, 5);
60
- expect(mortgage.currentBalance).toBe(75000);
61
- expect(mortgage.fees).toBe(1000);
62
- }));
63
- it('creates a Loan with optional parameters and working methods', () => __awaiter(void 0, void 0, void 0, function* () {
64
- expect(mortgage.numPaymentsToZero()).toBe(70);
65
- expect(mortgage.numPaymentsToZero(1500)).toBe(59);
66
- expectPaymentTooLow(() => mortgage.numPaymentsToZero(300), mortgage.minPayment, 300);
67
- expect(mortgage.validatePayment(1300)).toBe(1300);
68
- expect(mortgage.validatePayment()).toBeCloseTo(1283.683005, 5);
69
- expectPaymentTooLow(() => mortgage.validatePayment(20), mortgage.minPayment, 20);
70
- expectPaymentTooLow(() => mortgage.validatePayment(-160), mortgage.minPayment, -160);
71
- expect(mortgage.principalRemaining(33)).toBeCloseTo(42881.516563, 5);
72
- expect(mortgage.principalRemaining(0)).toBe(75000);
73
- expect(mortgage.principalRemaining(8, 1300)).toBeCloseTo(67576.367309, 5);
74
- expect(mortgage.principalRemaining(60, 1500)).toBe(0);
75
- expect(mortgage.principalRemaining(3, 1300, 4000)).toBeCloseTo(142.273033, 5);
76
- expectPaymentTooLow(() => mortgage.principalRemaining(21, 40, 9000), mortgage.minPayment, 40);
77
- expect(mortgage.interestPaid(0)).toBe(0);
78
- expect(mortgage.interestPaid(22)).toBeCloseTo(7442.995104, 5);
79
- expect(mortgage.interestPaid(8, 1300)).toBeCloseTo(2976.367309, 5);
80
- expect(mortgage.interestPaid(50, 1300)).toBeCloseTo(13140.910180, 5);
81
- expect(mortgage.interestPaid(59)).toBeCloseTo(14157.609595, 5);
82
- expectPaymentTooLow(() => mortgage.interestPaid(30, 10, 20000), mortgage.minPayment, 10);
83
- }));
84
- it('calculates min payment for zero-interest loan correctly', () => __awaiter(void 0, void 0, void 0, function* () {
85
- expect(zeroRateLoan.minPayment).toBe(381.25);
86
- }));
87
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=payments.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"payments.test.d.ts","sourceRoot":"","sources":["../../../tests/debt/payments.test.ts"],"names":[],"mappings":""}
@@ -1,91 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { describe, expect, it } from 'vitest';
11
- import * as constants from '@/lib/constants';
12
- import { Loan } from '@/lib/debt/loan';
13
- import * as payments from '@/lib/debt/payments';
14
- import * as sorting from '@/lib/shared/sorting';
15
- const Loans = () => [
16
- new Loan(314159.26, 0.0535, 12, 15, 'pi-house'),
17
- new Loan(27182.81, 0.0828, 12, 4, 'e-car', 23456.78),
18
- new Loan(10000, 0.0628, 12, 3, 'tau', undefined, 300),
19
- ];
20
- describe('payments module', () => {
21
- const [homeLoan, carLoan, otherLoan] = Loans();
22
- const loansAV = sorting.sortWith([otherLoan, homeLoan, carLoan], sorting.avalanche);
23
- const loansMinPayment = loansAV.reduce((currentValue, loan) => currentValue += loan.minPayment, 0);
24
- it('amortizes a single loan', () => __awaiter(void 0, void 0, void 0, function* () {
25
- const homeLoanAmortizationSchedule = payments.amortizePayments(homeLoan, homeLoan.principal, null, null);
26
- expect(homeLoanAmortizationSchedule.length).toBe(181);
27
- expect(homeLoanAmortizationSchedule[3].period).toBe(4);
28
- expect(homeLoanAmortizationSchedule[3].principal).toBeCloseTo(1156.712773, 5);
29
- expect(homeLoanAmortizationSchedule[3].interest).toBeCloseTo(1385.292599, 5);
30
- expect(homeLoanAmortizationSchedule[3].principalRemaining).toBeCloseTo(309563.122582, 5);
31
- expect(homeLoanAmortizationSchedule[119].period).toBe(120);
32
- expect(homeLoanAmortizationSchedule[119].principal).toBeCloseTo(1937.889312, 5);
33
- expect(homeLoanAmortizationSchedule[119].interest).toBeCloseTo(604.116060, 5);
34
- expect(homeLoanAmortizationSchedule[119].principalRemaining).toBeCloseTo(133564.778411, 5);
35
- expect(homeLoanAmortizationSchedule[179].period).toBe(180);
36
- expect(homeLoanAmortizationSchedule[179].principal).toBeCloseTo(2530.722568, 5);
37
- expect(homeLoanAmortizationSchedule[179].interest).toBeCloseTo(11.282804, 5);
38
- expect(homeLoanAmortizationSchedule[179].principalRemaining).toBe(0);
39
- }));
40
- it('determines extra payment for multiple loans', () => __awaiter(void 0, void 0, void 0, function* () {
41
- expect(payments.determineExtraPayment(loansAV, 3700)).toBeCloseTo(185.314618, 5);
42
- }));
43
- it('throws a paymentTooLowError when the total payment for loans is below their shared minimum', () => __awaiter(void 0, void 0, void 0, function* () {
44
- const tooLowPayment = 28;
45
- expect(() => {
46
- payments.determineExtraPayment(loansAV, tooLowPayment);
47
- }).toThrow(`Payment amount of ${tooLowPayment} must be greater than ${loansMinPayment}`);
48
- }));
49
- it('determines carryover', () => __awaiter(void 0, void 0, void 0, function* () {
50
- expect(payments.determineCarryover(carLoan, 1867.19, 348.33, false)).toBeCloseTo(1518.860000, 5);
51
- expect(payments.determineCarryover(carLoan, 1867.19, 348.33, true)).toBeCloseTo(851.669664, 5);
52
- }));
53
- it('amortizes payments for mutliple loans', () => __awaiter(void 0, void 0, void 0, function* () {
54
- const loansPaymentSummary = payments.payLoans(loansAV, 4000);
55
- for (const loanAV of loansAV) {
56
- expect(loansPaymentSummary[loanAV.id].lifetimeInterest.toFixed(5)).toBe(loansPaymentSummary[loanAV.id].amortizationSchedule
57
- .reduce((acc, cv) => acc + cv.interest, 0)
58
- .toFixed(5));
59
- }
60
- // 2 keys more than the 3 loans for totalInterest and totalPayments
61
- expect(Object.keys(loansPaymentSummary).length).toBe(4);
62
- expect(loansPaymentSummary[carLoan.id].lifetimeInterest).toBeCloseTo(1906.719625, 5);
63
- expect(loansPaymentSummary[homeLoan.id].lifetimeInterest).toBeCloseTo(91584.952030, 5);
64
- expect(loansPaymentSummary[otherLoan.id].lifetimeInterest).toBeCloseTo(876.423974, 5);
65
- expect(loansPaymentSummary[constants.TOTALS].lifetimeInterest).toBeCloseTo(94368.095630, 5);
66
- expect(loansPaymentSummary[constants.TOTALS].amortizationSchedule.length).toBe(111);
67
- expect(loansPaymentSummary[constants.TOTALS].amortizationSchedule[110].principal).toBeCloseTo(1975.328955, 5);
68
- expect(loansPaymentSummary[constants.TOTALS].amortizationSchedule[110].interest).toBeCloseTo(8.806674, 5);
69
- expect(loansPaymentSummary[constants.TOTALS].amortizationSchedule[110].principalRemaining).toBe(0);
70
- }));
71
- it('reduces minimum payments correctly and amortizes payments for multiple loans', () => __awaiter(void 0, void 0, void 0, function* () {
72
- const loansPaymentSummary = payments.payLoans(loansAV, 4000, true);
73
- for (const loanAV of loansAV) {
74
- expect(loansPaymentSummary[loanAV.id].lifetimeInterest.toFixed(5)).toBe(loansPaymentSummary[loanAV.id].amortizationSchedule
75
- .reduce((acc, cv) => acc + cv.interest, 0)
76
- .toFixed(5));
77
- }
78
- expect(Object.keys(loansPaymentSummary).length).toBe(4);
79
- expect(loansPaymentSummary[carLoan.id].lifetimeInterest).toBeCloseTo(1906.719625, 5);
80
- expect(loansPaymentSummary[homeLoan.id].lifetimeInterest).toBeCloseTo(118982.162556, 5);
81
- expect(loansPaymentSummary[otherLoan.id].lifetimeInterest).toBeCloseTo(902.921493, 5);
82
- expect(loansPaymentSummary[constants.TOTALS].lifetimeInterest).toBeCloseTo(121791.803675, 5);
83
- expect(loansPaymentSummary[constants.TOTALS].amortizationSchedule.length).toBe(148);
84
- expect(loansPaymentSummary[constants.TOTALS].amortizationSchedule[110].principal).toBeCloseTo(2562.376664, 5);
85
- expect(loansPaymentSummary[constants.TOTALS].amortizationSchedule[110].interest).toBeCloseTo(464.943326, 5);
86
- expect(loansPaymentSummary[constants.TOTALS].amortizationSchedule[110].principalRemaining).toBeCloseTo(101723.977006, 5);
87
- expect(loansPaymentSummary[constants.TOTALS].amortizationSchedule[147].principal).toBeCloseTo(1458.892110, 5);
88
- expect(loansPaymentSummary[constants.TOTALS].amortizationSchedule[147].interest).toBeCloseTo(6.504227, 5);
89
- expect(loansPaymentSummary[constants.TOTALS].amortizationSchedule[147].principalRemaining).toBe(0);
90
- }));
91
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=sorting.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sorting.test.d.ts","sourceRoot":"","sources":["../../../tests/debt/sorting.test.ts"],"names":[],"mappings":""}
@@ -1,43 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { describe, expect, it } from 'vitest';
11
- import { Loan } from '@/lib/debt/loan';
12
- import * as sorting from '@/lib/shared/sorting';
13
- const Loans = () => [
14
- new Loan(7500, 0.068, 12, 10, 'uno'),
15
- new Loan(4500, 0.0429, 12, 10, 'dos'),
16
- new Loan(7500, 0.0368, 12, 10, 'tres'),
17
- ];
18
- describe('sorting module', () => {
19
- const loans = Loans();
20
- const [loan2, loan3, loan1] = loans;
21
- it('avalanche compares loans correctly', () => __awaiter(void 0, void 0, void 0, function* () {
22
- expect(sorting.avalanche(loan2, loan1)).toBeCloseTo(-0.031200, 5);
23
- expect(sorting.avalanche(loan3, loan1)).toBeCloseTo(-0.006100, 5);
24
- }));
25
- it('snowball compares loans correctly', () => __awaiter(void 0, void 0, void 0, function* () {
26
- expect(sorting.snowball(loan2, loan3)).toBe(3000);
27
- expect(sorting.snowball(loan2, loan1)).toBe(0);
28
- }));
29
- it('orders loans correctly using avalanche sorting', () => __awaiter(void 0, void 0, void 0, function* () {
30
- expect(sorting.sortWith(loans, sorting.avalanche)).toStrictEqual([
31
- loan2,
32
- loan3,
33
- loan1,
34
- ]);
35
- }));
36
- it('orders loans correctly using snowball sorting', () => __awaiter(void 0, void 0, void 0, function* () {
37
- expect(sorting.sortWith(loans, sorting.snowball)).toStrictEqual([
38
- loan3,
39
- loan2,
40
- loan1,
41
- ]);
42
- }));
43
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../tests/index.test.ts"],"names":[],"mappings":""}
@@ -1,66 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { describe, expect, it } from 'vitest';
11
- import * as moneyfunx from '@/index';
12
- /**
13
- * Ensures all intended public members are exported from the library.
14
- * This test acts as a safeguard against accidental omission of core functionality
15
- * during refactors or version bumps.
16
- */
17
- describe('moneyfunx module', () => {
18
- it('exports expected members matching the new descriptive naming standard', () => __awaiter(void 0, void 0, void 0, function* () {
19
- const expectedExports = [
20
- // Constants
21
- 'MAX_DURATION_YEARS',
22
- 'TOTALS',
23
- // Debt / Loans
24
- 'ILoan',
25
- 'Loan',
26
- 'determineExtraPayment',
27
- 'amortizePayments',
28
- 'payLoans',
29
- 'LoansPaymentSchedule',
30
- 'LoanPrincipals',
31
- 'PaymentSchedule',
32
- 'PaymentRecord',
33
- // Investment / Accumulation
34
- 'IInstrument',
35
- 'Instrument',
36
- 'amortizeContributions',
37
- 'contributeInstruments',
38
- 'determineExtraContribution',
39
- 'ContributionRecord',
40
- 'ContributionSchedule',
41
- 'InstrumentsContributionSchedule',
42
- // Drawdown / Distribution
43
- 'calculateAmortizedWithdrawal',
44
- 'drawdownInstruments',
45
- 'WithdrawalRecord',
46
- 'WithdrawalSchedule',
47
- 'InstrumentsWithdrawalSchedule',
48
- // 'performWaterfallDrawdown',
49
- // Shared Math Primitives
50
- 'calculatePeriodicAmount',
51
- 'calculateBalanceRemaining',
52
- 'calculatePeriodsToZero',
53
- 'calculateInterestOverPeriods',
54
- // Errors
55
- 'NegativeContributionError',
56
- 'PaymentTooLowError',
57
- 'NegativeWithdrawalError',
58
- // Shared Utilities
59
- 'HasRateAndBalance',
60
- 'snowball',
61
- 'avalanche',
62
- 'sortWith',
63
- ].sort();
64
- expect(Object.keys(moneyfunx).sort()).toStrictEqual(expectedExports);
65
- }));
66
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=contributions.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contributions.test.d.ts","sourceRoot":"","sources":["../../../tests/investment/contributions.test.ts"],"names":[],"mappings":""}
@@ -1,113 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { describe, expect, it } from 'vitest';
11
- import * as constants from '@/lib/constants';
12
- import { Instrument } from '@/lib/investment/instrument';
13
- import * as contributions from '@/lib/investment/contributions';
14
- const Instruments = () => [
15
- new Instrument(10000, 0.11, 12, 'IRA', 6500),
16
- new Instrument(45000, 0.085, 12, '401(K)', 23500),
17
- new Instrument(0, 0.042666667, 12, 'ABC'),
18
- ];
19
- describe('contributions module', () => {
20
- const instruments = Instruments();
21
- const [inst1, inst2, inst3] = instruments;
22
- it('amortizes a single instrument', () => __awaiter(void 0, void 0, void 0, function* () {
23
- const iraAmortizationSchedulePre = contributions.amortizeContributions(inst1, inst1.currentBalance, inst1.periodicContribution(), 60, 0, true);
24
- expect(iraAmortizationSchedulePre.length).toBe(60);
25
- expect(iraAmortizationSchedulePre[3].period).toBe(4);
26
- expect(iraAmortizationSchedulePre[3].contribution).toBeCloseTo(541.666666, 5);
27
- expect(iraAmortizationSchedulePre[3].growth).toBeCloseTo(109.243473, 5);
28
- expect(iraAmortizationSchedulePre[3].currentBalance).toBeCloseTo(12568.380024, 5);
29
- expect(iraAmortizationSchedulePre[44].period).toBe(45);
30
- expect(iraAmortizationSchedulePre[44].contribution).toBeCloseTo(541.666666, 5);
31
- expect(iraAmortizationSchedulePre[44].growth).toBeCloseTo(404.570099, 5);
32
- expect(iraAmortizationSchedulePre[44].currentBalance).toBeCloseTo(45081.156667, 5);
33
- const iraAmortizationSchedulePost = contributions.amortizeContributions(inst1, inst1.currentBalance, inst1.periodicContribution(), 60, 0, false);
34
- expect(iraAmortizationSchedulePost.length).toBe(60);
35
- expect(iraAmortizationSchedulePost[3].period).toBe(4);
36
- expect(iraAmortizationSchedulePost[3].contribution).toBeCloseTo(541.666666, 5);
37
- expect(iraAmortizationSchedulePost[3].growth).toBeCloseTo(114.346552, 5);
38
- expect(iraAmortizationSchedulePost[3].currentBalance).toBeCloseTo(12588.515898, 5);
39
- expect(iraAmortizationSchedulePost[44].period).toBe(45);
40
- expect(iraAmortizationSchedulePost[44].contribution).toBeCloseTo(541.666666, 5);
41
- expect(iraAmortizationSchedulePost[44].growth).toBeCloseTo(411.988512, 5);
42
- expect(iraAmortizationSchedulePost[44].currentBalance).toBeCloseTo(45356.189858, 5);
43
- }));
44
- it('uses annualLimits on instruments', () => __awaiter(void 0, void 0, void 0, function* () {
45
- const workAcctAmortizationSchedule = contributions.amortizeContributions(inst2, inst2.currentBalance, 2000, 24);
46
- expect(workAcctAmortizationSchedule.length).toBe(24);
47
- expect(workAcctAmortizationSchedule[3].period).toBe(4);
48
- expect(workAcctAmortizationSchedule[3].contribution).toBe(23500 / 12);
49
- expect(workAcctAmortizationSchedule[3].growth).toBeCloseTo(367.481578, 5);
50
- expect(workAcctAmortizationSchedule[3].currentBalance).toBeCloseTo(54205.567182, 5);
51
- expect(workAcctAmortizationSchedule[23].period).toBe(24);
52
- expect(workAcctAmortizationSchedule[23].contribution).toBe(23500 / 12);
53
- expect(workAcctAmortizationSchedule[23].growth).toBeCloseTo(720.115315, 5);
54
- expect(workAcctAmortizationSchedule[23].currentBalance).toBeCloseTo(104341.787377, 5);
55
- }));
56
- it('determines extra contributions', () => __awaiter(void 0, void 0, void 0, function* () {
57
- expect(contributions.determineExtraContribution(instruments, 2250)).toBe(0);
58
- expect(contributions.determineExtraContribution(instruments, 3000)).toBe(500);
59
- }));
60
- it('amortizes contributions for multiple instruments', () => __awaiter(void 0, void 0, void 0, function* () {
61
- const instrumentsContributionSummary = contributions.contributeInstruments(instruments, 2250, 300);
62
- expect(Object.keys(instrumentsContributionSummary).length).toBe(4);
63
- expect(instrumentsContributionSummary[inst1.id].lifetimeContribution).toBeCloseTo(162499.999999, 5);
64
- expect(instrumentsContributionSummary[inst1.id].lifetimeGrowth).toBeCloseTo(835717.757059, 5);
65
- expect(instrumentsContributionSummary[inst1.id].amortizationSchedule.length).toBe(300);
66
- // correct below given current code
67
- // but need to write ways to default/spread a single contribution across instruments
68
- expect(instrumentsContributionSummary[inst3.id].lifetimeContribution).toBe(0);
69
- expect(instrumentsContributionSummary[inst3.id].lifetimeGrowth).toBe(0);
70
- expect(instrumentsContributionSummary[inst3.id].amortizationSchedule.length).toBe(300);
71
- expect(instrumentsContributionSummary[constants.TOTALS].lifetimeContribution).toBeCloseTo(674999.999999, 5);
72
- expect(instrumentsContributionSummary[constants.TOTALS].lifetimeGrowth).toBeCloseTo(2415285.956132, 5);
73
- expect(instrumentsContributionSummary[constants.TOTALS].amortizationSchedule.length).toBe(300);
74
- // period 28
75
- expect(instrumentsContributionSummary[inst1.id].amortizationSchedule[27].period).toBe(28);
76
- expect(instrumentsContributionSummary[inst1.id].amortizationSchedule[27].contribution).toBeCloseTo(541.666666, 5);
77
- expect(instrumentsContributionSummary[inst1.id].amortizationSchedule[27].growth).toBeCloseTo(268.604841, 5);
78
- expect(instrumentsContributionSummary[inst1.id].amortizationSchedule[27].currentBalance).toBeCloseTo(30112.617826, 5);
79
- expect(instrumentsContributionSummary[inst2.id].amortizationSchedule[27].period).toBe(28);
80
- expect(instrumentsContributionSummary[inst2.id].amortizationSchedule[27].contribution).toBeCloseTo(1708.333333, 5);
81
- expect(instrumentsContributionSummary[inst2.id].amortizationSchedule[27].growth).toBeCloseTo(744.328300, 5);
82
- expect(instrumentsContributionSummary[inst2.id].amortizationSchedule[27].currentBalance).toBeCloseTo(107534.304119, 5);
83
- // correct below given current code
84
- // but need to write ways to default/spread a single contribution across instruments
85
- expect(instrumentsContributionSummary[inst3.id].amortizationSchedule[27].period).toBe(28);
86
- expect(instrumentsContributionSummary[inst3.id].amortizationSchedule[27].contribution).toBe(0);
87
- expect(instrumentsContributionSummary[inst3.id].amortizationSchedule[27].growth).toBe(0);
88
- expect(instrumentsContributionSummary[inst3.id].amortizationSchedule[27].currentBalance).toBe(0);
89
- expect(instrumentsContributionSummary[constants.TOTALS].amortizationSchedule[27].period).toBe(28);
90
- expect(instrumentsContributionSummary[constants.TOTALS].amortizationSchedule[27].contribution).toBe(2250);
91
- expect(instrumentsContributionSummary[constants.TOTALS].amortizationSchedule[27].growth).toBeCloseTo(1012.933142, 5);
92
- expect(instrumentsContributionSummary[constants.TOTALS].amortizationSchedule[27].currentBalance).toBeCloseTo(137646.921945, 5);
93
- // period 272
94
- expect(instrumentsContributionSummary[inst1.id].amortizationSchedule[271].period).toBe(272);
95
- expect(instrumentsContributionSummary[inst1.id].amortizationSchedule[271].contribution).toBeCloseTo(541.666666, 5);
96
- expect(instrumentsContributionSummary[inst1.id].amortizationSchedule[271].growth).toBeCloseTo(6967.253017, 5);
97
- expect(instrumentsContributionSummary[inst1.id].amortizationSchedule[271].currentBalance).toBeCloseTo(767572.885191, 5);
98
- expect(instrumentsContributionSummary[inst2.id].amortizationSchedule[271].period).toBe(272);
99
- expect(instrumentsContributionSummary[inst2.id].amortizationSchedule[271].contribution).toBeCloseTo(1708.333333, 5);
100
- expect(instrumentsContributionSummary[inst2.id].amortizationSchedule[271].growth).toBeCloseTo(12019.353385, 5);
101
- expect(instrumentsContributionSummary[inst2.id].amortizationSchedule[271].currentBalance).toBeCloseTo(1710577.576386, 5);
102
- // correct below given current code
103
- // but need to write ways to default/spread a single contribution across instruments
104
- expect(instrumentsContributionSummary[inst3.id].amortizationSchedule[271].period).toBe(272);
105
- expect(instrumentsContributionSummary[inst3.id].amortizationSchedule[271].contribution).toBe(0);
106
- expect(instrumentsContributionSummary[inst3.id].amortizationSchedule[271].growth).toBe(0);
107
- expect(instrumentsContributionSummary[inst3.id].amortizationSchedule[271].currentBalance).toBe(0);
108
- expect(instrumentsContributionSummary[constants.TOTALS].amortizationSchedule[271].period).toBe(272);
109
- expect(instrumentsContributionSummary[constants.TOTALS].amortizationSchedule[271].contribution).toBe(2250);
110
- expect(instrumentsContributionSummary[constants.TOTALS].amortizationSchedule[271].growth).toBeCloseTo(18986.606402, 5);
111
- expect(instrumentsContributionSummary[constants.TOTALS].amortizationSchedule[271].currentBalance).toBeCloseTo(2478150.461577, 5);
112
- }));
113
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=instrument.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"instrument.test.d.ts","sourceRoot":"","sources":["../../../tests/investment/instrument.test.ts"],"names":[],"mappings":""}
@@ -1,57 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { describe, expect, it } from 'vitest';
11
- import { Instrument } from '@/lib/investment/instrument';
12
- const Instruments = () => [
13
- new Instrument(10000, 0.11, 12, 'IRA', 6500),
14
- new Instrument(45000, 0.085, 12, '401(K)', 23500),
15
- new Instrument(0, 0.042666667, 12, 'ABC'),
16
- ];
17
- describe('instrument module', () => {
18
- const [inst1, inst2, inst3] = Instruments();
19
- it('creates an Instrument with proper attributes', () => __awaiter(void 0, void 0, void 0, function* () {
20
- expect(inst1.name).toBe('IRA');
21
- expect(inst1.currentBalance).toBe(10000);
22
- expect(inst1.annualRate).toBe(0.11);
23
- expect(inst1.periodicRate).toBeCloseTo(0.009166, 5);
24
- expect(inst1.periodicContribution()).toBeCloseTo(541.666666, 5);
25
- expect(inst1.annualLimit).toBe(6500);
26
- }));
27
- it('defaults attributes appropriately', () => __awaiter(void 0, void 0, void 0, function* () {
28
- expect(inst3.annualLimit).toBe(0);
29
- expect(inst3.periodicContribution()).toBe(0);
30
- }));
31
- it('validates contributions', () => __awaiter(void 0, void 0, void 0, function* () {
32
- const negativeContribution = -177;
33
- expect(inst2.validateContribution(2000, 22400)).toBe(1100);
34
- expect(inst3.validateContribution(2000, 22400)).toBe(2000);
35
- expect(inst2.validateContribution(2000, 24400)).toBe(0);
36
- expect(() => inst1.validateContribution(negativeContribution, 2000)).toThrow(`contribution of ${negativeContribution} must be greater than/equal to zero`);
37
- }));
38
- it('accrues interest', () => __awaiter(void 0, void 0, void 0, function* () {
39
- expect(inst2.accrueInterest()).toBe(318.75);
40
- expect(inst2.accrueInterest(1000)).toBeCloseTo(7.083333, 5);
41
- expect(inst3.accrueInterest()).toBe(0);
42
- expect(inst3.accrueInterest(200)).toBeCloseTo(0.711111, 5);
43
- }));
44
- describe('instrument module - drawdown methods', () => {
45
- const testInstrument = new Instrument(10000, 0.06, 12, 'Test Acc');
46
- it('calculates periods to zero (numWithdrawalsToZero)', () => {
47
- // Covers instrument.ts lines 87-95
48
- const periods = testInstrument.numWithdrawalsToZero(500);
49
- expect(periods).toBe(22);
50
- });
51
- it('calculates maximum sustainable withdrawal (calculateMaxWithdrawal)', () => {
52
- // Covers instrument.ts lines 105-113
53
- const maxWithdrawal = testInstrument.calculateMaxWithdrawal(12);
54
- expect(maxWithdrawal).toBeCloseTo(860.66, 2);
55
- });
56
- });
57
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=strategies.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"strategies.test.d.ts","sourceRoot":"","sources":["../../../tests/investment/strategies.test.ts"],"names":[],"mappings":""}
@@ -1,15 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { Instrument } from '@/lib/investment/instrument';
3
- import { performWaterfallDrawdown } from '@/lib/investment/strategies';
4
- import * as constants from '@/lib/constants';
5
- describe('strategies module', () => {
6
- it('executes a waterfall drawdown and handles depletion', () => {
7
- const smallAccount = new Instrument(1000, 0.05, 12, 'Small');
8
- const largeAccount = new Instrument(100000, 0.05, 12, 'Large');
9
- // Request more than Small has in one period
10
- const results = performWaterfallDrawdown([smallAccount, largeAccount], 5000, 1, 0);
11
- expect(results[smallAccount.id].amortizationSchedule[0].currentBalance).toBe(0);
12
- expect(results[largeAccount.id].amortizationSchedule[0].withdrawal).toBeGreaterThan(0);
13
- expect(results[constants.TOTALS].lifetimeWithdrawal).toBe(5000);
14
- });
15
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=withdrawals.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"withdrawals.test.d.ts","sourceRoot":"","sources":["../../../tests/investment/withdrawals.test.ts"],"names":[],"mappings":""}
@@ -1,66 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { describe, expect, it } from 'vitest';
11
- import * as constants from '@/lib/constants';
12
- import { Instrument } from '@/lib/investment/instrument';
13
- import { calculateAmortizedWithdrawal, drawdownInstruments } from '@/lib/investment/withdrawals';
14
- const Instruments = () => [
15
- new Instrument(50000, 0.06, 12, 'Taxable Account'),
16
- new Instrument(100000, 0.08, 12, 'IRA Account'),
17
- ];
18
- describe('withdrawals module', () => {
19
- const [taxableAccount, iraAccount] = Instruments();
20
- it('calculates a single period amortized withdrawal (Accrue Before)', () => __awaiter(void 0, void 0, void 0, function* () {
21
- const record = calculateAmortizedWithdrawal(taxableAccount, 50000, 2000, 0, 0.15, true);
22
- // 50,000 * (0.06/12) = 250 growth
23
- // 50,250 - 2000 withdrawal = 48,250
24
- expect(record.growth).toBe(250);
25
- expect(record.currentBalance).toBe(48250);
26
- expect(record.netAmount).toBe(2000 * 0.85);
27
- }));
28
- it('calculates a single period amortized withdrawal (Withdraw Before)', () => __awaiter(void 0, void 0, void 0, function* () {
29
- // This covers withdrawals.ts lines 51-63
30
- const record = calculateAmortizedWithdrawal(taxableAccount, 50000, 2000, 0, 0.15, false);
31
- // 50,000 - 2000 = 48,000
32
- // 48,000 * (0.06/12) = 240 growth
33
- // 48,000 + 240 = 48,240
34
- expect(record.growth).toBe(240);
35
- expect(record.currentBalance).toBe(48240);
36
- expect(record.netAmount).toBe(1700);
37
- }));
38
- it('draws down multiple instruments and validates comprehensive schedules', () => __awaiter(void 0, void 0, void 0, function* () {
39
- const targetNetIncome = 3000;
40
- const simulationDuration = 36;
41
- const taxRate = 0.10;
42
- const summary = drawdownInstruments([taxableAccount, iraAccount], targetNetIncome, simulationDuration, taxRate);
43
- // Verify lifetime totals match the sum of individual schedules (style of payments.test.ts)
44
- for (const instrument of [taxableAccount, iraAccount]) {
45
- const computedLifetimeGrowth = summary[instrument.id].amortizationSchedule
46
- .reduce((sum, record) => sum + record.growth, 0);
47
- expect(summary[instrument.id].lifetimeGrowth).toBeCloseTo(computedLifetimeGrowth, 5);
48
- }
49
- // Verify global totals structure
50
- expect(Object.keys(summary).length).toBe(3); // 2 instruments + TOTALS
51
- expect(summary[constants.TOTALS].amortizationSchedule.length).toBe(36);
52
- // Check final period balance
53
- const lastRecord = summary[constants.TOTALS].amortizationSchedule[35];
54
- expect(lastRecord.period).toBe(36);
55
- expect(lastRecord.currentBalance).toBeLessThan(150000);
56
- }));
57
- describe('withdrawals module - validation', () => {
58
- const testAccount = new Instrument(10000, 0.05, 12, 'Test Account');
59
- it('throws a NegativeWithdrawalError when the withdrawal amount is less than zero', () => {
60
- const negativeWithdrawalAmount = -500;
61
- expect(() => {
62
- calculateAmortizedWithdrawal(testAccount, testAccount.currentBalance, negativeWithdrawalAmount, 0, 0.15);
63
- }).toThrow(`withdrawal of ${negativeWithdrawalAmount} must be greater than/equal to zero`);
64
- });
65
- });
66
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=primitives.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"primitives.test.d.ts","sourceRoot":"","sources":["../../../tests/shared/primitives.test.ts"],"names":[],"mappings":""}
@@ -1,76 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import * as sharedFinancialPrimitives from '@/lib/shared/primitives';
3
- /**
4
- * Unit tests for shared financial primitives.
5
- * These tests ensure the core mathematical engine for the library is accurate
6
- * across various interest rates and durations.
7
- */
8
- describe('shared financial primitives', () => {
9
- // Shared test constants for consistency across test cases
10
- const initialPrincipalBalance = 10000;
11
- const annualInterestRate = 0.05;
12
- const periodicInterestRate = annualInterestRate / 12;
13
- const totalLoanPeriods = 120; // 10 years in months
14
- describe('calculatePeriodicAmount (PMT)', () => {
15
- it('should calculate the standard amortization payment correctly', () => {
16
- const calculatedPeriodicAmount = sharedFinancialPrimitives.calculatePeriodicAmount(initialPrincipalBalance, periodicInterestRate, totalLoanPeriods);
17
- // Expected: $10,000 at 5% for 120 periods is ~$106.0655
18
- expect(calculatedPeriodicAmount).toBeCloseTo(106.0655, 4);
19
- });
20
- it('should handle zero percent interest rates via simple division', () => {
21
- const simplePrincipalBalance = 12000;
22
- const zeroInterestRate = 0;
23
- const twelveMonths = 12;
24
- const calculatedPeriodicAmount = sharedFinancialPrimitives.calculatePeriodicAmount(simplePrincipalBalance, zeroInterestRate, twelveMonths);
25
- expect(calculatedPeriodicAmount).toBe(1000);
26
- });
27
- });
28
- describe('calculateBalanceRemaining (FV)', () => {
29
- it('should calculate the correct remaining balance after a specific number of periods', () => {
30
- const fixedPeriodicPayment = 150;
31
- const periodsElapsed = 12;
32
- const remainingBalance = sharedFinancialPrimitives.calculateBalanceRemaining(initialPrincipalBalance, fixedPeriodicPayment, periodicInterestRate, periodsElapsed);
33
- // Corrected math expectation for 1 year of $150 payments at 5%
34
- expect(remainingBalance).toBeCloseTo(8669.7907, 4);
35
- });
36
- it('should return zero if the balance is overpaid within the specified periods', () => {
37
- const smallInitialBalance = 1000;
38
- const largePeriodicPayment = 1200;
39
- const singlePeriod = 1;
40
- const remainingBalance = sharedFinancialPrimitives.calculateBalanceRemaining(smallInitialBalance, largePeriodicPayment, periodicInterestRate, singlePeriod);
41
- expect(remainingBalance).toBe(0);
42
- });
43
- it('should calculate the correct remaining balance for zero percent interest scenarios', () => {
44
- const zeroInterestRate = 0;
45
- const fixedPeriodicPayment = 100;
46
- const fivePeriodsElapsed = 5;
47
- const remainingBalance = sharedFinancialPrimitives.calculateBalanceRemaining(1000, fixedPeriodicPayment, zeroInterestRate, fivePeriodsElapsed);
48
- expect(remainingBalance).toBe(500);
49
- });
50
- });
51
- describe('calculatePeriodsToZero (NPER)', () => {
52
- it('should calculate the total number of periods required to reach a zero balance', () => {
53
- const fixedPeriodicPayment = 200;
54
- const totalPeriodsRequired = sharedFinancialPrimitives.calculatePeriodsToZero(initialPrincipalBalance, fixedPeriodicPayment, periodicInterestRate);
55
- // $10,000 at 5% with $200 payments rounds up to 57 months
56
- expect(totalPeriodsRequired).toBe(57);
57
- });
58
- });
59
- describe('calculateInterestOverPeriods', () => {
60
- it('should calculate the total interest paid during a set duration', () => {
61
- // Using a slightly more precise payment to match amortization curve
62
- const fixedPeriodicPayment = 106.07;
63
- const oneYearInMonths = 12;
64
- const totalInterestPaid = sharedFinancialPrimitives.calculateInterestOverPeriods(initialPrincipalBalance, fixedPeriodicPayment, periodicInterestRate, oneYearInMonths);
65
- // Total interest for the first year should be approximately $482.04
66
- expect(totalInterestPaid).toBeCloseTo(482.04, 2);
67
- });
68
- it('should return zero interest for loans with a zero percent interest rate', () => {
69
- const zeroInterestRate = 0;
70
- const fixedPeriodicPayment = 100;
71
- const fivePeriods = 5;
72
- const totalInterestPaid = sharedFinancialPrimitives.calculateInterestOverPeriods(1000, fixedPeriodicPayment, zeroInterestRate, fivePeriods);
73
- expect(totalInterestPaid).toBe(0);
74
- });
75
- });
76
- });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes