Skip to content

fix: correct color inversion, UnboundLocalError, and Tencent data key bugs#34

Merged
AlanFokCo merged 3 commits into
mainfrom
copilot/phase1-backtest-scientificity-design
May 28, 2026
Merged

fix: correct color inversion, UnboundLocalError, and Tencent data key bugs#34
AlanFokCo merged 3 commits into
mainfrom
copilot/phase1-backtest-scientificity-design

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 27, 2026

Codebase audit surfaced five bugs across report.py, data.py, and objects.py.

Color values swapped in report charts

  • CSS variables --green and --red were mapped to opposite hex values (--green: #f5222d 🔴, --red: #52c41a 🟢)
  • _build_daily_pnl() bar chart colors used the same inverted logic — gains rendered red, losses green

UnboundLocalError in _align_fallback()

base was only assigned when i == 0, but if the first data point was skipped (empty series or NaN), subsequent iterations crashed on the unguarded base reference:

# Before — base never assigned if i==0 is skipped
if i == 0:
    base = pr
if base <= 0 or np.isnan(base):  # UnboundLocalError
    continue

# After — safe initialization
base = None
...
if base is None:
    base = pr

Tencent API returns wrong kline series for hfq adjust

The key lookup was "qfqday" if adjust else "day", so any non-empty adjust (including "hfq") resolved to "qfqday". Fixed to f"{adjust}day".

Redundant local imports in objects.py

Removed two local import datetime statements that shadowed the existing module-level import.

Copilot AI added 2 commits May 27, 2026 16:28
Add eqlib/scientific/ package with:
- overfitting.py: walk-forward analysis, parameter sensitivity, OOS test
- statistics.py: bootstrap CI, Monte Carlo simulation, significance tests
- bias.py: survivorship, lookahead, selection, data bias detection
- risk.py: extended risk metrics (VaR, CVaR, stress test, tail risk)
- comparison.py: platform comparison and trade verification
- validation_runner.py: unified pipeline orchestration
- report.py: markdown/JSON/HTML report generation
- validation_config.py: global configuration dataclass

Add comprehensive tests (56 new tests, 338 total passing)
Copilot AI changed the title feat: Phase 1 backtest scientificity framework feat: Phase 1 backtest scientificity validation framework May 27, 2026
Copilot AI requested a review from AlanFokCo May 27, 2026 16:31
… bugs

- Fix inverted CSS color variables in report.py (--green was red, --red was green)
- Fix inverted color logic in _build_daily_pnl() bar charts
- Fix UnboundLocalError in _align_fallback() when first data point is skipped
- Fix Tencent data key lookup: "hfq" adjust now correctly maps to "hfqday"
- Remove redundant local `import datetime` in objects.py
Copilot AI changed the title feat: Phase 1 backtest scientificity validation framework fix: correct color inversion, UnboundLocalError, and Tencent data key bugs May 28, 2026
@AlanFokCo AlanFokCo marked this pull request as ready for review May 28, 2026 03:04
@AlanFokCo AlanFokCo merged commit 9c5898e into main May 28, 2026
3 checks passed
@AlanFokCo AlanFokCo deleted the copilot/phase1-backtest-scientificity-design branch May 28, 2026 07:57
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.

2 participants