fintech-algorithms

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

fintech-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.
324个用于市场与金融计算的纯函数。输入为普通数组和对象,输出为普通值。零运行时依赖,支持Node >= 22,采用ESM规范。

Non-negotiables

不可协商规则

Four rules. Breaking any one produces output that looks right and is wrong.
  1. 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 —
    scripts/lookup.mjs
    or the resolution order below. If the topic does not exist, say so and stop.
  2. Never guess a returned field name. Return-key casing is not consistent across the library:
    bollingerBands
    returns
    percent_b
    ,
    macd
    rows return
    fastEma
    . Read the captured example output for that topic. See
    references/pitfalls.md
    .
  3. State the verification tier on any numeric claim.
    verified
    (158 topics) means the arithmetic is replayed and asserted on every build.
    contract
    (166 topics) means the signature and shape are checked but the numbers are not attested by an independent published figure.
  4. 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.
四条规则。违反任何一条都会导致输出看似正确实则错误。
  1. 切勿自行编造导入路径、函数名或参数。 每个子路径都与文档URL完全对应,这使得合理的猜测也可能产生看似正确的错误结果。请查阅相关内容——可使用
    scripts/lookup.mjs
    或下文的解析顺序。若相关主题不存在,请直接说明并停止操作。
  2. 切勿猜测返回字段名。 库中返回键的大小写并不统一:
    bollingerBands
    返回
    percent_b
    macd
    的行返回
    fastEma
    。请查阅对应主题的示例输出。详见
    references/pitfalls.md
  3. 说明数值声明的验证等级
    verified
    (158个主题)表示算法运算会在每次构建时重放并验证。
    contract
    (166个主题)表示仅检查签名和结构,但数值未经过独立发布数据的验证。
  4. 仅做分析,不提供建议。 这些函数仅计算数值。指标交叉只是对序列的观察——并非预测、信号,更绝非针对个人资金的推荐。请报告计算内容、输入数据、验证等级,以及有多少前置值是预热值而非信号值。若被问及买卖建议,请说明该问题需咨询持牌顾问。

The library does not fetch data

本库不获取数据

There is no HTTP client, no vendor SDK, no API key, no
node:fs
. If a task needs prices, the caller supplies them. This is deliberate: vendor APIs get rewritten every few years and algorithms do not.
When 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
references/ingestion.md
for the adapter pattern and the canonical
Trade
/
Bar
shapes.
本库无HTTP客户端、无厂商SDK、无API密钥、无
node:fs
模块。若任务需要价格数据,需由调用方提供。这是有意设计的:厂商API每隔几年就会重写,但算法不会。
当用户需要“实时分析”时,流程始终为:他们的数据源 → 他们的适配器 → 验证 → 计算 → 报告。本库仅负责中间两个步骤。如需了解适配器模式及标准
Trade
/
Bar
结构,请查看
references/ingestion.md

Resolution order

解析顺序

Stop at the first step that answers the question.
  1. Installed package — if
    fintech-algorithms
    is a dependency, read
    node_modules/fintech-algorithms/docs.json
    . Every signature, contract and worked example, no network. Prefer this.
    scripts/lookup.mjs
    uses it automatically.
  2. Domain index
    https://docs.thefintechbuilder.com/{domain-slug}/llms.txt
    (3–11 KB each). The map of all thirteen is the
    ## Per-domain indexes
    block at the top of
    /llms.txt
    ; one root fetch gives a permanent routing table.
  3. Topic markdown — append
    index.md
    to any docs URL. The full contract in 3–11 KB instead of 68–114 KB of HTML.
  4. Full payload
    https://docs.thefintechbuilder.com/reference/payload.json
    (~2.6 MB). For ingestion, not for answering one question.
Turn a docs URL into an import: swap
https://docs.thefintechbuilder.com/
for
fintech-algorithms/
and drop the trailing slash.
Check the installed version matches the docs with
https://docs.thefintechbuilder.com/version.json
(under 1 KB).
找到第一个能回答问题的步骤即停止。
  1. 已安装的包 —— 若
    fintech-algorithms
    是依赖项,请读取
    node_modules/fintech-algorithms/docs.json
    。包含所有签名、契约和示例,无需网络。优先使用此方式
    scripts/lookup.mjs
    会自动使用该文件。
  2. 领域索引 ——
    https://docs.thefintechbuilder.com/{domain-slug}/llms.txt
    (每个3–11 KB)。所有13个领域的映射表位于
    /llms.txt
    顶部的
    ## Per-domain indexes
    块;一次根请求即可获取永久路由表。
  3. 主题Markdown文档 —— 在任意文档URL后追加
    index.md
    。完整契约仅3–11 KB,而非68–114 KB的HTML。
  4. 完整负载 ——
    https://docs.thefintechbuilder.com/reference/payload.json
    (约2.6 MB)。用于数据导入,而非回答单个问题。
将文档URL转换为导入路径:把
https://docs.thefintechbuilder.com/
替换为
fintech-algorithms/
并去掉末尾斜杠。
通过
https://docs.thefintechbuilder.com/version.json
(小于1 KB)检查已安装版本是否与文档匹配。

Workflow

工作流程

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:
ArchetypeTakesReturnsCount
series-transform
(number | null)[]
+ numeric params
same-length array37
tape-aggregate
Trade[]
+ config
Bar[]
7
row-classify
rowsone verdict per row17
snapshot-evaluate
one snapshot + decision timeone verdict6
record-transform
domain-specificdomain-specific257
record-transform
is the residual bucket — read that topic's own contract. Details and executed examples:
references/archetypes.md
.
3. Read the contract. Signature, params, returns, warm-up, errors.
bash
node scripts/lookup.mjs show rsi
4. 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个主题,每个索引行都标注了原型:
原型输入输出数量
series-transform
(number | null)[]
+ 数值参数
等长数组37
tape-aggregate
Trade[]
+ 配置
Bar[]
7
row-classify
行数据每行一个判定结果17
snapshot-evaluate
单个快照 + 决策时间一个判定结果6
record-transform
特定领域数据特定领域数据257
record-transform
是剩余分类——请查阅该主题自身的契约。详细信息及执行示例:
references/archetypes.md
3. 阅读契约。 签名、参数、返回值、预热机制、错误处理。
bash
node scripts/lookup.mjs show rsi
4. 整理数据格式。 将用户数据映射为文档规定的输入格式。当输入为K线、tick或报价数据时,先运行边界验证器。
5. 计算并报告。 说明计算内容、输入数据、验证等级,以及有多少前置值是预热值而非信号值。

Quick start

快速开始

bash
npm install fintech-algorithms
Algorithms are subpath-only. The root export carries metadata and lookups (
topics
,
topic
,
byDomain
,
byFamily
,
byArchetype
,
load
,
runner
) and re-exports no algorithm. A sibling topic's function is never re-exported from another subpath — import each from its own.
js
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 - 1
The
require
condition resolves to the same ES module — there is no separate CommonJS build, so
require()
needs a runtime supporting
require(esm)
.
bash
npm install fintech-algorithms
算法仅支持子路径导入。根导出仅包含元数据和查找功能(
topics
topic
byDomain
byFamily
byArchetype
load
runner
),不导出任何算法。某一主题的函数绝不会从其他子路径重新导出——每个算法都需从自身子路径导入。
js
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值:窗口大小 - 1
require
条件会解析为相同的ES模块——本库无单独的CommonJS构建,因此
require()
需要支持
require(esm)
的运行时环境。

The lookup script

查找脚本

scripts/lookup.mjs
sits next to this file. The working directory is the user's project, not the skill, so always invoke it by absolute path.
These files write
${SKILL_DIR}
for the directory containing this SKILL.md.
In Claude Code that is
${CLAUDE_SKILL_DIR}
, which the harness substitutes for you. In any other agent, substitute the real path before running the command.
bash
node "${CLAUDE_SKILL_DIR}/scripts/lookup.mjs" search "moving average"
Commands:
CommandDoes
search <query>
find topics by name, slug, family or entry
show <slug|id|path>
full contract, warm-up, errors, executed example
archetype <name>
every topic sharing an input shape, plus its caveat
domain <id|slug>
every topic in a domain, grouped by family
domains
the thirteen domains with their index URLs
version
the reference version vs the published one
Reads
node_modules/fintech-algorithms/docs.json
when the package is installed anywhere above the working directory; otherwise fetches and caches the published payload for a day. Set
FINTECH_DOCS_JSON
to point it at a specific file. Accepts a slug (
rsi
), a catalog id (
D07-F03-A01
), a full path, or a docs URL.
If
show
cannot find the topic it says so rather than guessing — that failure is the correct answer, not an obstacle to route around.
scripts/lookup.mjs
位于本文件旁。工作目录为用户项目目录,而非技能目录,因此请始终通过绝对路径调用它。
以下文件使用
${SKILL_DIR}
表示包含本SKILL.md的目录。
在Claude Code中,该目录为
${CLAUDE_SKILL_DIR}
,由工具自动替换。在其他Agent中,请在运行命令前替换为实际路径。
bash
node "${CLAUDE_SKILL_DIR}/scripts/lookup.mjs" search "moving average"
命令说明:
命令功能
search <query>
按名称、slug、分类或条目查找主题
show <slug|id|path>
显示完整契约、预热机制、错误处理及执行示例
archetype <name>
显示所有共享同一输入结构的主题及其注意事项
domain <id|slug>
显示某一领域下的所有主题,按分类分组
domains
显示13个领域及其索引URL
version
显示参考版本与已发布版本的对比
当包安装在工作目录上方任意位置时,脚本会读取
node_modules/fintech-algorithms/docs.json
;否则会获取并缓存已发布的负载数据,有效期为一天。可设置
FINTECH_DOCS_JSON
指向特定文件。接受slug(如
rsi
)、目录ID(如
D07-F03-A01
)、完整路径或文档URL。
show
命令无法找到主题,会直接说明而非猜测——这种失败是正确的结果,而非需要绕过的障碍。

Load a reference when

何时加载参考文档

  • references/archetypes.md
    — mapping user data into an input shape, or deciding how much adapter code a task needs.
  • references/ingestion.md
    — the user has a provider, a CSV, a websocket or a broker API and asks how to connect it.
  • references/recipes.md
    — an end-to-end task: clean a feed, build bars, compute a multi-indicator report.
  • references/pitfalls.md
    — before finalising any numeric answer. Short, and every entry is a real failure mode with a real cause.
  • references/archetypes.md
    —— 将用户数据映射为输入结构,或确定任务所需的适配器代码量时。
  • references/ingestion.md
    —— 用户有数据源提供商、CSV文件、WebSocket或经纪商API,并询问如何对接时。
  • references/recipes.md
    —— 处理端到端任务:清洗数据源、构建K线、生成多指标报告时。
  • 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个)。
本库不是回测工具、执行系统、投资组合管理器或市场数据源。它仅计算数值,不发送订单,且调用之间不保存状态。