Skip to content

legendtkl/claude-stock-agent

Repository files navigation

Claude Stock Agent

A Claude Code subagent specialized in real-time US stock market analysis using yfinance for accurate, up-to-date market data with automatic Python execution via uv.

Overview

This subagent provides comprehensive stock analysis combining technical indicators, fundamental metrics, sentiment analysis, and peer comparisons. It generates professional markdown reports with actionable investment insights.

Designed for Claude Code: This agent is meant to be used within Claude Code's agent ecosystem. Simply install and start chatting with Claude about stock analysis - the agent handles everything automatically.

Features

  • Real-time Market Data: Live prices, volume, and market cap data
  • Technical Analysis: 20+ indicators including MA, RSI, MACD, Bollinger Bands, Stochastic, CCI, MFI, OBV, ATR, Williams %R, and more
  • Fundamental Analysis: Comprehensive valuation, profitability, growth, and financial health metrics
  • Peer Comparison: Side-by-side analysis with competitor stocks
  • Options Data: Put/call ratios and open interest analysis
  • Sentiment Analysis: News sentiment and analyst recommendations
  • Automated Reports: Professional markdown reports saved automatically

Quick Start

Installation

Run the automated installation script:

./install.sh

The script will:

  1. Copy agent files to ~/.claude/agents/ directory
  2. Install Python dependencies (yfinance, pandas, numpy) via uv
  3. Set up proper permissions

Requirements:

Usage in Claude Code

Simply ask Claude about stocks naturally:

You: Analyze AAPL stock
or

You: Analyze AAPL stock using us-stock-realtime agent

Claude will automatically:

  1. Invoke the stock analysis agent
  2. Fetch real-time market data
  3. Calculate technical indicators
  4. Analyze fundamentals
  5. Compare with relevant peers
  6. Generate a comprehensive markdown report
  7. Save the report as stock_analysis_[TICKER]_[DATE].md

How It Works

When you ask Claude Code about stock analysis, the agent:

  1. Identifies the request: Recognizes stock analysis queries
  2. Fetches data: Uses yfinance to get real-time market data
  3. Calculates indicators: Computes 20+ technical indicators
  4. Analyzes fundamentals: Evaluates valuation, profitability, growth
  5. Identifies peers: Automatically selects relevant competitor stocks
  6. Generates report: Creates comprehensive markdown analysis
  7. Saves output: Stores report in your current directory

Analysis Methodology

The subagent performs multi-dimensional analysis across four key areas:

1. Technical Analysis (30% weight)

  • Trend assessment using multiple moving averages
  • Momentum indicators (RSI, MACD, Stochastic)
  • Volatility analysis (Bollinger Bands, ATR)
  • Support/resistance levels (Pivot Points)

2. Fundamental Analysis (40% weight)

  • Valuation metrics (P/E, PEG, P/S, P/B, EV/EBITDA)
  • Profitability (margins, ROE, ROA)
  • Growth metrics (revenue, earnings growth)
  • Financial health (liquidity, debt ratios, cash flow)

3. Sentiment & Market Structure (20% weight)

  • Recent news sentiment
  • Analyst consensus and price targets
  • Options flow analysis
  • Volume and short interest

4. Peer Comparison (10% weight)

  • Relative valuation
  • Competitive positioning
  • Market share trends

Output

JSON Output

The script returns structured JSON data containing:

  • Real-time price data
  • All technical indicators
  • Fundamental metrics
  • Options data
  • Peer comparison data

Markdown Reports

When used as a Claude Code subagent, comprehensive analysis reports are automatically saved as:

stock_analysis_[TICKER]_[YYYY-MM-DD].md

Example: stock_analysis_NVDA_2025-09-23.md

Example Reports Included: This repository includes sample analysis reports for reference:

These examples demonstrate the depth and format of the automated analysis reports.

Scoring System

Composite Score (0-100):

  • 80-100: Strong Buy
  • 65-79: Buy
  • 50-64: Hold
  • 35-49: Reduce
  • 0-34: Sell

Key Metrics Reference

Valuation Thresholds

  • P/E Ratio: <15 (undervalued) | 15-25 (fair) | >25 (growth premium)
  • PEG Ratio: <1 (undervalued) | 1-2 (fair) | >2 (overvalued)
  • P/S Ratio: <1 (attractive) | 1-3 (reasonable) | >3 (expensive)

Profitability Benchmarks

  • Gross Margin: >40% (excellent) | 20-40% (good) | <20% (concerning)
  • Net Margin: >20% (excellent) | 10-20% (good) | <5% (weak)
  • ROE: >20% (excellent) | 15-20% (good) | <10% (poor)

Technical Indicators

  • RSI: <30 (oversold) | 30-70 (neutral) | >70 (overbought)
  • Put/Call Ratio: <0.5 (bullish) | 0.7-1.3 (neutral) | >1.5 (bearish)

Code Structure

Main Components

stock_analyzer.py: Core analysis module

  • get_realtime_data(ticker): Fetches live market data and metrics
  • calculate_technical_indicators(ticker, period): Computes 20+ technical indicators
  • get_options_data(ticker): Retrieves options chain data
  • fetch_stock_data(ticker, peer_tickers): Main data aggregation function
  • quick_price(ticker): Fast price check utility

Data Flow

  1. User requests stock analysis
  2. Script fetches real-time data via yfinance
  3. Calculates technical indicators from historical data
  4. Retrieves fundamental metrics and options data
  5. Optionally fetches peer comparison data
  6. Returns structured JSON
  7. Claude Code subagent analyzes and generates markdown report

Error Handling

The agent handles common issues automatically:

Issue How It's Handled
Missing dependencies Installation script installs all required packages
Rate limiting Automatic delays between API calls
Market closed Returns most recent available data
Invalid ticker Provides error message and suggests checking symbol
API unavailable Graceful error handling with partial data

File Structure

claude-stock-agent/
├── install.sh                          # Automated installation script
├── stock_analyzer.py                   # Core Python analysis module
├── us-stock-realtime.md               # Claude Code agent definition
├── README.md                          # This file
└── stock_analysis_*.md                # Generated analysis reports (examples)

Installed Location (after running install.sh):

~/.claude/agents/
├── stock_analyzer.py                   # Analysis engine
└── us-stock-realtime.md               # Agent configuration

Limitations

  • Market data may have 15-20 minute delay for some exchanges
  • Options data availability depends on the stock
  • Peer comparison limited to 6 stocks to avoid rate limiting
  • Real-time data quality depends on yfinance API availability

Disclaimer

This tool is for educational and research purposes only. The analysis and recommendations provided are not investment advice. Always conduct your own due diligence and consult with a qualified financial advisor before making investment decisions.

Data Source

All market data is sourced from Yahoo Finance via the yfinance Python library.

License

This project is part of the Claude Code agent ecosystem.

Version

Current Version: 1.0

Support

  • Installation Issues: Ensure uv is installed and Claude Code is configured
  • Agent Not Working: Verify files are in ~/.claude/agents/ directory
  • Data Issues: Check Yahoo Finance for ticker symbol validity
  • Claude Code Help: Refer to Claude Code documentation

Contributing

This is a specialized Claude Code subagent. When contributing:

  1. Maintain compatibility with Claude Code agent framework
  2. Follow the analysis methodology in us-stock-realtime.md
  3. Ensure all data fetching uses uv run python
  4. Test with multiple stock tickers and market conditions
  5. Update documentation for any new features

Acknowledgments

  • Built for the Claude Code ecosystem
  • Market data powered by yfinance
  • Uses Yahoo Finance as the data source

About

Claude Code SubAgent for stock Analyze

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published