fintech-algorithms
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesefintech-algorithms
fintech-algorithms
324 pure functions for market and financial calculations. Plain arrays and
objects in, plain values out. Zero runtime dependencies, Node >= 22, ESM.
Docs: https://docs.thefintechbuilder.com ·
Authoritative agent guide: https://docs.thefintechbuilder.com/guides/ai-agents/
324个用于市场与金融计算的纯函数。输入为普通数组和对象,输出为普通值。零运行时依赖,支持Node >= 22,采用ESM规范。
Non-negotiables
不可协商规则
Four rules. Breaking any one produces output that looks right and is wrong.
- Never invent an import path, a function name, or a parameter. Every
subpath mirrors its docs URL exactly, which makes a plausible guess wrong in
a way that reads as correct. Look it up — or the resolution order below. If the topic does not exist, say so and stop.
scripts/lookup.mjs - Never guess a returned field name. Return-key casing is not consistent
across the library: returns
bollingerBands,percent_brows returnmacd. Read the captured example output for that topic. SeefastEma.references/pitfalls.md - State the verification tier on any numeric claim. (158 topics) means the arithmetic is replayed and asserted on every build.
verified(166 topics) means the signature and shape are checked but the numbers are not attested by an independent published figure.contract - Analysis, not advice. These functions compute quantities. An indicator crossing is an observation about a series — not a prediction, not a signal, and never a recommendation for a specific person's money. Report what was computed, on what input, at which tier. If asked what to buy or sell, say that is a question for a licensed adviser.
四条规则。违反任何一条都会导致输出看似正确实则错误。
- 切勿自行编造导入路径、函数名或参数。 每个子路径都与文档URL完全对应,这使得合理的猜测也可能产生看似正确的错误结果。请查阅相关内容——可使用或下文的解析顺序。若相关主题不存在,请直接说明并停止操作。
scripts/lookup.mjs - 切勿猜测返回字段名。 库中返回键的大小写并不统一:返回
bollingerBands,percent_b的行返回macd。请查阅对应主题的示例输出。详见fastEma。references/pitfalls.md - 说明数值声明的验证等级。(158个主题)表示算法运算会在每次构建时重放并验证。
verified(166个主题)表示仅检查签名和结构,但数值未经过独立发布数据的验证。contract - 仅做分析,不提供建议。 这些函数仅计算数值。指标交叉只是对序列的观察——并非预测、信号,更绝非针对个人资金的推荐。请报告计算内容、输入数据、验证等级,以及有多少前置值是预热值而非信号值。若被问及买卖建议,请说明该问题需咨询持牌顾问。
The library does not fetch data
本库不获取数据
There is no HTTP client, no vendor SDK, no API key, no . If a task
needs prices, the caller supplies them. This is deliberate: vendor APIs get
rewritten every few years and algorithms do not.
node:fsWhen a user wants "live analysis", the shape is always: their feed → their
adapter → validate → compute → report. Only the middle two steps are this
library. Load for the adapter pattern and the
canonical / shapes.
references/ingestion.mdTradeBar本库无HTTP客户端、无厂商SDK、无API密钥、无模块。若任务需要价格数据,需由调用方提供。这是有意设计的:厂商API每隔几年就会重写,但算法不会。
node:fs当用户需要“实时分析”时,流程始终为:他们的数据源 → 他们的适配器 → 验证 → 计算 → 报告。本库仅负责中间两个步骤。如需了解适配器模式及标准/结构,请查看。
TradeBarreferences/ingestion.mdResolution order
解析顺序
Stop at the first step that answers the question.
- Installed package — if is a dependency, read
fintech-algorithms. Every signature, contract and worked example, no network. Prefer this.node_modules/fintech-algorithms/docs.jsonuses it automatically.scripts/lookup.mjs - Domain index — (3–11 KB each). The map of all thirteen is the
https://docs.thefintechbuilder.com/{domain-slug}/llms.txtblock at the top of## Per-domain indexes; one root fetch gives a permanent routing table./llms.txt - Topic markdown — append to any docs URL. The full contract in 3–11 KB instead of 68–114 KB of HTML.
index.md - Full payload — (~2.6 MB). For ingestion, not for answering one question.
https://docs.thefintechbuilder.com/reference/payload.json
Turn a docs URL into an import: swap for
and drop the trailing slash.
https://docs.thefintechbuilder.com/fintech-algorithms/Check the installed version matches the docs with
(under 1 KB).
https://docs.thefintechbuilder.com/version.json找到第一个能回答问题的步骤即停止。
- 已安装的包 —— 若是依赖项,请读取
fintech-algorithms。包含所有签名、契约和示例,无需网络。优先使用此方式。node_modules/fintech-algorithms/docs.json会自动使用该文件。scripts/lookup.mjs - 领域索引 —— (每个3–11 KB)。所有13个领域的映射表位于
https://docs.thefintechbuilder.com/{domain-slug}/llms.txt顶部的/llms.txt块;一次根请求即可获取永久路由表。## Per-domain indexes - 主题Markdown文档 —— 在任意文档URL后追加。完整契约仅3–11 KB,而非68–114 KB的HTML。
index.md - 完整负载 —— (约2.6 MB)。用于数据导入,而非回答单个问题。
https://docs.thefintechbuilder.com/reference/payload.json
将文档URL转换为导入路径:把替换为并去掉末尾斜杠。
https://docs.thefintechbuilder.com/fintech-algorithms/通过(小于1 KB)检查已安装版本是否与文档匹配。
https://docs.thefintechbuilder.com/version.jsonWorkflow
工作流程
1. Identify the quantity. What is actually being asked for? "Is this
overbought" → RSI. "Smooth this" → which moving average, and why that one.
2. Narrow by archetype before fetching anything. Five input shapes cover all
324 topics, and the archetype is on every index line:
| Archetype | Takes | Returns | Count |
|---|---|---|---|
| | same-length array | 37 |
| | | 7 |
| rows | one verdict per row | 17 |
| one snapshot + decision time | one verdict | 6 |
| domain-specific | domain-specific | 257 |
record-transformreferences/archetypes.md3. Read the contract. Signature, params, returns, warm-up, errors.
bash
node scripts/lookup.mjs show rsi4. Shape the data. Map the user's payload into the documented input. Run the
boundary validator first when the input is bars, ticks or quotes.
5. Compute and report. Say what was computed, on what input, at which tier,
and how many leading values are warm-up rather than signal.
1. 确定计算量。 用户实际需求是什么?“是否超买”→ RSI。“平滑数据”→ 哪种移动平均线,以及选择原因。
2. 在获取任何内容前先按原型缩小范围。 5种输入结构覆盖所有324个主题,每个索引行都标注了原型:
| 原型 | 输入 | 输出 | 数量 |
|---|---|---|---|
| | 等长数组 | 37 |
| | | 7 |
| 行数据 | 每行一个判定结果 | 17 |
| 单个快照 + 决策时间 | 一个判定结果 | 6 |
| 特定领域数据 | 特定领域数据 | 257 |
record-transformreferences/archetypes.md3. 阅读契约。 签名、参数、返回值、预热机制、错误处理。
bash
node scripts/lookup.mjs show rsi4. 整理数据格式。 将用户数据映射为文档规定的输入格式。当输入为K线、tick或报价数据时,先运行边界验证器。
5. 计算并报告。 说明计算内容、输入数据、验证等级,以及有多少前置值是预热值而非信号值。
Quick start
快速开始
bash
npm install fintech-algorithmsAlgorithms are subpath-only. The root export carries metadata and lookups
(, , , , , , ) and
re-exports no algorithm. A sibling topic's function is never re-exported from
another subpath — import each from its own.
topicstopicbyDomainbyFamilybyArchetypeloadrunnerjs
import { calculateSma } from "fintech-algorithms/technical-indicators/trend-smoothing/sma";
calculateSma([44.34, 44.09, 44.15, 43.61, 44.33, 44.83], 5);
// → [null, null, null, null, 44.104, 44.202]
// ^^^^ four warm-up nulls: window - 1The condition resolves to the same ES module — there is no separate
CommonJS build, so needs a runtime supporting .
requirerequire()require(esm)bash
npm install fintech-algorithms算法仅支持子路径导入。根导出仅包含元数据和查找功能(、、、、、、),不导出任何算法。某一主题的函数绝不会从其他子路径重新导出——每个算法都需从自身子路径导入。
topicstopicbyDomainbyFamilybyArchetypeloadrunnerjs
import { calculateSma } from "fintech-algorithms/technical-indicators/trend-smoothing/sma";
calculateSma([44.34, 44.09, 44.15, 43.61, 44.33, 44.83], 5);
// → [null, null, null, null, 44.104, 44.202]
// ^^^^ 四个预热null值:窗口大小 - 1requirerequire()require(esm)The lookup script
查找脚本
scripts/lookup.mjsThese files write for the directory containing this SKILL.md.
In Claude Code that is , which the harness substitutes for
you. In any other agent, substitute the real path before running the command.
${SKILL_DIR}${CLAUDE_SKILL_DIR}bash
node "${CLAUDE_SKILL_DIR}/scripts/lookup.mjs" search "moving average"Commands:
| Command | Does |
|---|---|
| find topics by name, slug, family or entry |
| full contract, warm-up, errors, executed example |
| every topic sharing an input shape, plus its caveat |
| every topic in a domain, grouped by family |
| the thirteen domains with their index URLs |
| the reference version vs the published one |
Reads when the package is installed
anywhere above the working directory; otherwise fetches and caches the published
payload for a day. Set to point it at a specific file.
Accepts a slug (), a catalog id (), a full path, or a docs URL.
node_modules/fintech-algorithms/docs.jsonFINTECH_DOCS_JSONrsiD07-F03-A01If cannot find the topic it says so rather than guessing — that failure is
the correct answer, not an obstacle to route around.
showscripts/lookup.mjs以下文件使用表示包含本SKILL.md的目录。 在Claude Code中,该目录为,由工具自动替换。在其他Agent中,请在运行命令前替换为实际路径。
${SKILL_DIR}${CLAUDE_SKILL_DIR}bash
node "${CLAUDE_SKILL_DIR}/scripts/lookup.mjs" search "moving average"命令说明:
| 命令 | 功能 |
|---|---|
| 按名称、slug、分类或条目查找主题 |
| 显示完整契约、预热机制、错误处理及执行示例 |
| 显示所有共享同一输入结构的主题及其注意事项 |
| 显示某一领域下的所有主题,按分类分组 |
| 显示13个领域及其索引URL |
| 显示参考版本与已发布版本的对比 |
当包安装在工作目录上方任意位置时,脚本会读取;否则会获取并缓存已发布的负载数据,有效期为一天。可设置指向特定文件。接受slug(如)、目录ID(如)、完整路径或文档URL。
node_modules/fintech-algorithms/docs.jsonFINTECH_DOCS_JSONrsiD07-F03-A01若命令无法找到主题,会直接说明而非猜测——这种失败是正确的结果,而非需要绕过的障碍。
showLoad a reference when
何时加载参考文档
- — mapping user data into an input shape, or deciding how much adapter code a task needs.
references/archetypes.md - — the user has a provider, a CSV, a websocket or a broker API and asks how to connect it.
references/ingestion.md - — an end-to-end task: clean a feed, build bars, compute a multi-indicator report.
references/recipes.md - — before finalising any numeric answer. Short, and every entry is a real failure mode with a real cause.
references/pitfalls.md
- —— 将用户数据映射为输入结构,或确定任务所需的适配器代码量时。
references/archetypes.md - —— 用户有数据源提供商、CSV文件、WebSocket或经纪商API,并询问如何对接时。
references/ingestion.md - —— 处理端到端任务:清洗数据源、构建K线、生成多指标报告时。
references/recipes.md - —— 在确定任何数值答案前。内容简短,每条都是真实的失败模式及原因。
references/pitfalls.md
Coverage
覆盖范围
13 domains: Market Data Engineering (31) · Corporate Actions and Security Master
Data (20) · Index and Benchmark Engineering (40) · Market Breadth and Internals
(28) · Price Action and Candlesticks (38) · Technical Indicators (37) ·
Geometric Chart Patterns (27) · Statistical Time Series (29) · Market
Microstructure (29) · Matching Engines and Venue Logic (21) · Execution and
Transaction Cost Analysis (9) · Digital Assets and On-Chain Finance (10) ·
Earnings and Per-Share Analytics (5).
Not a backtester, an execution system, a portfolio manager, or a source of
market data. It computes quantities, places no orders, and holds no state
between calls.
13个领域:市场数据工程(31个)· 公司行为与证券主数据(20个)· 指数与基准工程(40个)· 市场广度与内部数据(28个)· 价格行为与K线(38个)· 技术指标(37个)· 几何图表形态(27个)· 统计时间序列(29个)· 市场微观结构(29个)· 匹配引擎与交易场所逻辑(21个)· 执行与交易成本分析(9个)· 数字资产与链上金融(10个)· 收益与每股收益分析(5个)。
本库不是回测工具、执行系统、投资组合管理器或市场数据源。它仅计算数值,不发送订单,且调用之间不保存状态。