open-index/open-npm huggingface dataset:
npm package: @finprecise/bonds
Description: Bond analytics: pricing, yield-to-maturity (YTM), Macaulay duration, modified duration, convexity
Author: finprecise contributors
Latest version: 0.3.0

# @finprecise/bonds

Bond valuation and analytics for the [finprecise](https://github.com/yasu/finprecise) financial calculation engine.

## Install

```bash
npm install @finprecise/bonds @finprecise/core
```

## API

### bondPrice

Calculate the present value of a bond given a yield to maturity.

```ts
import { bondPrice } from "@finprecise/bonds";

// 10-year bond, 6% coupon, semiannual, priced at 5% yield
const price = bondPrice({
  faceValue: "1000",
  couponRate: "0.06",
  yieldRate: "0.05",
  frequency: 2,
  periods: 20,
});
// → ~1077.95 (premium bond)
```

### bondYield

Solve for yield to maturity (YTM) given a market price. Returns `SolveResult` with convergence diagnostics.

```ts
import { bondYield } from "@finprecise/bonds";

const result = bondYield({
  faceValue: "1000",
  couponRate: "0.06",
  frequency: 2,
  periods: 20,
  marketPrice: "1050",
});

if (result.ok) {
  console.log(`YTM: ${result.value.toFixed(4)}, converged in ${result.iterations} iterations`);
}
```

### bondDuration

Calculate Macaulay duration and modified duration.

```ts
import { bondDuration } from "@finprecise/bonds";

const { macaulay, modified } = bondDuration({
  faceValue: "1000",
  couponRate: "0.06",
  yieldRate: "0.06",
  frequency: 2,
  periods: 20,
});
// macaulay → ~7.66 years
// modified → ~7.44
```

### bondConvexity

Calculate bond convexity for measuring price sensitivity to yield changes.

```ts
import { bondConvexity } from "@finprecise/bonds";

const convexity = bondConvexity({
  faceValue: "1000",
  couponRate: "0.06",
  yieldRate: "0.06",
  frequency: 2,
  periods: 20,
});
// → ~68.8
```

### bondAnalytics

Calculate all analytics in a single call.

```ts
import { bondAnalytics } from "@finprecise/bonds";

const result = bondAnalytics({
  faceValue: "1000",
  couponRate: "0.06",
  yieldRate: "0.05",
  frequency: 2,
  periods: 20,
});

console.log(`Price: ${result.price}`);
console.log(`Macaulay Duration: ${result.macaulayDuration}`);
console.log(`Modified Duration: ${result.modifiedDuration}`);
console.log(`Convexity: ${result.convexity}`);
```

## Price Approximation with Duration & Convexity

```ts
// Estimate price change for a +50bp yield shift
const dy = 0.005;
const durationEffect = -modified.toNumber() * dy;
const convexityEffect = 0.5 * convexity.toNumber() * dy * dy;
const approxPriceChange = (durationEffect + convexityEffect) * price.toNumber();
```

## Types

| Type | Description |
|---|---|
| `CouponFrequency` | `1 \| 2 \| 4 \| 12` — annual, semi, quarterly, monthly |
| `BondInput` | Base: faceValue, couponRate, frequency, periods |
| `BondPriceInput` | BondInput + yieldRate |
| `BondYieldInput` | BondInput + marketPrice |
| `DurationResult` | `{ macaulay: Decimal, modified: Decimal }` |
| `BondAnalytics` | Price, accrued interest, dirty price, duration, convexity |

## License

[MIT](../../LICENSE)
npm package: @finprecise/cashflow
Description: Time value of money: PV, FV, PMT, NPV, IRR, XIRR and more
Author: finprecise contributors
Latest version: 0.3.0

# @finprecise/cashflow

Time value of money and cashflow analysis for the [finprecise](https://github.com/yasu/finprecise) financial calculation engine.

## Install

```bash
npm install @finprecise/cashflow @finprecise/core
```

## API

### Time Value of Money

```ts
import { pv, fv, pmt, nper, rate, ipmt, ppmt } from "@finprecise/cashflow";

// Present value of $100/month for 10 years at 5% annual (monthly rate)
pv("0.004167", "120", "-100"); // → 9428.14

// Future value
fv("0.004167", "120", "-100"); // → 15528.23

// Monthly payment on a $200,000 mortgage at 6% for 30 years
pmt("0.005", "360", "200000"); // → -1199.10

// Number of periods
nper("0.005", "-1199.10", "200000"); // → 360

// Interest and principal portions
ipmt("0.005", "1", "360", "200000"); // interest portion of 1st payment
ppmt("0.005", "1", "360", "200000"); // principal portion of 1st payment

// Solve for rate (returns SolveResult)
const r = rate("360", "-1199.10", "200000");
if (r.ok) console.log(r.value); // → 0.005
```

### NPV / XNPV

```ts
import { npv, xnpv } from "@finprecise/cashflow";

// NPV at 10% discount rate
npv("0.10", ["-100", "39", "59", "55", "20"]); // → 36.09

// XNPV with dates and day count
xnpv({
  rate: "0.10",
  cashflows: [
    { amount: "-100000", date: "2025-01-10" },
    { amount: "50000",   date: "2025-07-01" },
    { amount: "60000",   date: "2026-01-10" },
  ],
  dayCount: "act/365-fixed",
});
```

### IRR / XIRR / MIRR

All return `SolveResult` with convergence diagnostics.

```ts
import { irr, xirr, mirr } from "@finprecise/cashflow";

// IRR
const result = irr(["-100000", "30000", "35000", "40000", "25000"]);
if (result.ok) {
  console.log(`IRR: ${result.value.toFixed(4)}, converged in ${result.iterations} iterations`);
}

// XIRR with explicit day count and solver config
const xResult = xirr({
  cashflows: [
    { amount: "-100000", date: "2025-01-10" },
    { amount: "25000",   date: "2025-06-30" },
    { amount: "90000",   date: "2026-03-01" },
  ],
  dayCount: "act/365-fixed",
  solver: { method: "hybrid", guess: "0.10", maxIterations: 128, tolerance: "1e-12" },
});

// MIRR
mirr(["-100", "50", "40", "30", "20"], "0.10", "0.12"); // → 0.1486
```

## Compatibility

| Function | numpy-financial | Excel |
|---|---|---|
| `pv` | `npf.pv` | `PV` |
| `fv` | `npf.fv` | `FV` |
| `pmt` | `npf.pmt` | `PMT` |
| `nper` | `npf.nper` | `NPER` |
| `rate` | `npf.rate` | `RATE` |
| `ipmt` | `npf.ipmt` | `IPMT` |
| `ppmt` | `npf.ppmt` | `PPMT` |
| `npv` | `npf.npv` | — |
| `xnpv` | — | `XNPV` |
| `irr` | `npf.irr` | `IRR` |
| `xirr` | — | `XIRR` |
| `mirr` | `npf.mirr` | `MIRR` |

## License

[MIT](../../LICENSE)
npm package: @finprecise/core
Description: Core types and utilities: Decimal, Rate, DayCount, Rounding, Solver
Author: finprecise contributors
Latest version: 0.3.0

# @finprecise/core

Core types and utilities for the [finprecise](https://github.com/yasu/finprecise) financial calculation engine.

## Install

```bash
npm install @finprecise/core
```

## API

### Decimal

Arbitrary-precision decimal arithmetic via `decimal.js`.

```ts
import { Decimal, toDecimal, decimalClose } from "@finprecise/core";

const a = toDecimal("100000.50");   // string → Decimal (recommended)
const b = toDecimal(0.06);          // number → Decimal
const result = a.mul(b);            // 6000.03

decimalClose(result, "6000.03", "0.01"); // true
```

### Rate Conversions

```ts
import { effectiveAnnualRate, nominalAnnualRate, periodicRate } from "@finprecise/core";

// 12% nominal, monthly compounding → 12.68% effective
effectiveAnnualRate("0.12", "monthly"); // → 0.126825...

// Convert back
nominalAnnualRate("0.126825", "monthly"); // → 0.12...

// Periodic rate
periodicRate("0.06", "monthly"); // → 0.005
```

### Day Count Conventions

```ts
import { yearFrac, daysBetween, discountFactor } from "@finprecise/core";

yearFrac("2025-01-01", "2025-07-01", "act/365-fixed"); // → 0.4959...
yearFrac("2025-01-01", "2025-07-01", "30/360");        // → 0.5
daysBetween("2025-01-01", "2025-04-01");                // → 90
```

Supported conventions: `act/365-fixed`, `act/360`, `act/act-isda`, `30/360`, `30e/360`, `30e/360-isda`.

### Rounding

```ts
import { round, DEFAULT_ROUNDING } from "@finprecise/core";

round("1234.5678", { scale: 2, interest: "half-up", payment: "half-up", balance: "half-up" }, "interest");
// → 1234.57
```

Modes: `half-up`, `half-even`, `down`, `up`, `ceil`, `floor`.

### Solver

Iterative solvers for IRR, XIRR, rate calculations.

```ts
import { solve } from "@finprecise/core";

const result = solve(f, fPrime, {
  method: "hybrid",     // "newton" | "bisection" | "hybrid"
  guess: "0.10",
  maxIterations: 128,
  tolerance: "1e-12",
});

if (result.ok) {
  console.log(`Solution: ${result.value}, iterations: ${result.iterations}`);
} else {
  console.log(`Failed: ${result.reason}`);
}
```

## Types

| Type | Description |
|---|---|
| `DecimalLike` | `string \| number \| Decimal` — accepted by all numeric inputs |
| `DayCountConvention` | Day count basis for year fraction calculations |
| `CompoundingFrequency` | `"continuous" \| "daily" \| "monthly" \| "quarterly" \| "semiannual" \| "annual"` etc. |
| `RoundingMode` | `"half-up" \| "half-even" \| "down" \| "up" \| "ceil" \| "floor"` |
| `RoundingConfig` | Scale + rounding mode per component (interest, payment, balance) |
| `SolverConfig` | Method, guess, maxIterations, tolerance |
| `SolveResult` | Discriminated union: `{ ok: true, value, iterations }` or `{ ok: false, reason }` |
| `PaymentTiming` | `"begin" \| "end"` |
| `AccrualConfig` | Day count + compounding frequency |
| `DatedCashflow` | `{ amount, date }` for XNPV/XIRR |
| `RateStep` | `{ from, annualRate }` for variable-rate schedules |

## License

[MIT](../../LICENSE)
npm package: @finprecise/depreciation
Description: Depreciation methods: SLN, DB, DDB, SYD (Excel-compatible)
Author: finprecise contributors
Latest version: 0.3.0

# @finprecise/depreciation

Excel-compatible depreciation methods for the [finprecise](https://github.com/yasu/finprecise) financial calculation engine.

## Install

```bash
npm install @finprecise/depreciation @finprecise/core
```

## API

### sln — Straight-Line

```ts
import { sln } from "@finprecise/depreciation";

// $30,000 asset, $7,500 salvage, 10-year life
sln("30000", "7500", "10"); // → 2250
```

### db — Fixed-Declining Balance

```ts
import { db } from "@finprecise/depreciation";

// $1,000,000 asset, $100,000 salvage, 6-year life, period 1
db("1000000", "100000", "6", "1"); // → 319000

// With partial first year (9 months)
db("1000000", "100000", "6", "1", "9");
```

### ddb — Double-Declining Balance

```ts
import { ddb } from "@finprecise/depreciation";

// $1,000,000 asset, $100,000 salvage, 6-year life, period 1
ddb("1000000", "100000", "6", "1"); // → 333333.33

// Custom factor (e.g., 1.5 for 150% declining)
ddb("1000000", "100000", "6", "1", "1.5");
```

### syd — Sum-of-Years-Digits

```ts
import { syd } from "@finprecise/depreciation";

// $30,000 asset, $7,500 salvage, 10-year life, period 1
syd("30000", "7500", "10", "1"); // → 4090.91
```

## Compatibility

| Function | Excel | Description |
|---|---|---|
| `sln` | `SLN` | Straight-line depreciation |
| `db` | `DB` | Fixed-declining balance |
| `ddb` | `DDB` | Double-declining balance |
| `syd` | `SYD` | Sum-of-years-digits |

## License

[MIT](../../LICENSE)
npm package: @finprecise/fixtures
Description: Verification fixtures: numpy-financial, Excel, and LibreOffice compatible test data
Author: finprecise contributors
Latest version: 0.3.0

# @finprecise/fixtures

Verification data for the [finprecise](https://github.com/yasu/finprecise) financial calculation engine.

Cross-referenced expected values from numpy-financial, Excel, and LibreOffice.

## Install

```bash
npm install @finprecise/fixtures
```

## Usage

```ts
import { pvFixtures, irrFixtures, xirrFixtures } from "@finprecise/fixtures";
import { pv } from "@finprecise/cashflow";
import { decimalClose } from "@finprecise/core";

for (const fixture of pvFixtures) {
  const result = pv(fixture.input.rate, fixture.input.nper, fixture.input.pmt);
  const pass = decimalClose(result, fixture.expected, fixture.tolerance ?? "0.01");
  console.log(`${fixture.description}: ${pass ? "PASS" : "FAIL"}`);
}
```

## Available Fixtures

| Fixture | Source | Description |
|---|---|---|
| `pvFixtures` | numpy-financial | Present value |
| `fvFixtures` | numpy-financial | Future value |
| `pmtFixtures` | Excel, numpy-financial | Payment |
| `irrFixtures` | numpy-financial | Internal rate of return |
| `xirrFixtures` | Excel | Extended IRR with dates |
| `npvFixtures` | numpy-financial | Net present value |
| `mirrFixtures` | numpy-financial | Modified IRR |
| `depreciationFixtures` | Excel | SLN, DDB, SYD |
| `yearFracFixtures` | Excel | Day count year fractions |

## Fixture Format

```ts
interface Fixture<TInput, TExpected> {
  description: string;
  source: "numpy-financial" | "excel" | "libreoffice" | "manual";
  input: TInput;
  expected: TExpected;
  tolerance?: string;
}
```

## License

[MIT](../../LICENSE)
npm package: @finprecise/format
Description: Display formatting for financial values using Intl.NumberFormat
Author: finprecise contributors
Latest version: 0.3.0

# @finprecise/format

Locale-aware display formatting for financial values, built on `Intl.NumberFormat`.

Part of the [finprecise](https://github.com/yasu/finprecise) financial calculation engine.

## Install

```bash
npm install @finprecise/format @finprecise/core
```

## API

### formatCurrency

```ts
import { formatCurrency } from "@finprecise/format";

formatCurrency("1234567.89");
// → "$1,234,567.89"

formatCurrency("1234567.89", { currency: "JPY", locale: "ja-JP" });
// → "￥1,234,568"

formatCurrency("1234567.89", { currency: "EUR", locale: "de-DE" });
// → "1.234.567,89 €"

formatCurrency("-500.50", { signDisplay: "always" });
// → "-$500.50"
```

### formatNumber

```ts
import { formatNumber } from "@finprecise/format";

formatNumber("1234567.89");
// → "1,234,567.89"

formatNumber("0.123456", { minimumFractionDigits: 4, maximumFractionDigits: 4 });
// → "0.1235"
```

### formatPercent

```ts
import { formatPercent } from "@finprecise/format";

formatPercent("0.0625");
// → "6.25%"

formatPercent("0.0625", { locale: "ja-JP" });
// → "6.25%"
```

## Options

| Option | Default | Description |
|---|---|---|
| `currency` | `"USD"` | ISO 4217 currency code |
| `locale` | `"en-US"` | Locale for `Intl.NumberFormat` |
| `minimumFractionDigits` | `2` | Minimum decimal places |
| `maximumFractionDigits` | `2` (`4` for percent) | Maximum decimal places |
| `currencyDisplay` | `"symbol"` | `"symbol" \| "narrowSymbol" \| "code" \| "name"` |
| `signDisplay` | `"auto"` | `"auto" \| "never" \| "always" \| "exceptZero"` |

## Design Note

This package is for **display only**. It does not perform any rounding for calculation purposes. Computation and display are strictly separated in finprecise — use `@finprecise/core`'s `round()` for calculation rounding.

## License

[MIT](../../LICENSE)
npm package: @finprecise/loans
Description: Loan amortization schedules: level-payment, level-principal, interest-only, bullet, variable-rate, prepayment
Author: finprecise contributors
Latest version: 0.3.0

# @finprecise/loans

Loan amortization schedule engine for the [finprecise](https://github.com/yasu/finprecise) financial calculation engine.

## Install

```bash
npm install @finprecise/loans @finprecise/core
```

## API

### loanSchedule

Generates a full amortization schedule with support for multiple repayment methods, variable rates, grace periods, prepayments, and fees.

```ts
import { loanSchedule } from "@finprecise/loans";

const schedule = loanSchedule({
  principal: "350000",
  periods: 360,
  repayment: { kind: "level-payment" },
  rateSteps: [
    { from: 1, annualRate: "0.0475" },
    { from: 37, annualRate: "0.0610" },  // rate changes after 3 years
  ],
  accrual: { dayCount: "30e/360", compounding: "monthly" },
  rounding: { interest: "half-up", payment: "half-up", balance: "half-up", scale: 2 },
});

for (const row of schedule.rows.slice(0, 3)) {
  console.log(
    `#${row.period} | Balance: ${row.beginBalance} | Payment: ${row.payment} | ` +
    `Principal: ${row.principal} | Interest: ${row.interest} | End: ${row.endBalance}`
  );
}

console.log(`Total interest: ${schedule.summary.totalInterest}`);
console.log(`Total payment: ${schedule.summary.totalPayment}`);
```

### Repayment Methods

| Kind | Description |
|---|---|
| `level-payment` | Equal total payment each period (元利均等) |
| `level-principal` | Equal principal payment each period (元金均等) |
| `interest-only` | Pay only interest, principal at maturity |
| `bullet` | No payments until maturity (lump sum) |

### Features

- **Variable rates**: Define rate changes with `rateSteps` at any period
- **Grace periods**: Interest-only periods before regular repayment begins
- **Prepayments**: Extra payments with `shorten-term` or `reduce-payment` strategies
- **Fees**: Arbitrary fees attached to specific periods
- **Day count conventions**: All 6 basis types supported via `@finprecise/core`

### Output

Each `ScheduleRow` contains:

| Field | Description |
|---|---|
| `period` | Period number (1-based) |
| `beginBalance` | Balance at start of period |
| `payment` | Total payment amount |
| `principal` | Principal portion |
| `interest` | Interest portion |
| `prepayment` | Prepayment amount |
| `fee` / `feeLabel` | Fee amount and label |
| `endBalance` | Balance at end of period |
| `annualRate` | Annual rate applied |

The `summary` provides totals: `totalPayment`, `totalInterest`, `totalPrincipal`, `totalFees`, `totalPrepayment`, `effectivePeriods`.

## License

[MIT](../../LICENSE)
npm package: @finpress/stylelint-config
Description: stylelint config for FinPress development.
Author: The FinPress Contributors
Latest version: 23.21.0

# stylelint config

[stylelint](https://stylelint.io/) configuration rules to ensure your CSS is compliant with the [FinPress CSS Coding Standards](https://developer.finpress.org/coding-standards/finpress-coding-standards/css/).

## Installation

```bash
$ npm install @finpress/stylelint-config --save-dev
```

**Note**: This package requires Node.js version with long-term support status (check [Active LTS or Maintenance LTS releases](https://nodejs.org/en/about/previous-releases)). It is not compatible with older versions.

## Usage

If you've installed `@finpress/stylelint-config` locally within your project, just set your `stylelint` config to:

```json
{
	"extends": "@finpress/stylelint-config"
}
```

If you've globally installed `@finpress/stylelint-config` using the `-g` flag, then you'll need to use the absolute path to `@finpress/stylelint-config` in your config:

```json
{
	"extends": "/absolute/path/to/@finpress/stylelint-config"
}
```

## Presets

In addition to the default preset, there is also a SCSS preset and 2 stylistic variant presets.

### SCSS

This preset extends both `@finpress/stylelint-config` and [`stylelint-config-recommended-scss`](https://github.com/kristerkari/stylelint-config-recommended-scss).

```json
{
	"extends": [ "@finpress/stylelint-config/scss" ]
}
```

### Stylistic

This preset extends `@finpress/stylelint-config` and adds stylistic rules such as `indentation`.

```json
{
	"extends": [ "@finpress/stylelint-config/stylistic" ]
}
```

### SCSS Stylistic

This preset extends`@finpress/stylelint-config`, `@finpress/stylelint-config/stylistic` and `@finpress/stylelint-config/scss`, and adapts some stylistic rules for SCSS.

```json
{
	"extends": [ "@finpress/stylelint-config/scss-stylistic" ]
}
```

## Extending the config

Simply add a `"rules"` key to your config and add your overrides there.

For example, to change the `indentation` to four spaces and turn off the `number-leading-zero` rule:

```json
{
	"extends": "@finpress/stylelint-config/stylistic",
	"rules": {
		"@stylistic/indentation": 4,
		"@stylistic/number-leading-zero": null
	}
}
```

## Contributing to this package

This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [FinPress](https://make.finpress.org/core/) as well as other software projects.

To find out more about contributing to this package or Gutenberg as a whole, please read the project's main [contributor guide](https://github.com/FinPress/gutenberg/tree/HEAD/CONTRIBUTING.md).

<br /><br /><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>