Market Candlestick & AI Pattern Scanner (yfinance-ta-patterns)
High-performance Python library and CLI that downloads multi-asset market data via yfinance, detects TA-Lib candlestick patterns, and enriches raw signals using an AI/Quant Confluence Engine to generate probabilistic confidence scores, trade setups, and LLM-ready market briefs.
Compatible with Python 3.12, 3.13, and 3.14.
Key Features
- Multi-Asset Data Loader: Universal fetching and candle normalization for stocks (
AAPL,NVDA), crypto (BTC-USD), commodities (GC=F), indices (^GSPC), and forex pairs (EURUSD). - TA-Lib Pattern Detection: Full recognition engine across 60+ classic candlestick patterns with date-filtering and timeframe resampling.
- AI Pattern Confidence Scorer: Probabilistic score ($0.0 - 1.0$) evaluating multi-factor confluence:
- Multi-EMA trend alignment (20, 50, 200 EMA)
- Relative Volume surge (RVOL)
- RSI momentum exhaustion & divergence
- Volatility expansion (ATR 14) & candle body dominance
- Automated Trade Setups: Computes entry price, ATR-based invalidation stop-loss, and multi-tier take-profit targets (1.5x / 3.0x risk/reward).
- AI Market Analyst & LLM Integration: Generates executive markdown briefs, JSON payloads, and engineered prompts tailored for external AI agents (GPT-4o, Claude 3.5, Gemini, Ollama).
- Quantitative Pattern Ranking: Built-in vectorized backtester ranking patterns by win rate, Sharpe ratio, and total profit/loss.
Quick start
1. Installation
# Recommended from PyPI:
pip install yfinance-ta-patterns
# Or install from source:
git clone https://github.com/eminsk/yfinance-ta-patterns.git
cd yfinance-ta-patterns
pip install -e .
2. Run CLI
# Detect a single pattern with classic output
yftp --pattern HAMMER --symbol AAPL --timeframe 1h --period 60d
# Scan all patterns on crypto with AI Confluence Scoring
yftp --all-patterns --symbol BTC-USD --timeframe 4h --period 60d --ai --min-confidence 0.65
# Generate an Executive AI Analyst Brief in Markdown
yftp --all-patterns --symbol NVDA --timeframe 15m --period 10d --ai-analyst --format markdown
# Generate an LLM-ready prompt template for GPT-4o / Claude
yftp --all-patterns --symbol EURUSD --timeframe 1h --period 60d --prompt
CLI Reference
yfinance-ta-patterns [-h] [-v] (--pattern PATTERN | --all-patterns)
[--symbol SYMBOL] [--period PERIOD] [--timeframe TIMEFRAME]
[--date YYYY-MM-DD] [--start-date YYYY-MM-DD] [--end-date YYYY-MM-DD]
[--ai] [--min-confidence MIN_CONFIDENCE]
[--ai-analyst] [--prompt] [--format {text,json,markdown}]
Options
| Flag | Description |
|---|---|
-v, --version |
Show package version. |
--pattern |
Single candlestick pattern (e.g. HAMMER, DOJI, CDLKICKING). |
--all-patterns |
Scan and display signals for all available candlestick patterns. |
--symbol |
Ticker symbol (e.g. AAPL, BTC-USD, GC=F, EURUSD). |
--period |
History period (5d, 60d, 1y, max). |
--timeframe |
Interval alias (M1, M5, M15, M30, H1, H4, D1) or yfinance interval (1m, 5m, 15m, 1h, 4h, 1d). |
--date |
Filter signals for a specific date (YYYY-MM-DD). |
--start-date / --end-date |
Date range filter (YYYY-MM-DD). |
--ai |
Enrich detected patterns with AI confidence scoring, signal grade, and trade setups. |
--min-confidence |
Minimum confidence threshold for AI scoring ($0.0$ to $1.0$, default: $0.0$). |
--ai-analyst |
Run executive AI market analysis with synthesis and trade setups. |
--prompt |
Generate an LLM prompt ready to pass to ChatGPT, Claude, or local LLMs. |
--format |
Output format: text (default), json, or markdown. |
Python API
1. Universal Multi-Asset Data Loader (MarketDataLoader)
Fetches and normalizes OHLC data across equities, crypto, forex, and commodities:
from yfinance_ta_patterns import MarketDataLoader
# Stocks
loader = MarketDataLoader(symbol="NVDA", period="60d", interval="1h")
df = loader.get_data()
# Crypto
crypto_loader = MarketDataLoader(symbol="BTC-USD", period="30d", interval="15m")
crypto_df = crypto_loader.get_data()
# Forex (ForexDataLoader is fully compatible alias)
from yfinance_ta_patterns import ForexDataLoader
forex_loader = ForexDataLoader(symbol="EURUSD", period="60d", interval="1h")
forex_df = forex_loader.get_data()
2. AI Pattern Confidence Scorer (AIPatternScorer)
Evaluates technical confluence (trend, momentum, volume, volatility) and builds complete risk-managed trade setups:
from yfinance_ta_patterns import MarketDataLoader, AIPatternScorer
data = MarketDataLoader("AAPL", period="60d", interval="1d").get_data()
scorer = AIPatternScorer(data)
scored_signals = scorer.score_all_active(min_confidence=0.60)
for sig in scored_signals:
print(f"Pattern: {sig.pattern_name}")
print(f"Confidence: {sig.confidence * 100:.1f}% ({sig.grade.value})")
print(f"Action: {sig.action}")
if sig.setup:
print(f"Entry: {sig.setup.entry_price:.2f}")
print(f"Stop Loss: {sig.setup.stop_loss:.2f}")
print(f"Target 1: {sig.setup.take_profit_1:.2f} (R:R {sig.setup.risk_reward_ratio:.1f})")
print("Confluences:", ", ".join(sig.confluences))
print("-" * 40)
3. AI Market Analyst & LLM Prompting (AIMarketAnalyst)
Generates structured briefs and prompt templates for external LLM reasoning agents:
from yfinance_ta_patterns import MarketDataLoader, AIMarketAnalyst
data = MarketDataLoader("BTC-USD", period="30d", interval="4h").get_data()
analyst = AIMarketAnalyst(data, symbol="BTC-USD")
results = analyst.analyze(min_confidence=0.65)
# 1. Executive Markdown Brief
brief = analyst.generate_brief(results)
print(brief)
# 2. Prompt for GPT-4o / Claude / Local LLM
llm_prompt = analyst.to_llm_prompt(results)
# 3. JSON Payload for APIs / Microservices
json_data = analyst.to_json(results)
4. Quantitative Backtesting & Pattern Ranking (PatternRankingTester)
Tests all candlestick patterns and ranks them by quantitative performance metrics:
from yfinance_ta_patterns import MarketDataLoader, PatternRankingTester
data = MarketDataLoader("EURUSD", period="60d", interval="1h").get_data()
tester = PatternRankingTester(data, initial_capital=10000.0, position_size=100.0)
results = tester.test_all_patterns()
top_patterns = tester.get_top_patterns(5)
for r in top_patterns:
print(
f"{r.pattern_name}: Win Rate={r.win_rate:.1f}%, PnL={r.total_pnl:.2f}, Sharpe={r.sharpe_ratio:.2f}"
)
# Export to CSV
tester.export_results("pattern_ranking.csv")
Development & Testing
Run the test suite and quality checks:
# Run pytest across test suite
uv run --extra dev pytest -v
# Linter and formatting check
uv run --extra dev ruff check .
uv run --extra dev ruff format --check .
# Static type check
uv run --extra dev mypy yfinance_ta_patterns
# Build source distribution and binary wheel
uv build
🌐 High-Performance Systems Ecosystem
yfinance-ta-patterns is developed by @eminsk as part of an open-source engineering ecosystem:
- ⚡ NanoGEMM — Minimalist, bare-metal AVX2+FMA SIMD matrix multiplication engine in ~100KB for sub-microsecond CPU neural network inference (
pip install nanogemm). - 🎥 screenvideo — Lightweight desktop screen recorder with WASAPI audio and a standalone pure x64 Flat Assembler (FASM) native edition.
- 📊 xlsx_vievers — Desktop spreadsheet processor with 80+ formula functions, Chart Wizard, and hardware-accelerated SIMD SSE2 math engine.
- 🔍 StackOverflowAPI — Bilingual desktop client for Stack Overflow built with CustomTkinter and native FASM x64 search client.
License
MIT License. See LICENSE for details.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yfinance_ta_patterns-0.2.0.tar.gz.
File metadata
- Download URL: yfinance_ta_patterns-0.2.0.tar.gz
- Upload date:
- Size: 29.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe539963460a02d97e45344596b2de5484c26e10fae890264763931a6054efbf
|
|
| MD5 |
a5054e33a77344104ecb638dcc61e795
|
|
| BLAKE2b-256 |
755fc69e943dcfa43ef562c781e86bb8c256342f77d1193d81078097dc05fc06
|
File details
Details for the file yfinance_ta_patterns-0.2.0-py3-none-any.whl.
File metadata
- Download URL: yfinance_ta_patterns-0.2.0-py3-none-any.whl
- Upload date:
- Size: 23.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c395fdafec32f54cc55f1276afa5f841c2f7a903ac52eba3de8d8460318d1f8f
|
|
| MD5 |
4af578f670c89f9fa07891823c3dff94
|
|
| BLAKE2b-256 |
d3cfcc5d7077c1cdfd0ba9a52b238f1b2e9aa259139fb9f817d06da665c2d0f0
|