@pyverret/ratejs 1.0.0 → 1.1.0

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/README.md CHANGED
@@ -8,10 +8,61 @@ Lightweight, dependency-free TypeScript financial math library providing pure ca
8
8
  npm i @pyverret/ratejs
9
9
  ```
10
10
 
11
+ ## Live Demo
12
+
13
+ - GitHub Pages URL: `https://pyverret.github.io/ratejs/`
14
+ - Demo source: [`demo/`](./demo)
15
+
16
+ Run locally:
17
+
18
+ ```bash
19
+ cd demo
20
+ npm install
21
+ npm run dev
22
+ ```
23
+
11
24
  ## Usage
12
25
 
13
26
  All functions take a single options object (no positional args). Rates are decimals (e.g. `0.05` = 5%).
14
27
 
28
+ Cash-flow sign convention (Excel-style):
29
+ - Cash paid out is negative, cash received is positive.
30
+ - Loan example: `presentValue > 0` and `payment < 0`.
31
+ - Investment withdrawal example: `presentValue < 0` and `payment > 0`.
32
+
33
+ ### Excel-style TVM formulas
34
+
35
+ - **`pmt`** - Excel `PMT`: payment per period for a loan/investment.
36
+ - **`pv`** - Excel `PV`: present value from payment stream and future value.
37
+ - **`fv`** - Excel `FV`: future value from present value and payment stream.
38
+ - **`nper`** - Excel `NPER`: number of periods required.
39
+ - **`rate`** - Excel `RATE`: implied rate per period. Supports optional `guess`, `maxIterations`, `lowerBound`, and `upperBound`.
40
+ - **`npv`** - Excel `NPV`: net present value of a cash flow series.
41
+
42
+ ```ts
43
+ const payment = pmt({
44
+ ratePerPeriod: 0.06 / 12,
45
+ periods: 360,
46
+ presentValue: 250000,
47
+ futureValue: 0,
48
+ timing: "end",
49
+ });
50
+
51
+ const impliedRate = rate({
52
+ periods: 360,
53
+ payment,
54
+ presentValue: 250000,
55
+ futureValue: 0,
56
+ timing: "end",
57
+ lowerBound: -0.99, // optional
58
+ upperBound: 10, // optional
59
+ });
60
+ ```
61
+
62
+ Edge cases:
63
+ - `nper` throws `RangeError` when `ratePerPeriod <= -1`.
64
+ - `rate` throws `RangeError` when no root is found within search bounds.
65
+
15
66
  ### Interest & growth
16
67
 
17
68
  - **`compound`** - Final amount for a lump sum with compound interest.
@@ -95,12 +146,23 @@ ruleOf72({ rate: 0.07, constant: 69 });
95
146
  cagr({ startValue: 1000, endValue: 2000, years: 10 });
96
147
  ```
97
148
 
98
- - **`irr`** - Internal rate of return: discount rate that makes NPV of cash flows zero. `cashFlows[0]` is typically the initial outlay (negative).
149
+ - **`irr`** - Internal rate of return: discount rate that makes NPV of cash flows zero. `cashFlows[0]` is typically the initial outlay (negative). Supports optional `guess`, `maxIterations`, `lowerBound`, and `upperBound`.
99
150
 
100
151
  ```ts
101
- irr({ cashFlows: [-1000, 300, 400, 500], guess: 0.1, maxIterations: 100 });
152
+ irr({
153
+ cashFlows: [-1000, 300, 400, 500],
154
+ guess: 0.1,
155
+ maxIterations: 100,
156
+ lowerBound: -0.99, // optional
157
+ upperBound: 10, // optional
158
+ });
102
159
  ```
103
160
 
161
+ Edge cases:
162
+ - Throws `RangeError` when `cashFlows` is empty.
163
+ - Throws `RangeError` when `cashFlows` does not contain at least one positive and one negative value.
164
+ - Throws `RangeError` when no root is found within search bounds.
165
+
104
166
  ### Inflation
105
167
 
106
168
  - **`realReturn`** - Real (inflation-adjusted) return from nominal return and inflation rate.