lmammino/financial
关于
一个零依赖的 TypeScript/JavaScript 金融库(基于 numpy-financial),适用于 Node.js、Deno 和浏览器
商业与金融实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- +1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Financial
A Zero-Dependency TypeScript / JavaScript financial utility library inspired by numpy-financial that can be used on Node.js, Deno, Bun and the browser.
It does support the same functionality offered by numpy-financial but it only supports scalar JavaScript number values (NO numpy-like array values) and it does NOT support arbitrary-precision signed decimal numbers (such as decimal.js, big.js or bignumber.js).
📖 API DOCS 📖 : financialjs.netlify.app
Install
With npm:
npm install --save-dev financial
Or, with yarn:
yarn add financial
Example usage
import { fv } from 'financial'
fv(0.05 / 12, 10 * 12, -100, -100) // 15692.928894335748
Module formats
This library exports its functionality using different module formats.
Commonjs
const financial = require('financial') // ./index.js
// use `financial.fv`, `financial.pmt`, etc.
or, leveraging destructuring
const { fv, pmt } = require('financial') // ./index.js
// use `fv`, `pmt`, etc.
An optimized Commonjs for browsers can be imported directly from the web:
<script src="https://www.npmcdn.com/[email protected]/dist/financial.cjs.production.min.js"></script>
Note: make sure you replace the x.y.z with the correct version you want to use.
ESM (EcmaScript Modules)
Also working with Typescript
import { fv, pmt } from 'financial'
// use `fv`, `pmt`, etc.
There's no default export in the ESM implementation, so you have to explicitely import the functionality you need, one by one.
Use with Deno
Make sure you specify the version you prefer in the import URL:
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'
import * as f from 'https://deno.land/x/npm:[email protected]/src/financial.ts'
assertEquals(f.fv(0.05 / 12, 10 * 12, -100, -100), 15692.928894335755)
Implemented functions and Documentation
Click on the function name to get the full documentation for every function, or check out the full programmatic documentation at financialjs.netlify.app.
-
fv(): Future Value (since v0.0.12) -
pmt(): Total payment (since v0.0.12) -
nper(): Number of period payments (since v0.0.12) -
ipmt(): Interest portion of a payment (since v0.0.12) -
ppmt(): Payment against loan principal (since v0.0.14) -
pv(): Present Value (since v0.0.15) -
rate(): Rate of interest per period (since v0.0.16) -
irr(): Internal Rate of Return (since v0.0.17) -
npv(): Net Present Value (since v0.0.18) -
mirr(): Modified Internal Rate of Return (since 0.1.0)
Local Development
Below is a list of commands you will probably find useful.
npm startoryarn start: Runs the project in development/watch mode. Your project will be rebuilt upon changes.npm run buildoryarn build: Bundles the package to thedistfolder. The package is optimized and bundled with Rollup into multiple format (CommonJS, UMD, and ES Module).npm run build:docsoryarn build:docs: Builds the API documentation in thedocsfolder usingtypedoc.npm testoryarn test: Runs the test watcher (Jest) in an interactive mode. it runs tests related to files changed since the last commit.npm run test:watchoryarn test:watch: runs the tests in watch mode
Test with Deno
To test with Deno, run:
deno test test/deno.ts
Contributing
Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub.
You can also submit PRs as long as you adhere with the code standards and write tests for the proposed changes.
License
Licensed under MIT License. © Luciano Mammino.
探索相关项目
加载中…