Automatically discover trading strategies by combining indicator conditions with multi-phase validation and stress testing.
The Strategy Generator is a research tool that accelerates the early stage of trading strategy development. Instead of manually picking indicators and writing signal logic, you feed it a stock symbol (or let it discover trending tickers from financial news), and it randomly assembles indicator conditions into entry and exit signals. Each candidate is validated across three separate data windows and then subjected to a stress-test gauntlet. Only strategies that survive this pipeline are reported, complete with a plain-language Markdown report.
The pipeline has four stages:
-
Data Acquisition -- Download historical OHLCV data from Yahoo Finance, or scan financial news RSS feeds (Bloomberg, CNBC, Reuters, MarketWatch) to discover trending tickers by mention frequency.
-
Strategy Search -- Randomly draw indicator conditions from a library of over 180 boolean conditions across 37 indicator families, combine them into entry and exit signals via AND logic, and run each candidate through a 3-phase backtest. A strategy must beat buy-and-hold on all three windows (in-sample 50%, out-of-sample 25%, holdout 25%) to advance.
-
Stress Testing -- Candidates that pass the 3-window validation enter the gauntlet:
- Walk-Forward Analysis -- The strategy is re-tested in rolling windows to verify consistency across different market phases.
- Monte Carlo Simulation -- Trade returns are reshuffled 200 times to estimate the probability distribution of outcomes.
- Cross-Ticker Testing -- The same entry and exit rules are tested on 10 major ETFs and liquid stocks to detect overfitting.
Each test contributes one point to a confidence score (0-3). Strategies need a score of 2 or higher to be reported.
-
Report Generation -- Every strategy that passes all gates receives a Markdown report with plain-English explanations of what each indicator condition means, a summary of the stress-test results, and caveats about the prototype nature of the tool.
Requires Python 3.12 or later. The project uses uv as the package manager.
git clone <repository-url>
cd strategy-generator
uv syncSpecify a ticker directly:
uv run stratgen --ticker AAPL --start 2015-01-01 --end 2024-01-01Let the tool scan financial news to find trending stocks:
uv run stratgen --auto| Option | Default | Description |
|---|---|---|
--ticker |
(none) | Stock symbol for manual mode |
--auto |
off | Auto-discover tickers from news feeds |
--start |
2015-01-01 | Start date for historical data |
--end |
2024-01-01 | End date for historical data |
--size |
1 | Number of conditions per signal (1-3) |
--min-trades |
5 | Minimum trades per validation window |
--max-attempts |
10000 | Maximum random combinations per ticker |
--no-stress |
off | Skip stress tests (faster but less rigorous) |
--output-dir |
. | Directory for strategy report files |
The generator draws from 37 indicator families, each providing multiple boolean conditions:
RSI, Bollinger Bands, MACD, SMA, EMA, Momentum, Stochastic, ATR, ADX, CCI, Williams %R, Rate of Change, Hull MA, KAMA, Kaufman Efficiency Ratio, Laguerre RSI, OsMA, QQE, Reflex, Schaff Trend Cycle, Volume, Historical Volatility, Chande Momentum Oscillator, Elder Impulse, DPO, QStick, TRIX, Chande Trend Score, TEMA, DEMA, VIDYA, Coppock Curve, TSI, McGinley Dynamic, Candlestick Patterns, Ulcer Index, SR Percent Rank.
uv run pytest tests/ -vFor each passing strategy, two outputs are produced:
- Terminal summary -- The entry conditions, exit conditions, total return, Sharpe ratio, and per-test results.
- Markdown report -- A file named
{TICKER}_strategy_report.mdwith plain-English explanations suitable for non-technical readers.
- Prototype status. This is a research tool, not a production trading system. Strategies it discovers should be treated as prototypes requiring further development.
- Past performance is not indicative of future results. All testing is performed on historical data. Real markets differ.
- Daily data only. The tool uses daily OHLCV data from Yahoo Finance. Intraday strategies are not supported.
- Long-only. The backtesting engine assumes long-only positions. Short selling is not modeled.
- No transaction costs or slippage. Returns do not account for commissions, spreads, or market impact.
- Curve fitting risk. Despite the 3-window validation and stress tests, discovered strategies can still be overfitted. The cross-ticker test provides a reasonable guard, but is not infallible.
- Not investment advice. The Strategy Generator is an educational and research tool. It does not provide investment recommendations.
- yfinance -- Yahoo Finance data
- pandas-ta -- Technical indicators
- vectorbt -- Vectorized backtesting
- feedparser -- RSS feed parsing
- click -- Command-line interface
- pandas / numpy -- Data manipulation
MIT -- see LICENSE for details.