Skip to content

Compare indicators against TA-Lib reference data - #536

Merged
cinar merged 1 commit into
masterfrom
talib-compat-tests
Nov 12, 2026
Merged

cinar merged 1 commit into
masterfrom
talib-compat-tests

Conversation

@cinar

@cinar cinar commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Summary

Adds internal/talibcompat, a test package that checks each indicator with a TA-Lib counterpart against TA-Lib output computed with the same parameters. TA-Lib serves as the reference implementation for indicator math.

  • Generator. testdata/generate.py builds two seeded 300-bar OHLCV datasets and writes the inputs plus the TA-Lib reference outputs to CSV:
    • walk: a random walk whose prices practically never repeat;
    • ticks: prices rounded to a 0.5 tick, so equal highs, lows and closes occur and tie handling is exercised.
  • Test. talibcompat_test.go reads the CSVs with the standard library and compares 72 cases (about 100 outputs) per dataset, with a relative tolerance of 1e-8.
  • No new dependencies. Only the generator needs TA-Lib (pip install ta-lib==0.8.3 numpy). The Go module and CI stay dependency-free, and the CSVs are committed (about 630 KB).

How known differences are recorded

Each case states how it compares, so every intentional difference is explicit in one place:

Field Meaning Cases
scale The library returns a ratio, TA-Lib a percentage (#533) Roc, Trix, Kst, BollingerBandWidth, StochasticRsi
fromBar EMA seeding differs, values converge after a warm-up (#535) Macd (170), ChaikinOscillator (150)
skip Known difference, linked to its issue Aroon #520, Cci #521, Dpo #522, EhlersFisher #523, ConnorsRsi #524, Stc #525, Atr / ChandelierExit #526, SuperTrend #527, KeltnerChannel #528, Kvo #529, Cfo #530, Slope #531, InternalBarStrength #532, IchimokuCloud #534

Resolving one of those issues means removing its skip line. I checked that every skipped case currently fails when unskipped. The one exception is IBS on walk, which has no bar where high equals low.

Two passing cases, AtrWithRma and SuperTrendWithRma, show that the existing NewAtrWithMa / NewSuperTrendWithMa extension points already match TA-Lib exactly with Wilder's smoothing (relevant to #526 and #527).

Other changes

Test plan

  • task (fmt, lint, test with -race, docs) passes locally
  • 123 subtests pass, 30 skip (15 known differences × 2 datasets)
  • Temporarily removing the skips makes every skipped case fail, except IBS on walk

🤖 Generated with Claude Code

Add internal/talibcompat, which checks each indicator that has a TA-Lib
counterpart against TA-Lib output computed with the same parameters.

testdata/generate.py produces two 300-bar datasets: a random walk, and
one rounded to a 0.5 tick so that ties occur. It writes the OHLCV inputs
and the TA-Lib outputs to CSV. Only the generator needs TA-Lib; the Go
test reads the CSV with the standard library, so the module stays free
of external dependencies.

Each test case records how it compares: a scale factor where the library
returns a ratio and TA-Lib a percentage (#533), a warm-up bar where EMA
seeding differs (#535), or a skip that links the issue tracking a known
difference (#520, #521-#532, #534).

Add ./internal/... to INDICATOR_BASE so that task runs these tests and
the existing internal/apiconsistency tests, which it did not run before.
Include README changes that task regenerates from earlier commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.75%. Comparing base (8e0d794) to head (35f6990).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #536      +/-   ##
==========================================
- Coverage   91.78%   91.75%   -0.03%     
==========================================
  Files         240      240              
  Lines        7835     7835              
==========================================
- Hits         7191     7189       -2     
- Misses        551      553       +2     
  Partials       93       93              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cinar
cinar merged commit 582c563 into master Nov 12, 2026
5 checks passed
@cinar
cinar deleted the talib-compat-tests branch November 12, 2026 05:15
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants