# 1. Activate virtual environment
source .venv/bin/activate
# 2. Run the script
python main.pyYou'll be prompted:
- Do you want to include most active stocks? → Answer
yorn
- Fetches S&P 500 list (~500 stocks)
- Optionally fetches most active stocks (filtered ≥$10B market cap)
- Saves to
input_tickers/
- First run: Fetches data from Yahoo Finance (takes a few minutes for 500+ stocks)
- Same-day reruns: Uses cached data (instant!)
- Cache stored in:
cache/raw_data_YYYY-MM-DD.csv
Creates folder: output_results/YYYY-MM-DD/ with 3 CSV files:
-
by_sell_then_buy.csv
- Best stocks with lowest sell ratings
- Ties broken by highest buy ratings
-
by_sell_then_price_gap.csv
- Best stocks with lowest sell ratings
- Ties broken by best price vs target (most undervalued)
-
by_sell_then_market_cap.csv
- Best stocks with lowest sell ratings
- Ties broken by largest market cap (more stable)
Look for:
total_sell = 0or very low → Few analysts recommend sellingtotal_buy = high→ Many analysts recommend buyingprice_vs_target < 0→ Trading below analyst's low target (potential bargain)price_at_low_end = True→ Currently within ±10% of analyst's low target
Example Good Stock:
ticker: AAPL
current_price: 267.11
target_low: 200.00
total_sell: 0
total_buy: 29
price_vs_target: 67.11 (trading above low target - bullish)
Example Potential Value:
ticker: INTC
current_price: 21.50
target_low: 25.00
total_sell: 2
total_buy: 15
price_vs_target: -3.50 (trading BELOW low target - potential bargain or concern)
- First run: Fetches fresh data
- Subsequent runs: Uses cache (instant)
- Experiment with different analysis without API limits!
- Create a CSV in
input_tickers/ - First column = ticker symbol
- Additional columns optional (name, notes, etc.)
Example input_tickers/my_watchlist.csv:
ticker,name,notes
AAPL,Apple Inc.,Tech leader
MSFT,Microsoft,Cloud growthDelete the cache file for today:
rm cache/raw_data_$(date +%Y-%m-%d).csv
python main.pySee README.md "Adding Custom Sorting Strategies" section
Problem: Wikipedia 403 Forbidden for S&P 500
- Fixed in current version with proper headers
- If still occurs, manually add CSV to
input_tickers/
Problem: 'Ticker' object has no attribute 'analyst_price_targets'
- Fixed in current version (using plural
analyst_price_targets) - Make sure yfinance is up to date:
pip install --upgrade yfinance
Problem: Data fetch takes too long
- Normal for 500+ stocks (can take 10-30 minutes)
- Use cache for subsequent runs on same day
- Or create smaller CSV in
input_tickers/with specific tickers
- Open the CSV files in Excel/Numbers/Google Sheets
- Sort/filter by your own criteria
- Cross-reference with your research
- Remember: This is a screening tool, not investment advice!