Skip to content

feat(testnet): testnet runner, weekly comparison infra, SMF known-answer tests, and validation audit - #12

Merged
guigerdts merged 8 commits into
mainfrom
feature/auditoria-validacion-infraestructura
Jul 4, 2026
Merged

guigerdts merged 8 commits into
mainfrom
feature/auditoria-validacion-infraestructura

Conversation

@guigerdts

Copy link
Copy Markdown
Owner

Summary

  • Testnet runner with continuous paper-trading (swing_smf + intraday_smf)
  • Weekly backtest-vs-live signal comparison script
  • 27 known-answer tests for SMF indicators
  • Clock injection fix (time.time → clock.timestamp) with 13 tests
  • Bug pattern scanner (id() cache, mutable defaults, iloc off-by-one) — 0 HIGH findings
  • Cross-validation of 9 classic indicators against pandas_ta

Changes

File Change
_scripts/run_testnet.sh Continuous testnet runner (start/stop/status)
_scripts/weekly_compare.py Parallel backtest + signal-by-signal comparison
_scripts/run_weekly_compare.sh Wrapper for weekly cron runs
tests/test_smf_known_answers.py 27 known-answer tests for 5 SMF indicators
tests/test_clock_injection.py 13 tests for clock protocol
tests/audit_patterns.py AST+regex scanner for 3 historical bug patterns
tests/golden/audit_patterns_report.json Audit report: 0 HIGH, 24 LOW (intentional)
tests/test_indicator_xval.py 51 cross-validation tests vs pandas_ta
tests/test_known_answers.py 19 known-answer tests for classic indicators
src/royaltdn/core/clock.py timestamp() method on SimClock/RealClock
src/royaltdn/cells/base.py clock injection in Cell.init, 9 time.time→self._now
src/royaltdn/cells/templates/*.yaml RegimeFilter enabled, SMF-only strategies
src/royaltdn/config.yaml enabled_strategies restricted to SMF pair
src/royaltdn/inference/conditions.py SMF cloud, adx, indicator fixes
src/royaltdn/risk/manager.py Circuit breaker, per-direction limits, concentration caps
openspec/changes/auditoria-validacion-infraestructura/ Full SDD artifacts

Test Plan

  • All 27 SMF known-answer tests pass
  • All clock injection tests pass
  • Audit scanner confirms 0 HIGH findings
  • Cross-validation: 9 indicators match pandas_ta within 1e-8 tolerance
  • Weekly comparison script runs end-to-end against real journal data

Notes

  • RegimeFilter is configured but wiring to live pipeline is pending
  • No real capital — pure paper trading on live market data
  • Weekly comparison needs 4+ weeks before drawing conclusions

- Add interval param (default 1m) to BinanceFeed.__init__
- Change _build_url() to stream @kline_{interval}
- Rewrite _handle_message() for kline schema with nested k object
- Add _kline_start to event data
- Update docstrings for kline feed
- Use function-level lazy imports
- Add 4 unit tests for kline parser (fields, skip non-kline, combined stream, open candle)
Add percentage-based stop-loss, take-profit, and trailing-stop exits
before existing ATR-based exits in all SMF cells across 3 templates.

- swing.yaml: SL 3%, TP 5%, TS 2% (trend); SL 2%, TP 3% (reversion)
- intraday.yaml: SL 1.5%, TP 2.5%, TS 1% (trend); SL 1%, TP 2% (reversion)
- scalping.yaml: SL 0.8%, TP 1.5%, TS 0.5% (trend); SL 0.6%, TP 1.2% (reversion)
- Non-SMF cells (swing_reversion, swing_momentum, intraday_volume_breakout,
  scalping_reversion) left unchanged
Move debug log after _calc_atr() so ATR value is available for display.
Show both pct and ATR exit values: SL_pct, SL_ATR, TP_pct, TS_pct,
TS_ATR, TS_min, TS_max, Z, and computed ATR.
- Update BinanceFeed component table to show @kline_1m
- Add exit management section with pct + ATR layer docs
- Pre-set entry/short_entry smf_strength to > 0.3 (was > 0.4)
- Optimized ADX period 38, threshold > 27 (was 14 / > 20)
- Optimized exits: SL 6.0%, TP 4.3%, TS 3.0%
- Tightened ATR exits (atr_mult 0.5, 0.6)
- Adjusted risk sizing to 0.035, max_positions 3
Add comprehensive validation tests for the indicator infrastructure:

- Known-answer tests (19 tests): EMA, ATR, Donchian, buy-and-hold
  benchmark, and insufficient-data guards using synthetic data
- Cross-validation tests (45 cases): 9 exact-match indicators validated
  against pandas_ta across 5 real symbols with 1e-8 tolerance
- Edge-case tests (6 tests): NaN propagation, constant-price RSI=50,
  zero-volume VWAP, hand-calculated VWAP verification
- Golden fixture schema: tests/golden/schema.json for future snapshot
  testing

RSI/ATR/ADX excluded from cross-validation matrix: pandas_ta uses
Wilder RMA (alpha=1/N) while the project uses SMA/rolling-mean.
These are covered by known-answer tests instead.

Part of: sdd/auditoria-validacion-infraestructura (Phase 2)
…nown-answer tests

- Add _scripts/run_testnet.sh: continuous paper-trading runner
- Add _scripts/weekly_compare.py: parallel backtest + signal comparison
- Add _scripts/run_weekly_compare.sh: weekly wrapper
- Add tests/test_smf_known_answers.py: 27 known-answer SMF tests
- Add Guia_testnet.md: quick reference guide
- Enable regime_filter on swing_smf + intraday_smf YAML
- Restrict enabled_strategies to 2 SMF strategies in config
@guigerdts
guigerdts merged commit 96fffd7 into main Jul 4, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant