Skip to content

[Feature Request]: technical-indicator kernels and rolling risk analytics #29949

Closed

Description

@dengn

Why this is needed

Financial/risk and telemetry workflows commonly use smoothed indicators, drawdown, streaks and local trends. Each library has seeding, warmup and missing-data conventions; repeatedly porting formulas increases maintenance and validation cost.

Requested behavior and scope

Add documented SQL/migration equivalents for the missing EMA/DEMA/TEMA/T3/KAMA/Wilder/WMA/SMA/TRIMA family and rolling drawdown/streak/trend operators. Prioritize well-defined profiles with warmup and NULL semantics rather than claiming all TA-Lib defaults are identical. The verified price fixture 100,120,90,110 has cumulative maximum drawdown ratios 0,0,0.25,0.25 using ordinary SQL windows. Bounded-frame drawdown must use frame-local peaks, not the all-history peak. No live DolphinDB/TA-Lib performance comparison is claimed.

Tested revision / existing issue check

  • MatrixOne commit: 23d8f61252f3017dff218b530817a240206fd762.
  • Existing issues were searched before filing; related requests/closed fixes are distinguished above.
  • All data below is synthetic. The probe is read-only and requires no persisted tables.

Executable unsupported case

SELECT mmaxDrawdown(CAST(1 AS DOUBLE),3) result;

Actual MO result, reproduced 3/3:

(20105, "not supported: function or operator 'mmaxdrawdown'")

This probe checks entry-name availability only. A rejection does not establish that the business calculation is impossible or that this is a valid DolphinDB script signature. The requested mathematical operation is defined above and checked by the independent profile below.

Additional actually executed cases

Each listed rejection was executed three times on the same synthetic fixture.

Case MO result Declared expected values / scope
ema_entry rejected 3/3 Entry resolution only; no invented engine result
kama_entry rejected 3/3 Entry resolution only; no invented engine result
mmaxDrawdown_entry rejected 3/3 Entry resolution only; no invented engine result
cumPositiveStreak_entry rejected 3/3 Entry resolution only; no invented engine result

Working SQL control / alternative

The following control was executed 3/3 and its complete output values were checked, not merely execution success:

WITH a AS (SELECT id,price,MAX(price) OVER(ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) peak
FROM (
  SELECT 1 id,CAST(100 AS DOUBLE) price
  UNION ALL SELECT 2,120
  UNION ALL SELECT 3,90
  UNION ALL SELECT 4,110) fixture) SELECT id,MAX(CAST(1 AS DOUBLE)-price/peak) OVER(ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) result FROM a ORDER BY id;
Control Verified values
cumulative_max_drawdown_control 0, 0, 0.25, 0.25

Acceptance / regression coverage

Retain the self-contained fixture and assert complete values, NULL bits and row alignment. Add partitions, ties, empty/all-NULL frames, frame-entry/exit and type boundaries appropriate to this operator. Validate named/API availability separately from mathematical rewrites. Benchmark any claimed state/performance advantage with identical data and correctness rules; no speedup is asserted by these small tests.

Subsequent SELECT 1 succeeded after the test matrix. DolphinDB references are official documentation; no DolphinDB runtime or all-parameter parity is claimed.

Reference

https://docs.dolphindb.com/en/Functions/Themes/TALib.html

Activity

  1. XuPeng-SH commented on Oct 12, 2026

    @XuPeng-SH
    Contributor

    Triage decision: defer.

    Reason: this is a specialized window/time-series capability. The report establishes a syntax or API gap, but does not show a confirmed customer blocker or near-term roadmap commitment. The umbrella report also notes that many profiles can be composed from existing SQL and does not provide a native-performance comparison.

    Promote when a concrete customer workload or roadmap commitment is identified and correctness/performance acceptance criteria are agreed.

  2. added this to the Backlog milestone on Oct 12, 2026
  3. self-assigned this
    on Oct 12, 2026
  4. 3 remaining items

  5. added
    severity/s0
    ai-easy
    and removed on Oct 23, 2026
  6. gouhongshen commented on Oct 24, 2026

    @gouhongshen
    Contributor

    PR #31017 is trying to fix this issue.

  7. gouhongshen commented on Oct 24, 2026

    @gouhongshen
    Contributor

    PR #31017 has merged and is awaiting manual validation. The issue remains open.

  8. XuPeng-SH commented on Oct 24, 2026

    @XuPeng-SH
    Contributor

    Manual validation for merged PR #31017 on an isolated local service:

    • Runtime: latest-main source dae02bbaaaa18aac7fa9b788e42f4483b3adf091; executable SHA-256 b534b2c2d33683eab3572971284093f6d584b626f4f94691b6dc050690c2d21c.
    • The committed SQL BVT's 50 positive statements passed; all 38 result tables / 404 rows matched, including NULL positions. All 18 expected binder, argument-boundary, type and non-finite error cases matched.
    • Independent EMA, KAMA and frame-local mmaxDrawdown references matched within tolerance; NULL bits matched. An 8,192-row period-1024 drawdown query matched the independent checksum (7,169 defined rows, 7096.737109), including two simultaneous sessions.
    • On 65,536 synthetic rows, actual SQL KILL QUERY returned error 1317 in 329 ms; the same connection recovered. A separate expected SQL error was followed by successful SELECT and EMA on that connection.

    This is a scoped pass on one local CN, not multi-CN/distributed or broad scale/performance acceptance. A focused Go unit command timed out twice during dependency compilation (5 min and 8 min); no unit tests ran, so those attempts are not counted as product failures. No defect was reproduced in the SQL cases above. Keeping the issue open for testing/acceptance.

  9. XuPeng-SH commented on Oct 25, 2026

    @XuPeng-SH
    Contributor

    Additional fresh-round evidence supersedes the earlier note that focused Go tests had only timed out during compilation. On isolated source aeaa273daf588a9988ba423915d3ae6b8c82124a / service SHA-256 450363d5ec5e693bdd7ded44565b3b0ab1addcb807d3f9569c5d5eedeb1486e4, the 69-statement SQL case and 15 independent math-oracle result sets still pass. A warm-cache focused TestIndicator suite in ./pkg/sql/colexec/window then exited 0 after a 17-minute dependency compile; package test time was 8.975s. It included cancellation/reuse, cancellation latency, empty/all-NULL partitions, seed-ring checks, procedure-M/U oracles/fuzzing, subnormal/ULP scans, drawdown, documented errors, and lifecycle tests. The log has two small mpool outstanding-ownership WARNs (64 and 512 bytes) while the associated lifecycle tests passed. Command: go test -vet=off ... ./pkg/sql/colexec/window -run '^TestIndicator' -count=1 -v with one worker, GOMEMLIMIT=1536MiB, and the retained native CGo libraries. This remains focused single-CN coverage; no full package/repository or multi-CN benchmark is claimed. The issue was already assigned to Ariznawlll, so assignment is unchanged. Local log: round2-aeaa273-31017-indicator-go-tests-retry30m.log.

  10. Ariznawlll commented on Oct 26, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 测试日期:2026-10-26。
    • MatrixOne:本地隔离构建,源码 5fe08a3307e246e1ab9951ab690b50557af0f509;LOG/TN/CN 在同一进程、单 CN、独立数据目录及 SQL 端口 6201。测试时官方 main 为 4769417cdce5531c9771644eca49f1e71d8f654c;本地源码比它少一个仅涉及 SHOW/ALTER 默认值及 dump 的提交,不把本轮称作该最新 SHA 的实测。
    • 用当前 mo-tester 309a0ca650e0c55e90292767fd61e4976818d66d 执行已合入的 SQL/golden。用户原工作区没有切分支或改文件。

    原问题验证

    原 issue 中不带 OVER 的 ema、kama、mmaxDrawdown、cumPositiveStreak 探针不再是“不支持函数”错误,而是窗口函数必须带 OVER 的预期诊断;这只验证入口存在,不把探针当作有效计算。有效窗口调用与 golden 逐条比较。原文 100,120,90,110 的普通 SQL 累计最大回撤对照仍为 0,0,0.25,0.25;有界 mmaxDrawdown 另按窗口内峰值核对,避免把累计峰值误当局部峰值。

    Happy Path 覆盖

    1. 完整执行已合入的 func_indicator_kernels.sql:69 条语句,69 成功、0 失败、0 异常、0 跳过;每条实际结果与配套 .result 比对,不只是 SQL 能执行。
    2. SMA/WMA/TRIMA/EMA/Wilder/KAMA/DEMA/TEMA/T3 的分区、混合正负数、全 NULL 分区、warmup 与分区重置;8 行链式序列检查 TEMA/T3 首个非 NULL 值及后续更新;常量输入、整数输入和周期 1。
    3. 周期常量折叠和纯函数表达式(如 2+1、ABS(3)、LENGTH('abc')、GREATEST(2,3));周期上限 1024。回撤周期 4/3/2/1 覆盖峰值进入与退出窗口、零谷值、负谷值、非正峰值及 NULL;另核对 KAMA 平坦段、正向 streak 及普通 SQL 的 SMA/趋势组合配方。

    Unhappy Path 覆盖

    1. 缺少窗口排序或显式提供不允许的窗口 frame;周期 0、1025、越界折叠值、非整数或列引用周期,均按 golden 拒绝。
    2. 回撤比值与 DEMA 计算可能产生非有限结果的输入按预期报错,不默默返回 Inf;错误后脚本继续执行后续对照查询并完成测试库清理。

    白盒验证

    本轮未重新运行 Go UT、race 或性能基准;此前研发的聚焦 TestIndicator 实测及其范围见已有验证评论,不计入本轮 69 条黑盒结果。

    回归测试

    实现 PR #31017 已合入;本轮复跑的是 SQL 用例 与配套 golden。本次没有新增回归代码或 PR。

    测试证据

    • 本地原始执行日志:/private/tmp/qa-three-features-local.TrLbxB/indicator_test.log,摘要 TOTAL=69, SUCCESS=69, FAILED=0, ABNORAML=0, SUCCESS RATE=100%。
    • 本轮是单机功能/结果正确性测试;未测多 CN、长稳或性能收益,不把它们写成已通过。

    测试结论

    测试通过。

  11. Ariznawlll commented on Oct 26, 2026

    @Ariznawlll
    Collaborator

    测试补充:已执行验证与回归跟踪

    测试版本

    2026-10-26,本地 MatrixOne 源码 5fe08a3307e246e1ab9951ab690b50557af0f509。SQL/golden 验证采用隔离单 CN 环境;新增 MOTR 用例另在同一进程内的两个 CN 服务、共享 LOG/TN 环境验证,不等同于 TKE 独立 CN Pod 验证。

    原问题验证

    已执行 func_indicator_kernels.sql,69/69 条成功,0 失败、0 异常、0 跳过,实际结果与 golden 一致。原文价格序列 100,120,90,110 的累计回撤对照为 0,0,0.25,0.25;有界回撤按窗口内峰值另行核对。

    Happy Path 覆盖

    • SMA/WMA/TRIMA/EMA/Wilder/KAMA/DEMA/TEMA/T3:warmup、分区重置、NULL、混合正负值、周期 1、链式 seed 及常量表达式周期。
    • 回撤窗口 4/3/2/1:峰值进入/退出、零/负谷值、非正峰值;另覆盖 KAMA 平坦段与正向 streak。
    • 新增 MOTR 对 EMA、KAMA、mmaxDrawdown 使用独立 Python 逐行 oracle,覆盖三个分区、NULL、混合符号和局部峰值淘汰,并在两个直连 CN 上校验。

    Unhappy Path 覆盖

    缺少排序、不支持的显式 frame、周期 0/1025、越界/非整数/列引用周期,以及非有限计算结果,均核对预期错误;错误后继续执行正常 SQL。新增 MOTR 与 #29947 用例一起以 --repeat 3 执行,共 6/6 通过。

    白盒验证

    本次未新增或重跑 Go UT/race;此前聚焦 TestIndicator 的白盒证据见已有验证记录,与本次黑盒结果分开统计。

    回归测试

    测试证据

    本地完整 SQL 验证记录及 MOTR 用例与本地复跑摘要。

    按本次确认的验收安排,先关闭本 feature;计划于 2026-10-27 执行的 TKE 回归仍标为待执行,不计入当前通过证据。当前未宣称长期稳定性、性能收益或与其他产品全部默认行为一致。下述结论仅针对上述已执行的本地功能验证。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/featureseverity/s0

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions