Skip to content

Commit 38c8c98

Browse files
feat: add finance module (TVM + bonds) [3.1.0]
Phase 1 of multi-phase expansion. Adds Excel-compatible TVM functions and bond analytics with full test coverage. - TVM: fv, pv, pmt, nper, ipmt, ppmt, rate, npv, irr, mirr, cagr, compoundInterest, discountFactor, amortizationSchedule - Bonds: cleanPrice, dirtyPrice, accruedInterest, yieldToMaturity, macaulay/modified duration, convexity, dv01, priceChangeApprox - 24 new tests (90 total passing) - docs/FINANCE.md - Cleanup: drop test-install/, pnpm-lock.yaml - Ship CHANGELOG.md to npm bundle
1 parent 56a0eb4 commit 38c8c98

11 files changed

Lines changed: 763 additions & 4134 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ docs/.vitepress/dist/
6767

6868
# Release files
6969
release-instructions.md
70+
.claude-memory/

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [3.1.0] - 2026-05-02
9+
10+
### Added
11+
- **Finance module (`src/finance/`)** with TVM and bond analytics.
12+
- **TVM functions** (Excel-compatible): `fv`, `pv`, `pmt`, `nper`, `ipmt`, `ppmt`, `rate`, `npv`, `irr`, `mirr`, `cagr`, `compoundInterest`, `discountFactor`, `amortizationSchedule`.
13+
- **Bond pricing**: `cleanPrice`, `dirtyPrice`, `accruedInterest`, `yieldToMaturity`, `macaulayDuration`, `modifiedDuration`, `convexity`, `dv01`, `priceChangeApprox`.
14+
- 24 new tests (90 total passing).
15+
- `docs/FINANCE.md` reference.
16+
17+
### Removed
18+
- Stale `test-install/` directory.
19+
- Duplicate `pnpm-lock.yaml` (kept `package-lock.json`).
20+
21+
### Notes
22+
This is **Phase 1** of a multi-phase expansion. Subsequent minor releases will add: Black-Scholes + stochastic models (3.2), yield curves + credit (3.3), risk/vol upgrade (3.4), execution algos + microstructure (3.5), HRP/Kelly/factor models (3.6), candlestick patterns + advanced indicators (3.7), ML + regime detection (3.8), Deno/Bun/UMD targets (3.9).
23+
824
## [3.0.0] - 2026-04-21
925

1026
### Added

docs/FINANCE.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Finance Module
2+
3+
Time Value of Money (TVM) and Bond analytics. Spreadsheet-compatible signatures (Excel/Google Sheets parity).
4+
5+
## Sign Convention
6+
7+
Cash inflows positive, outflows negative. Matches Excel.
8+
9+
## TVM Functions
10+
11+
```ts
12+
import {
13+
fv, pv, pmt, nper, ipmt, ppmt, rate,
14+
npv, irr, mirr,
15+
cagr, compoundInterest, discountFactor,
16+
amortizationSchedule,
17+
} from 'meridianalgo';
18+
```
19+
20+
### Core
21+
22+
| Function | Purpose |
23+
|----------|---------|
24+
| `fv(rate, nper, pmt?, pv?, when?)` | Future value |
25+
| `pv(rate, nper, pmt?, fv?, when?)` | Present value |
26+
| `pmt(rate, nper, pv, fv?, when?)` | Periodic payment |
27+
| `nper(rate, pmt, pv, fv?, when?)` | Number of periods |
28+
| `ipmt(rate, per, nper, pv, fv?, when?)` | Interest portion of period payment |
29+
| `ppmt(rate, per, nper, pv, fv?, when?)` | Principal portion |
30+
| `rate(nper, pmt, pv, fv?, when?, guess?)` | Solve interest rate (Newton-Raphson) |
31+
32+
`when`: `0` = end of period (default), `1` = beginning (annuity due).
33+
34+
### Cash Flow Analysis
35+
36+
| Function | Purpose |
37+
|----------|---------|
38+
| `npv(rate, cashflows[])` | Net Present Value (cf[0] at t=0) |
39+
| `irr(cashflows[], guess?)` | Internal Rate of Return |
40+
| `mirr(cashflows[], financeRate, reinvestRate)` | Modified IRR |
41+
42+
### Helpers
43+
44+
- `cagr(begin, end, years)` — Compound Annual Growth Rate
45+
- `compoundInterest(principal, rate, periods, compoundsPerPeriod?)`
46+
- `discountFactor(rate, t)`
47+
- `amortizationSchedule(principal, ratePerPeriod, nper, when?)` — full per-period schedule
48+
49+
### Examples
50+
51+
```ts
52+
// 30-year mortgage, $200k @ 6%
53+
const monthlyPayment = pmt(0.06 / 12, 360, 200000);
54+
// → -1199.10
55+
56+
// Project IRR
57+
const r = irr([-1000, 300, 400, 500, 600]);
58+
// → ~0.1487
59+
60+
// 7-year CAGR
61+
cagr(1000, 2000, 7);
62+
// → 0.10409
63+
```
64+
65+
## Bonds
66+
67+
```ts
68+
import {
69+
cleanPrice, dirtyPrice, accruedInterest, yieldToMaturity,
70+
macaulayDuration, modifiedDuration, convexity, dv01,
71+
priceChangeApprox,
72+
} from 'meridianalgo';
73+
```
74+
75+
`BondParams = { face, couponRate, ytm, yearsToMaturity, frequency? }` — frequency defaults to 2 (semi-annual).
76+
77+
| Function | Returns |
78+
|----------|---------|
79+
| `cleanPrice(params)` | Flat price |
80+
| `dirtyPrice(params, daysSinceLastCoupon, daysInPeriod)` | Invoice price (clean + AI) |
81+
| `accruedInterest(face, couponRate, freq, daysSince, daysInPeriod)` | Accrued coupon |
82+
| `yieldToMaturity(price, face, couponRate, years, freq?)` | YTM (bisection) |
83+
| `macaulayDuration(params)` | Macaulay duration (years) |
84+
| `modifiedDuration(params)` | Modified duration |
85+
| `convexity(params)` | Convexity |
86+
| `dv01(params)` | Price value of 1 bp |
87+
| `priceChangeApprox(params, dy)` | Δprice from duration + convexity |
88+
89+
### Example
90+
91+
```ts
92+
const bond = { face: 1000, couponRate: 0.05, ytm: 0.06, yearsToMaturity: 10, frequency: 2 };
93+
const price = cleanPrice(bond); // 925.61
94+
const ytm = yieldToMaturity(price, 1000, 0.05, 10, 2); // 0.06
95+
const mod = modifiedDuration(bond); // ~7.66
96+
const conv = convexity(bond); // ~74
97+
const bp1 = dv01(bond); // ~0.71
98+
```

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "meridianalgo",
3-
"version": "3.0.0",
3+
"version": "3.1.0",
44
"description": "Professional-grade quantitative finance framework for JavaScript/TypeScript - algorithmic trading, backtesting, risk management, and portfolio optimization",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",
@@ -83,7 +83,8 @@
8383
"files": [
8484
"dist",
8585
"README.md",
86-
"LICENSE"
86+
"LICENSE",
87+
"CHANGELOG.md"
8788
],
8889
"directories": {
8990
"doc": "docs",

0 commit comments

Comments
 (0)