Skip to main content

Professional quantitative trading research platform with ML-powered backtesting, multi-source options analysis, portfolio management, and interactive Plotly visualizations

Project description

QuantLab - Quantitative Trading Research Platform

PyPI version Documentation Status Python Version License Release

A quantitative trading research platform powered by Microsoft's Qlib, designed for systematic alpha generation and backtesting.

๐Ÿ“š Full Documentation | ๐Ÿš€ Quick Start Guide | ๐Ÿ“– API Reference

๐Ÿ“ Project Structure

quantlab/
โ”œโ”€โ”€ README.md                       # This file
โ”œโ”€โ”€ .gitignore                      # Git ignore rules
โ”œโ”€โ”€ .venv/                          # Python virtual environment (uv)
โ”‚
โ”œโ”€โ”€ docs/                           # Documentation
โ”‚   โ”œโ”€โ”€ BACKTEST_SUMMARY.md         # Backtest results analysis
โ”‚   โ”œโ”€โ”€ ALPHA158_SUMMARY.md         # Alpha158 features documentation
โ”‚   โ”œโ”€โ”€ ALPHA158_CORRECTED.md       # Alpha158 corrections
โ”‚   โ”œโ”€โ”€ USE_QLIB_ALPHA158.md        # Guide for using Alpha158
โ”‚   โ””โ”€โ”€ QUANTMINI_README.md         # QuantMini data setup
โ”‚
โ”œโ”€โ”€ scripts/                        # Utility scripts
โ”‚   โ”œโ”€โ”€ data/                       # Data processing
โ”‚   โ”‚   โ”œโ”€โ”€ convert_to_qlib.py      # Convert data to qlib format
โ”‚   โ”‚   โ”œโ”€โ”€ refresh_today_data.py   # Update latest data
โ”‚   โ”‚   โ””โ”€โ”€ quantmini_setup.py      # QuantMini data setup
โ”‚   โ”œโ”€โ”€ analysis/                   # Analysis tools
โ”‚   โ”‚   โ””โ”€โ”€ visualize_results.py    # Backtest visualization
โ”‚   โ””โ”€โ”€ tests/                      # Test scripts
โ”‚       โ”œโ”€โ”€ test_qlib_alpha158.py   # Test Alpha158 features
โ”‚       โ”œโ”€โ”€ test_stocks_minute_fix.py
โ”‚       โ””โ”€โ”€ enable_alpha158.py
โ”‚
โ”œโ”€โ”€ configs/                        # Qlib workflow configurations
โ”‚   โ”œโ”€โ”€ lightgbm_external_data.yaml # Full universe (all stocks)
โ”‚   โ”œโ”€โ”€ lightgbm_fixed_dates.yaml   # 2024 only (date filter)
โ”‚   โ””โ”€โ”€ lightgbm_liquid_universe.yaml # Filtered liquid stocks
โ”‚
โ”œโ”€โ”€ results/                        # Backtest outputs
โ”‚   โ”œโ”€โ”€ visualizations/             # Charts and plots
โ”‚   โ”‚   โ””โ”€โ”€ backtest_visualization.png
โ”‚   โ””โ”€โ”€ mlruns/                     # MLflow experiment tracking
โ”‚       โ””โ”€โ”€ 489214785307856385/     # Experiment runs
โ”‚
โ”œโ”€โ”€ data/                           # Local data storage
โ”‚   โ”œโ”€โ”€ parquet/                    # Raw parquet files
โ”‚   โ””โ”€โ”€ metadata/                   # Metadata files
โ”‚
โ”œโ”€โ”€ notebooks/                      # Jupyter notebooks
โ”‚   โ””โ”€โ”€ workflow_by_code.ipynb      # Qlib workflow examples
โ”‚
โ”œโ”€โ”€ config/                         # System configuration
โ”‚   โ””โ”€โ”€ system_profile.yaml         # System settings
โ”‚
โ””โ”€โ”€ qlib_repo/                      # Qlib source (gitignored, 828MB)
    โ””โ”€โ”€ (Microsoft qlib clone)

๐Ÿš€ Quick Start

Installation from PyPI

# Install from PyPI
pip install quantlabs

# Or using uv (recommended)
uv pip install quantlabs

# Verify installation
quantlab --version
quantlab --help

Development Setup

# Clone the repository
git clone https://github.com/nittygritty-zzy/quantlab.git
cd quantlab

# Using uv (recommended)
uv venv
source .venv/bin/activate
uv sync

# Or using pip
python -m venv .venv
source .venv/bin/activate
pip install -e .

2. Prepare Data

# Option A: Use external data (QuantMini on /Volumes/sandisk)
# Data is already at: /Volumes/sandisk/quantmini-data/data/qlib/stocks_daily

# Option B: Download community data
wget https://github.com/chenditc/investment_data/releases/latest/download/qlib_bin.tar.gz
mkdir -p ~/.qlib/qlib_data/cn_data
tar -zxvf qlib_bin.tar.gz -C ~/.qlib/qlib_data/cn_data --strip-components=1

3. Run a Backtest

# Navigate to qlib examples (if using qlib_repo)
cd qlib_repo/examples

# Run workflow with external data
uv run qrun ../../configs/lightgbm_liquid_universe.yaml

4. Visualize Results

# Update the experiment ID in visualize_results.py, then:
uv run python scripts/analysis/visualize_results.py

Results will be saved to results/visualizations/backtest_visualization.png

๐Ÿ’ผ QuantLab CLI - Real-World Use Cases

QuantLab includes a powerful CLI for portfolio management, market analysis, and data queries.

๐ŸŽฌ Use Case 1: Building a Tech Portfolio

Scenario: Create and manage a diversified tech portfolio with FAANG+ stocks.

# Initialize QuantLab
quantlab init

# Create a tech portfolio
quantlab portfolio create tech_giants --name "FAANG+ Portfolio" \
    --description "Large-cap tech companies"

# Add positions with target weights
quantlab portfolio add tech_giants AAPL GOOGL MSFT --weight 0.20
quantlab portfolio add tech_giants META AMZN --weight 0.15
quantlab portfolio add tech_giants NVDA --weight 0.10

# View your portfolio
quantlab portfolio show tech_giants

# Expected output:
# ๐Ÿ“Š Portfolio: FAANG+ Portfolio
# ๐Ÿ“ˆ Positions: 6
# โ”œโ”€ AAPL    โ”‚ Weight: 20.00% โ”‚ Shares: -   โ”‚ Cost Basis: -
# โ”œโ”€ GOOGL   โ”‚ Weight: 20.00% โ”‚ Shares: -   โ”‚ Cost Basis: -
# โ”œโ”€ MSFT    โ”‚ Weight: 20.00% โ”‚ Shares: -   โ”‚ Cost Basis: -
# โ”œโ”€ META    โ”‚ Weight: 15.00% โ”‚ Shares: -   โ”‚ Cost Basis: -
# โ”œโ”€ AMZN    โ”‚ Weight: 15.00% โ”‚ Shares: -   โ”‚ Cost Basis: -
# โ””โ”€ NVDA    โ”‚ Weight: 10.00% โ”‚ Shares: -   โ”‚ Cost Basis: -
# Total Weight: 100.00%

๐Ÿ“Š Use Case 2: Real Position Tracking

Scenario: Track actual shares purchased at specific cost basis.

# Update positions with real trade data
quantlab portfolio update tech_giants AAPL \
    --shares 50 \
    --cost-basis 178.25 \
    --notes "Bought on Q4 dip"

quantlab portfolio update tech_giants GOOGL \
    --shares 30 \
    --cost-basis 142.50 \
    --notes "Post-earnings entry"

quantlab portfolio update tech_giants NVDA \
    --shares 20 \
    --cost-basis 485.00 \
    --notes "AI boom position"

# View updated portfolio
quantlab portfolio show tech_giants

# Expected output:
# ๐Ÿ“Š Portfolio: FAANG+ Portfolio
# ๐Ÿ“ˆ Positions: 6
# โ”œโ”€ AAPL    โ”‚ Weight: 20.00% โ”‚ Shares: 50  โ”‚ Cost: $178.25 โ”‚ "Bought on Q4 dip"
# โ”œโ”€ GOOGL   โ”‚ Weight: 20.00% โ”‚ Shares: 30  โ”‚ Cost: $142.50 โ”‚ "Post-earnings entry"
# โ”œโ”€ NVDA    โ”‚ Weight: 10.00% โ”‚ Shares: 20  โ”‚ Cost: $485.00 โ”‚ "AI boom position"
# Total Investment: $22,812.50

๐Ÿ” Use Case 3: Analyzing a Stock Before Purchase

Scenario: Deep-dive analysis on ORCL before adding to portfolio.

# Comprehensive analysis with all data sources
quantlab analyze ticker ORCL \
    --include-fundamentals \
    --include-options \
    --include-sentiment \
    --include-technicals \
    --output results/orcl_analysis.json

# Expected output:
# ๐Ÿ” Analyzing ORCL (Oracle Corporation)
#
# ๐Ÿ“ˆ Price Information:
#    Current: $145.50
#    Change: +2.3% ($3.25)
#    Volume: 5,234,567
#
# ๐Ÿ’ฐ Fundamentals:
#    Market Cap: $401.2B
#    P/E Ratio: 28.5
#    Forward P/E: 21.2
#    Revenue Growth: 7.2%
#    Profit Margin: 21.5%
#    Debt/Equity: 2.84
#
# ๐Ÿ“Š Options Activity:
#    Put/Call Ratio: 0.78 (Bullish)
#    Implied Volatility: 22.5%
#    Next Earnings: 2025-03-15 (30 days)
#
# ๐Ÿ“ฐ Sentiment Analysis:
#    Score: 0.72 (Positive)
#    Articles: 45 (7 days)
#    Buzz: High
#
# ๐ŸŽฏ Analyst Consensus:
#    Rating: Buy (12) / Hold (8) / Sell (2)
#    Target Price: $165.00 (+13.4%)
#
# โœ… Analysis complete โ†’ results/orcl_analysis.json

# Visualize price action
quantlab visualize price ORCL --period 90d --chart-type candlestick
quantlab visualize price ORCL --period 1year --chart-type line

# Quick decision check
quantlab lookup get company ORCL
quantlab lookup get ratings ORCL

๐Ÿ“ˆ Use Case 4: Portfolio-Wide Analysis

Scenario: Analyze all positions in your tech portfolio.

# Analyze entire portfolio
quantlab analyze portfolio tech_giants \
    --include-options \
    --aggregate-metrics \
    --output results/tech_giants_analysis.json

# Expected output:
# ๐Ÿ“Š Analyzing Portfolio: FAANG+ Portfolio (6 positions)
#
# Processing: [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ] 6/6
#
# Individual Analyses:
# โœ“ AAPL  โ”‚ Score: 82/100 โ”‚ Sentiment: Positive โ”‚ Analysts: 85% Buy
# โœ“ GOOGL โ”‚ Score: 78/100 โ”‚ Sentiment: Positive โ”‚ Analysts: 80% Buy
# โœ“ MSFT  โ”‚ Score: 88/100 โ”‚ Sentiment: Very Positive โ”‚ Analysts: 90% Buy
# โœ“ META  โ”‚ Score: 75/100 โ”‚ Sentiment: Neutral โ”‚ Analysts: 75% Buy
# โœ“ AMZN  โ”‚ Score: 81/100 โ”‚ Sentiment: Positive โ”‚ Analysts: 82% Buy
# โš  NVDA  โ”‚ Score: 68/100 โ”‚ Sentiment: Mixed โ”‚ Analysts: 70% Buy
#
# Portfolio Metrics:
# Total Value: $52,450
# Avg P/E: 32.5
# Avg Sentiment: 0.68 (Positive)
# Portfolio Beta: 1.15
# Weighted Analyst Rating: 80% Buy
#
# โš ๏ธ Alerts:
# - NVDA showing weakness (consider reducing position)
# - MSFT strongest performer (98% of analysts bullish)

# Visualize portfolio performance comparison
quantlab visualize compare AAPL GOOGL MSFT META AMZN NVDA \
    --period 90d \
    --normalize \
    --output results/tech_giants_comparison.html

๐Ÿ”Ž Use Case 5: Querying Historical Data

Scenario: Research historical price patterns for backtesting.

# Query daily stock data
quantlab data query AAPL GOOGL MSFT \
    --start 2024-01-01 \
    --end 2025-01-15 \
    --type stocks_daily \
    --limit 100

# Expected output:
# ๐Ÿ“Š Querying data for 3 tickers...
#
# AAPL (Apple Inc.)
# Date Range: 2024-01-01 to 2025-01-15 (252 trading days)
#
# Recent Data (last 5 days):
# Date       โ”‚ Open    โ”‚ High    โ”‚ Low     โ”‚ Close   โ”‚ Volume
# 2025-01-15 โ”‚ $180.25 โ”‚ $182.50 โ”‚ $179.80 โ”‚ $181.75 โ”‚ 52.3M
# 2025-01-14 โ”‚ $179.50 โ”‚ $181.25 โ”‚ $178.90 โ”‚ $180.25 โ”‚ 48.7M
# ...
#
# Performance: +15.3% YTD
# Volatility: 18.5% (annualized)

# Visualize historical price patterns
quantlab visualize price AAPL --period 2year --chart-type candlestick
quantlab visualize price AAPL --interval 5min --period 5d --chart-type line

# Check available data coverage
quantlab data check

# Expected output:
# ๐Ÿ“ Parquet Data Availability
# โœ“ stocks_daily    โ”‚ 13,187 tickers โ”‚ 2024-09-01 to 2025-10-15 (442 days)
# โœ“ stocks_minute   โ”‚ 8,523 tickers  โ”‚ Last 90 days
# โœ“ options_daily   โ”‚ 3,245 tickers  โ”‚ 2024-09-01 to 2025-10-15
# โœ— options_minute  โ”‚ Not available

๐Ÿฆ Use Case 6: Maintaining Reference Data

Scenario: Keep company info and analyst ratings up-to-date.

# Initialize lookup tables
quantlab lookup init

# Refresh data for your portfolio
quantlab lookup refresh portfolio tech_giants

# Expected output:
# ๐Ÿ”„ Refreshing data for 6 tickers in tech_giants...
#
# Company Info:
# โœ“ AAPL  - Apple Inc. (Technology - Consumer Electronics)
# โœ“ GOOGL - Alphabet Inc. (Technology - Internet Services)
# โœ“ MSFT  - Microsoft Corporation (Technology - Software)
# โœ“ META  - Meta Platforms Inc. (Technology - Social Media)
# โœ“ AMZN  - Amazon.com Inc. (Consumer Cyclical - Internet Retail)
# โœ“ NVDA  - NVIDIA Corporation (Technology - Semiconductors)
#
# Analyst Ratings:
# โœ“ AAPL  - 35 analysts (Buy: 28, Hold: 6, Sell: 1) Target: $210
# โœ“ GOOGL - 42 analysts (Buy: 35, Hold: 6, Sell: 1) Target: $165
# โœ“ MSFT  - 48 analysts (Buy: 43, Hold: 4, Sell: 1) Target: $450
# โœ“ META  - 38 analysts (Buy: 28, Hold: 8, Sell: 2) Target: $520
# โœ“ AMZN  - 45 analysts (Buy: 38, Hold: 6, Sell: 1) Target: $215
# โœ“ NVDA  - 40 analysts (Buy: 32, Hold: 7, Sell: 1) Target: $850
#
# โœ… Refresh complete (6/6 successful)

# View stored data
quantlab lookup stats

# Expected output:
# ๐Ÿ“Š Lookup Tables Statistics
#
# Company Information: 6 companies
# Analyst Ratings: 6 tickers (248 total analysts)
# Treasury Rates: Current (updated: 2025-10-15)
# Last Updated: 2025-10-15 14:32:15

๐ŸŽฏ Use Case 7: Multi-Portfolio Strategy

Scenario: Manage multiple portfolios for different strategies.

# Create portfolios for different strategies
quantlab portfolio create growth --name "High Growth" \
    --description "Growth stocks with P/E > 30"

quantlab portfolio create value --name "Value Plays" \
    --description "Undervalued stocks with P/E < 15"

quantlab portfolio create dividend --name "Dividend Income" \
    --description "High dividend yield stocks"

# Add different stocks to each
quantlab portfolio add growth NVDA TSLA SNOW --weight 0.33
quantlab portfolio add value BAC JPM WFC --weight 0.33
quantlab portfolio add dividend T VZ SO --weight 0.33

# View all portfolios
quantlab portfolio list

# Expected output:
# ๐Ÿ“Š Your Portfolios
#
# Portfolio ID    โ”‚ Name              โ”‚ Positions โ”‚ Total Weight โ”‚ Last Updated
# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
# tech_giants     โ”‚ FAANG+ Portfolio  โ”‚ 6         โ”‚ 100.00%      โ”‚ 2025-10-15
# growth          โ”‚ High Growth       โ”‚ 3         โ”‚ 99.00%       โ”‚ 2025-10-15
# value           โ”‚ Value Plays       โ”‚ 3         โ”‚ 99.00%       โ”‚ 2025-10-15
# dividend        โ”‚ Dividend Income   โ”‚ 3         โ”‚ 99.00%       โ”‚ 2025-10-15
#
# Total Portfolios: 4
# Total Unique Positions: 15

๐Ÿ”ฌ Use Case 8: Options Strategy Research

Scenario: Research options opportunities for covered calls.

# Analyze ticker specifically for options
quantlab analyze ticker AAPL \
    --include-options \
    --no-fundamentals \
    --no-sentiment \
    --output results/aapl_options.json

# Expected output:
# ๐Ÿ” Options Analysis: AAPL
#
# Current Price: $181.75
#
# Near-Term Expiration (30 days):
# Call Options (Covered Call Candidates):
# Strike โ”‚ Premium โ”‚ IV    โ”‚ Delta โ”‚ Break-even โ”‚ Return
# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
# $185   โ”‚ $3.85   โ”‚ 21.2% โ”‚ 0.45  โ”‚ $185.00    โ”‚ 2.1%
# $190   โ”‚ $2.15   โ”‚ 19.8% โ”‚ 0.28  โ”‚ $190.00    โ”‚ 4.6%
# $195   โ”‚ $0.95   โ”‚ 18.5% โ”‚ 0.15  โ”‚ $195.00    โ”‚ 7.3%
#
# Put Options (Cash-Secured Put Candidates):
# Strike โ”‚ Premium โ”‚ IV    โ”‚ Delta โ”‚ Net Cost   โ”‚ Yield
# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
# $175   โ”‚ $2.80   โ”‚ 22.5% โ”‚ -0.35 โ”‚ $172.20    โ”‚ 1.6%
# $170   โ”‚ $1.45   โ”‚ 20.1% โ”‚ -0.20 โ”‚ $168.55    โ”‚ 0.9%
#
# Volatility Metrics:
# Current IV: 21.2%
# Historical Vol (30d): 18.5%
# IV Percentile: 62% (Elevated)
#
# ๐Ÿ’ก Suggestion: Good conditions for selling premium
#    IV elevated vs historical - consider covered calls at $190 strike

# Visualize options payoff diagrams
quantlab visualize options long_call --current-price 181.75 --strike 190 --premium 2.15
quantlab visualize options bull_call_spread \
    --current-price 181.75 --strike1 185 --strike2 195 --premium 1.70

๐Ÿ“… Use Case 9: Regular Portfolio Review

Scenario: Monthly portfolio review workflow.

# Step 1: Refresh all market data
quantlab lookup refresh portfolio tech_giants

# Step 2: Get comprehensive analysis
quantlab analyze portfolio tech_giants --aggregate-metrics

# Step 3: Visualize portfolio performance
quantlab visualize compare AAPL GOOGL MSFT META AMZN NVDA --period 30d --normalize

# Step 4: Review individual positions
quantlab visualize price AAPL --period 90d --chart-type candlestick
quantlab visualize price NVDA --period 90d --chart-type candlestick

# Step 5: Check for rebalancing needs
quantlab portfolio show tech_giants

# Step 6: Look for new opportunities
quantlab data tickers --type stocks_daily | grep -E "^[A-Z]{1,4}$" | head -20
quantlab analyze ticker CRM --include-fundamentals
quantlab visualize price CRM --period 90d --chart-type candlestick

# Step 7: Update positions based on analysis
quantlab portfolio update tech_giants NVDA --weight 0.05 --notes "Reduced - valuation concerns"
quantlab portfolio add tech_giants CRM --weight 0.05 --notes "New position - cloud growth"

# Step 8: Export for records
quantlab analyze portfolio tech_giants --output results/monthly_review_2025_10.json

๐Ÿšจ Use Case 10: Risk Monitoring

Scenario: Monitor portfolio risk daily.

# Create a monitoring script
cat > scripts/daily_monitor.sh << 'EOF'
#!/bin/bash
DATE=$(date +%Y-%m-%d)

echo "๐Ÿ” Daily Portfolio Monitor - $DATE"
echo "=================================="

# Analyze each portfolio
for portfolio in tech_giants growth value dividend; do
    echo ""
    echo "๐Ÿ“Š Portfolio: $portfolio"
    quantlab analyze portfolio $portfolio \
        --include-options \
        --output "results/monitoring/${portfolio}_${DATE}.json" 2>&1 | \
        grep -E "(Score:|Sentiment:|Analysts:|โš |โŒ)"
done

# Check treasury rates for risk-free rate
echo ""
echo "๐Ÿ“ˆ Current Treasury Rates:"
quantlab lookup get treasury 10y

echo ""
echo "โœ… Monitoring complete"
EOF

chmod +x scripts/daily_monitor.sh

# Run daily monitoring
./scripts/daily_monitor.sh

# Expected output:
# ๐Ÿ” Daily Portfolio Monitor - 2025-10-15
# ==================================
#
# ๐Ÿ“Š Portfolio: tech_giants
# โœ“ AAPL  โ”‚ Score: 82/100 โ”‚ Sentiment: Positive
# โœ“ GOOGL โ”‚ Score: 78/100 โ”‚ Sentiment: Positive
# โš  NVDA  โ”‚ Score: 68/100 โ”‚ Sentiment: Mixed
#
# ๐Ÿ“ˆ Current Treasury Rates:
# 10-Year Treasury: 4.25% (as of 2025-10-15)
#
# โœ… Monitoring complete

๐Ÿ“Š Available Configurations

1. Liquid Universe (Recommended)

  • File: configs/lightgbm_liquid_universe.yaml
  • Universe: 13,187 stocks (filtered - no warrants, units)
  • Period: Sept 2024 - Sept 2025
  • Best for: Realistic backtesting with tradable stocks

2. Fixed Dates

  • File: configs/lightgbm_fixed_dates.yaml
  • Universe: All stocks
  • Period: July 2024 - Dec 2024
  • Best for: Testing on stable period

3. Full Universe

  • File: configs/lightgbm_external_data.yaml
  • Universe: All 14,310 instruments (includes warrants, penny stocks)
  • Period: Sept 2024 - Sept 2025
  • Best for: Maximum alpha discovery (but risky)

๐ŸŽฏ Key Metrics from Latest Runs

Configuration IC Rank IC Sharpe Max DD Universe Size
Liquid Universe 0.066 -0.006 3.94 -39.2% 13,187
Fixed Dates 0.079 -0.008 4.54 -35.3% 14,310
Full Universe 0.080 -0.004 2.98 -41.7% 14,310

IC (Information Coefficient): 0.06-0.08 is good - shows predictive power Rank IC: Near zero - model struggles with relative ranking Sharpe Ratio: 2.98-4.54 - excellent risk-adjusted returns

๐Ÿ“Š Visualization Capabilities

QuantLab includes comprehensive interactive visualization tools powered by Plotly.

Price Charts

# Candlestick charts (daily data)
quantlab visualize price AAPL --period 90d --chart-type candlestick

# Line charts with volume
quantlab visualize price AAPL --period 1year --chart-type line

# Intraday charts (5min, 15min, 1hour intervals)
quantlab visualize price AAPL --interval 5min --period 5d --chart-type candlestick
quantlab visualize price NVDA --interval 1hour --period 30d --chart-type line

Features:

  • Multiple timeframes: 1d, 5d, 30d, 90d, 1year, 2year
  • Intraday intervals: 1min, 5min, 15min, 1hour
  • Categorical x-axis for gap-free intraday charts
  • Timezone-aware (US Eastern Time)
  • Regular market hours filtering (9:30 AM - 4:00 PM ET)

Example Charts:

Multi-Ticker Comparison

# Compare normalized performance
quantlab visualize compare AAPL GOOGL MSFT --period 90d --normalize

# Absolute price comparison
quantlab visualize compare AAPL GOOGL MSFT --period 1year

Example Chart:

Options Payoff Diagrams

# Single leg strategies
quantlab visualize options long_call --current-price 180 --strike 190 --premium 2.15
quantlab visualize options long_put --current-price 180 --strike 175 --premium 2.80

# Spread strategies
quantlab visualize options bull_call_spread \
    --current-price 180 --strike1 185 --strike2 195 --premium 1.70

quantlab visualize options iron_condor \
    --current-price 180 --strike1 170 --strike2 175 --strike3 195 --strike4 200

Available Strategies:

  • Single: long_call, long_put, short_call, short_put
  • Spreads: bull_call_spread, bear_put_spread, iron_condor, butterfly
  • Volatility: long_straddle, short_straddle, long_strangle, short_strangle

Example Chart:

Backtest Results

# Visualize backtest performance
quantlab visualize backtest results/mlruns/[experiment_id]

Metrics Displayed:

  • Cumulative returns vs benchmark
  • Drawdown analysis
  • Rolling Sharpe ratio
  • Win/loss distribution
  • Monthly returns heatmap

๐Ÿ“š Documentation

๐Ÿ”ง Data Setup

External Data Location

/Volumes/sandisk/quantmini-data/data/qlib/stocks_daily/
โ”œโ”€โ”€ calendars/day.txt           # Trading calendar (442 days)
โ”œโ”€โ”€ instruments/
โ”‚   โ”œโ”€โ”€ all.txt                 # All 14,310 instruments
โ”‚   โ””โ”€โ”€ liquid_stocks.txt       # Filtered 13,187 instruments
โ””โ”€โ”€ features/                   # Stock price data (OHLCV)

Creating Custom Universe Filters

# See scripts/data/ for examples
# Filter by:
# - Market cap
# - Average volume
# - Exclude warrants/units
# - Sector/industry

๐Ÿงช Testing

# Test Alpha158 features
python scripts/tests/test_qlib_alpha158.py

# Test data conversion
python scripts/data/convert_to_qlib.py

# Refresh latest data
python scripts/data/refresh_today_data.py

๐Ÿ” Next Steps

Improve Model Performance

  1. Fix Rank IC - Try ensemble models (XGBoost, TabNet, LSTM)
  2. Better features - Add momentum, volatility, cross-sectional features
  3. Risk controls - Add position limits, volatility weighting

Data Quality

  1. Validate corporate actions (splits, dividends)
  2. Check for survivorship bias
  3. Add liquidity filters (min volume, market cap)

Alternative Strategies

  1. Market-neutral long-short
  2. Factor-based weighting
  3. Multi-timeframe approaches

๐Ÿ“ Notes

  • Data Source: External data from QuantMini (US stocks, daily, 2024-2025)
  • ML Framework: Qlib by Microsoft Research
  • Models Tested: LightGBM with Alpha158 features
  • Tracking: MLflow for experiment management

โš ๏ธ Known Issues

  1. Unrealistic backtest returns - Investigating data quality and backtest engine
  2. Rank IC near zero - Model can predict returns but not rank stocks well
  3. High volatility - Some instruments show extreme price movements
  4. See BACKTEST_SUMMARY.md for detailed analysis

๐Ÿค Contributing

This is a research project. Key areas for improvement:

  • Better universe filters
  • Alternative features
  • Improved ranking models
  • Risk management strategies

๐Ÿ“„ License

Research and educational purposes.

๐Ÿ”— Resources

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quantlabs-0.3.0.tar.gz (656.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quantlabs-0.3.0-py3-none-any.whl (173.7 kB view details)

Uploaded Python 3

File details

Details for the file quantlabs-0.3.0.tar.gz.

File metadata

  • Download URL: quantlabs-0.3.0.tar.gz
  • Upload date:
  • Size: 656.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for quantlabs-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f8e6231a0cbb93dfd2f9bb67ac3b3fcbb13000daf58b176b1a9c335417e65ad7
MD5 2efe4937c3ca8624eb94252602ca0332
BLAKE2b-256 b75dba8dbec3b020a0b30f19b886a9e4a8fc9904606a2d8be2c2dfd775f38c99

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantlabs-0.3.0.tar.gz:

Publisher: publish-to-pypi.yml on nittygritty-zzy/quantlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quantlabs-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: quantlabs-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 173.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for quantlabs-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 761c04ac84d8572843af289f1c3627d5700314e9e37f47e645e41c431fcd357c
MD5 1a2b99734e0442778aaa6e56c83f6880
BLAKE2b-256 c2de920ed28f4c1355e3a2c0cd6b88d3f5ef59612ae60f95c298fa4b36ea9fb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for quantlabs-0.3.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on nittygritty-zzy/quantlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page