Skip to content

Add equities adapter for US stock trading#1

Open
zaycruz wants to merge 24 commits into
Nunchi-trade:mainfrom
zaycruz:feat/equities-adapter
Open

Add equities adapter for US stock trading#1
zaycruz wants to merge 24 commits into
Nunchi-trade:mainfrom
zaycruz:feat/equities-adapter

Conversation

@zaycruz
Copy link
Copy Markdown

@zaycruz zaycruz commented Mar 20, 2026

Summary

Adds an equities/ directory with a complete adapter for trading US stocks using the same autoresearch pattern as the crypto version. This enables users to run the autonomous strategy discovery loop on equities instead of crypto.

Key Changes from Crypto Version

Component Crypto Equities
Data Source CryptoCompare + Hyperliquid Yahoo Finance (free, no API key)
Bar Interval 1h (hourly) 1d (daily)
Symbols BTC, ETH, SOL SPY, QQQ, AAPL, MSFT, NVDA
Leverage 20x 2x
Fees 2-5 bps Commission-free
Funding Rate Yes (crypto perps) No
BTC Correlation Filter Yes No

What Remains Unchanged

  • Strategy logic (momentum, EMA, RSI, MACD, BB ensemble) — asset-class agnostic
  • Scoring formula (Sharpe, drawdown penalty, turnover penalty)
  • Backtest engine
  • Autoresearch loop pattern

Testing

cd equities
uv run prepare.py          # Download data (~10s)
uv run backtest.py         # Run backtest (~3s)

First run results on validation data (2023-2024):

  • Score: 3.84
  • Sharpe: 3.84
  • Return: +69%
  • Max Drawdown: 2.76%
  • Win Rate: 77.8%

Files Added

  • equities/prepare.py — Yahoo Finance data download, daily OHLCV
  • equities/strategy.py — 5-signal ensemble (removed crypto-specific logic)
  • equities/backtest.py — Entry point (same as original)
  • equities/pyproject.toml — Dependencies with yfinance
  • equities/README.md — Documentation for equities adapter
  • equities/.gitignore — Ignore venv and cache

Why Daily Bars?

Yahoo Finance provides unlimited daily data for free, but hourly data is limited to the last 60 days. Daily bars work well for equity swing trading and provide enough history for robust backtesting.

Future Enhancements

  • Add support for more symbols (edit ACTIVE_SYMBOLS in strategy.py)
  • Sector rotation signals
  • Volume-based signals
  • Futures adapter (ES, NQ, CL) with paid data provider

Adds an equities/ directory with a complete adapter for trading US stocks
using the same autoresearch pattern as the crypto version.

Changes from crypto version:
- Data source: Yahoo Finance (free, no API key) instead of CryptoCompare/Hyperliquid
- Bar interval: Daily instead of hourly
- Removed funding_rate (crypto perp specific)
- Removed BTC-ETH correlation filter
- Symbols: SPY, QQQ, AAPL, MSFT, NVDA
- Leverage: 2x instead of 20x
- Fees: Commission-free

The strategy logic (momentum, EMA, RSI, MACD, BB ensemble) remains unchanged
and is asset-class agnostic.
@besoeasy
Copy link
Copy Markdown

well we should focus on crypto as of now because once its perfect it can easily be potted to other things right now is not the good time

master and others added 23 commits March 21, 2026 23:58
…or equities

Make symbols configurable via --symbols CLI arg across all scripts (backtest.py,
prepare.py, run_benchmarks.py) with auto-download of missing data. Tune strategy
parameters for daily bars. Add 4 benchmark strategies and program.md for the
autonomous experiment loop.

Baseline score: 5.58 (Sharpe 5.58, +127% return, 1.8% max DD) on 10 diversified
symbols over 2023-2024 validation period.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…, ensemble integration

Add scikit-learn GradientBoostingClassifier as confidence signal in the ensemble.
- 28 features: momentum, trend, RSI, MACD, vol, volume, price action, BB, regression
- Warmup training on first 150 bars, predict for remaining ~350 bars
- ML acts as 6th vote in ensemble (currently score-neutral — foundation for evolution)
- Backtest time: 10.1s (within 120s budget)

Score unchanged at 9.288 — ML hyperparameters ready for autonomous evolution.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Describe a trading strategy in natural language, Claude generates the code,
backtests it automatically, and offers refine/evolve/restore options.

Usage:
  uv run generate.py "pairs trading with z-score entry" --symbols SPY QQQ
  uv run generate.py --refine "tighten stops to 2x ATR"
  uv run generate.py --evolve --budget 5
  uv run generate.py --restore

Uses claude CLI (-p mode) for code generation with retry on failure.
Zero new dependencies — stdlib only.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Generate (fresh NL description) forces a new backup.
Refine skips if backup already exists, preserving the original.
This ensures --restore always returns to the pre-generation state.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…te loop

Convert while True to bounded for loop. Estimate ~$0.50/generation, so
$5 budget = ~10 generations. Also add consecutive failure detection (stops
after 3 in a row).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…timeout

- Detect OAuth vs API key via ANTHROPIC_API_KEY env var
- --generations N directly sets iteration count (OAuth/subscription users)
- --budget $N estimates generations at ~$0.50/gen (API key users)
- Default 10 generations when neither specified
- Bump evolve Claude call timeout from 120s to 300s (large prompts)
- Fix infinite while True → bounded for loop

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add mirofish/ package that connects to MiroFish multi-agent simulation
engine for generating synthetic market scenarios. Strategies are now
evaluated across 8 predefined scenarios (fed hike, tech crash, energy
crisis, recession, bull euphoria, flash crash, inflation, sector rotation).

New CLI flags:
  backtest.py --scenario NAME     Run on single MiroFish scenario
  backtest.py --stress-test       Run on real data + all scenarios
  generate.py --evolve --stress-test  Evolve for robustness

Includes fallback mode — generates synthetic data from scenario seeds
without requiring MiroFish to be running (uses sentiment modulation
on historical prices). Full MiroFish Docker setup also included.

Composite scoring: 0.6 * real_score + 0.4 * mean(scenario_scores)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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