{"id":48490432,"url":"https://github.com/netbeen/fund-tools","last_synced_at":"2026-04-07T11:32:22.770Z","repository":{"id":40612740,"uuid":"427666529","full_name":"netbeen/fund-tools","owner":"netbeen","description":"An NPM lib supports the Chinese fund's data fetching, rate of return calculation, and especially annualized rate of return calculation, which is available to Node.js runtime and browsers.","archived":false,"fork":false,"pushed_at":"2023-07-09T08:18:54.000Z","size":5625,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-08-06T19:35:57.490Z","etag":null,"topics":["annualized-rate-of-return","fund","return"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/fund-tools","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/netbeen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-13T13:03:35.000Z","updated_at":"2023-07-07T11:49:08.000Z","dependencies_parsed_at":"2023-02-10T10:15:27.484Z","dependency_job_id":null,"html_url":"https://github.com/netbeen/fund-tools","commit_stats":null,"previous_names":[],"tags_count":3,"template":null,"template_full_name":null,"purl":"pkg:github/netbeen/fund-tools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netbeen%2Ffund-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netbeen%2Ffund-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netbeen%2Ffund-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netbeen%2Ffund-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/netbeen","download_url":"https://codeload.github.com/netbeen/fund-tools/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netbeen%2Ffund-tools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31511613,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T03:10:19.677Z","status":"ssl_error","status_checked_at":"2026-04-07T03:10:13.982Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["annualized-rate-of-return","fund","return"],"created_at":"2026-04-07T11:32:22.075Z","updated_at":"2026-04-07T11:32:22.757Z","avatar_url":"https://github.com/netbeen.png","language":"TypeScript","readme":"## Fund Tools\n\n\u003cdiv\u003e\n    \u003ca href=\"https://unpkg.com/fund-tools/index.min.js\"\u003e\u003cimg src=\"https://img.badgesize.io/https:/unpkg.com/fund-tools/index.min.js?style=flat-square\u0026compression=gzip\" alt=\"Gzip Size\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/package/fund-tools\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/fund-tools.svg?style=flat-square\u0026colorB=51C838\" alt=\"NPM Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://travis-ci.com/iamkun/dayjs\"\u003e\u003cimg src=\"https://img.shields.io/travis/iamkun/dayjs/master.svg?style=flat-square\" alt=\"Build Status\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/netbeen/fund-tools\"\u003e\u003cimg\n            src=\"https://img.shields.io/codecov/c/github/netbeen/fund-tools/master.svg?style=flat-square\" alt=\"Codecov\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/netbeen/fund-tools/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\" alt=\"License\"\u003e\u003c/a\u003e\n    \u003cbr\u003e\n\u003c/div\u003e\n\n\u003e 很多人都会把基金作为一个投资方式或者家庭资产配置的重要品种，却很少有人可以回答得清楚如下的问题：你买的基金收益率如何？年化收益率如何？投资过程中获取的分红有多少？付出的手续费有多少？有没有收益表现更好的同类型基金？\n\u003e\n\u003e 如果无法准确回答出上述问题，基金投资无异于盲人走夜路。\n\n如果你有上述困惑，那就来对地方了，这个库可以完美回答上述问题，帮助你在投资过程中更加客观地评估自身能力，也是基金量化投资系统的核心度量组件。\n\n## Getting Started\n\n### Package\n\nNPM: [https://www.npmjs.com/package/fund-tools](https://www.npmjs.com/package/fund-tools)\n\n### Installation\n\n```shell\nnpm install fund-tools --save\n# OR\nyarn add fund-tools\n```\n\n### Example\n\n```javascript\nimport {\n    fetchUnitPriceByIdentifier,\n    fetchSplitByIdentifier,\n    fetchDividendByIdentifier,\n    calcReturn,\n    OPERATION_DIRECTION_BUY,\n    OPERATION_DIRECTION_SELL\n} from 'fund-tools';\nimport * as dayjs from 'dayjs';\n\n// 以 160119 中证500为例\nconst fundIdentifier = '160119'\n\n// 通过爬虫抓取基金历史数据，包括单位净值、分红、拆分\nconst unitPrices = await fetchUnitPriceByIdentifier(fundIdentifier);\nconst dividends = await fetchDividendByIdentifier(fundIdentifier);\nconst splits = await fetchSplitByIdentifier(fundIdentifier);\n\n// 录入自己的历史交易\nconst operations = [{\n    date: dayjs('2021-06-09'), volume: 2958.54, direction: OPERATION_DIRECTION_BUY, commission: 5.99\n}, {\n    date: dayjs('2021-07-12'), volume: 3378.46, direction: OPERATION_DIRECTION_BUY, commission: 6.54\n}, {\n    date: dayjs('2021-08-09'), volume: 3957.39, direction: OPERATION_DIRECTION_BUY, commission: 7.53\n}, {\n    date: dayjs('2021-11-09'), volume: 3197.19, direction: OPERATION_DIRECTION_SELL, commission: 5.99\n}];\n\nconst calcResult = calcReturn(unitPrices, dividends, splits, operations);\nconsole.log(calcResult);\n/**\n {\n      unitPrice: 1.597, // 当前单位净值\n      unitCost: 1.6110785712273878, // 当前单位净值\n      volume: 13491.58, // 持仓数量\n      totalCommission: 26.050000000000004, // 总显性手续费\n      totalDividend: 0, // 总分红\n      positionReturn: -189.94217000000165,  // 持仓收益\n      positionCost: 21735.995430000003, // 持仓总成本\n      positionValue: 21546.05326,   // 总市值\n      positionRateOfReturn: -0.008738600015430793,  // 持仓收益率\n      exitReturn: 0,    // 落袋收益\n      totalReturn: -189.94217000000165, // 总收益\n      totalAnnualizedRateOfReturn: -0.054593138863008296    // 总年化收益率\n  }\n */\n```\n\n### API Reference\n\n#### fetchBasicInfoByIdentifier\n\n拉取特定基金的基本信息\n\n```javascript\nfunction fetchBasicInfoByIdentifier(\n    identifier: string  // 六位数字格式的基金代码\n): Promise\u003c{\n    identifier: string, // 基金代码回显\n    name: string,       // 基金名称\n    type: string        // 基金类型: 股票型、债券型、商品型、货币型、混合型\n}\u003e;\n```\n\n#### fetchUnitPriceByIdentifier\n\n拉取特定基金的全部交易日的单位净值数据\n\n```javascript\nfunction fetchUnitPriceByIdentifier(\n    identifier: string  // 六位数字格式的基金代码\n): Promise\u003cArray\u003c{\n    date: dayjs.Dayjs,  // 交易日时间戳\n    price: number       // 单位净值 单位:人民币\n}\u003e\u003e;\n```\n\n#### fetchAccumulatedPriceByIdentifier\n\n拉取特定基金的全部交易日的累计净值数据\n\n```javascript\nfunction fetchAccumulatedPriceByIdentifier(\n    identifier: string  // 六位数字格式的基金代码\n): Promise\u003cArray\u003c{\n    date: dayjs.Dayjs,  // 交易日时间戳\n    price: number       // 累计净值 单位:人民币\n}\u003e\u003e;\n```\n\n#### fetchSplitByIdentifier\n\n拉取特定基金的全部交易日的基金拆分数据\n\n```javascript\nfunction fetchAccumulatedPriceByIdentifier(\n    identifier: string  // 六位数字格式的基金代码\n): Promise\u003cArray\u003c{\n    date: dayjs.Dayjs,  // 交易日时间戳\n    splitRatio: number  // 拆分比例，如果是 1 拆 2.4，那么这个值就是 2.4\n}\u003e\u003e;\n```\n\n#### fetchSplitByIdentifier\n\n拉取特定基金的全部交易日的基金分红数据\n\n```javascript\nfunction fetchDividendByIdentifier(\n    identifier: string  // 六位数字格式的基金代码\n): Promise\u003cArray\u003c{\n    date: dayjs.Dayjs,  // 交易日时间戳\n    dividend: number    // 每份基金分红，如果是每份分红 0.024 元，那么这个值就是 0.024 单位:人民币\n}\u003e\u003e;\n```\n\n#### calcReturn\n\n计算投资回报率\n\n```javascript\nfunction calcReturn(\n    unitPrices: Array\u003c{date: dayjs.Dayjs, price: number}\u003e,      // 同单位净值的接口返回格式\n    dividends: Array\u003c{date: dayjs.Dayjs, dividend: number}\u003e,    // 同基金分红的接口返回格式\n    splits: Array\u003c{date: dayjs.Dayjs, splitRatio: number}\u003e,     // 同基金拆分的接口返回格式\n    operations: Array\u003c{             // 交易记录\n        date: Date,                 // 交易日时间戳\n        volume: number,             // 成交量\n        commission: number,         // 手续费/佣金\n        direction: 'BUY'|'SELL'     // 方向：买入/卖出\n    }\u003e\n): Promise\u003c{\n    unitPrice: number,              // 单位净值\n    unitCost: number,               // 单位成本\n    volume: number,                 // 持仓数量\n    totalCommission: number,        // 总显性手续费（仅计算申购费和赎回费，不计算银行托管费、基金管理费）\n    totalDividend: number,          // 总分红\n    positionReturn: number,         // 持仓收益\n    positionCost: number,           // 持仓成本\n    positionValue: number,          // 总市值\n    positionRateOfReturn: number,   // 持仓收益率\n    exitReturn: number,             // 已落袋收益\n    totalReturn: number,            // 总收益\n    totalAnnualizedRateOfReturn: number     // 年化收益率\n}\u003e;\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetbeen%2Ffund-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetbeen%2Ffund-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetbeen%2Ffund-tools/lists"}