Overview
Thesingle_stock_analyzer.py script provides detailed fundamental analysis for any stock in the ChartsMaze database. It extracts quarterly results, ratios, and ownership data directly from fundamental_data.json.
Use Case: Quick inspection of a single stock’s fundamentals without processing the entire dataset.
Quick Start
Ensure fundamental_data.json exists
The analyzer requires If missing, fetch it:
fundamental_data.json from the pipeline:Usage
Basic Syntax
<SYMBOL>: NSE stock symbol (e.g., RELIANCE, TCS, INFY, HDFCBANK)
Examples
Error Handling
Missing file:Output Format
Sample Output (RELIANCE)
Metrics Explained
1. Net Profit Analysis
| Metric | Description |
|---|---|
| Net Profit Latest Quarter | Net profit for most recent quarter (in Crores) |
| Net Profit Previous Quarter | Net profit for Q-1 |
| Net Profit 2/3 Quarters Back | Net profit for Q-2, Q-3 |
| Net Profit Last Year Quarter | Net profit for same quarter last year (for YoY comparison) |
| QoQ % Net Profit Latest | Quarter-over-Quarter growth: (Latest - Previous) / Previous * 100 |
| YoY % Net Profit Latest | Year-over-Year growth: (Latest - Last Year Q) / Last Year Q * 100 |
- Positive QoQ: Sequential improvement
- Positive YoY: Year-over-year growth
- Consistent growth across quarters: Strong momentum
2. Earnings Per Share (EPS)
| Metric | Description |
|---|---|
| EPS Latest Quarter | Earnings per share for latest quarter (₹) |
| EPS Previous/2Q/3Q Back | Historical quarterly EPS |
| EPS Last Year Quarter | Same quarter last year (for YoY) |
| QoQ % EPS Latest | Sequential EPS growth |
| YoY % EPS Latest | Year-over-year EPS growth |
| EPS Last Year | Full-year EPS for previous fiscal year |
| EPS 2 Years Back | EPS from 2 years ago |
- Rising EPS: Improving profitability per share
- YoY > 15%: High growth stock
- Compare with P/E to assess valuation
3. Sales (Revenue)
| Metric | Description |
|---|---|
| Sales Latest Quarter | Total revenue for latest quarter (in Crores) |
| Sales Previous/2Q/3Q Back | Historical quarterly revenue |
| Sales Last Year Quarter | Same quarter last year |
| QoQ % Sales Latest | Sequential revenue growth |
| YoY % Sales Latest | Year-over-year revenue growth |
| Sales Growth 5 Years(%) | 5-year CAGR: ((Current / 5Y Ago)^(1/5) - 1) * 100 |
- Consistent sales growth: Market share expansion
- 5Y CAGR > 10%: Strong long-term growth
- Compare with profit growth to assess margin trends
4. Operating Profit Margin (OPM)
| Metric | Description |
|---|---|
| OPM Latest Quarter | Operating margin % for latest quarter |
| OPM Previous/2Q/3Q Back | Historical quarterly margins |
| OPM Last Year Quarter | Same quarter last year |
| QoQ % OPM Latest | Sequential margin change |
| YoY % OPM Latest | Year-over-year margin change |
| OPM TTM(%) | Trailing Twelve Months operating margin |
- Rising OPM: Improving operational efficiency
- OPM > 15%: High-margin business
- Declining OPM with rising sales: Volume growth at cost of margins
5. Valuation Ratios
| Metric | Description | Formula |
|---|---|---|
| P/E | Price-to-Earnings ratio | Stock Price / TTM EPS |
| Forward P/E | Forward Price-to-Earnings | Price / (Latest Q EPS * 4) |
| PEG | Price/Earnings to Growth | P/E / YoY EPS Growth % |
| Historical P/E 5 | 5-year average P/E | Not available in current data |
- P/E < 15: Potentially undervalued (or low growth)
- P/E 15-25: Fairly valued
- P/E > 25: Premium valuation (growth stock) or overvalued
- Forward P/E < Current P/E: Earnings expected to grow
- PEG < 1: Undervalued relative to growth
- PEG > 2: Overvalued relative to growth
6. Return Ratios
| Metric | Description | Benchmark |
|---|---|---|
| ROE(%) | Return on Equity | > 15% is good |
| ROCE(%) | Return on Capital Employed | > 15% is good |
| D/E | Debt-to-Equity ratio | < 1.0 is healthy |
- ROE > 15%: Efficient use of shareholder equity
- ROCE > ROE: Efficient use of total capital
- D/E < 0.5: Conservative leverage
- D/E 0.5-1.0: Moderate leverage
- D/E > 1.0: High debt (check industry norms)
7. Ownership Changes
| Metric | Description |
|---|---|
| FII % change QoQ | Foreign Institutional Investor holdings change (percentage points) |
| DII % change QoQ | Domestic Institutional Investor holdings change (percentage points) |
- FII increase: Positive institutional sentiment
- DII increase: Domestic confidence
- Both increasing: Strong accumulation
- Both decreasing: Institutional selling pressure
Data Source Structure
The analyzer reads fromfundamental_data.json, which contains:
Data Sections
Pipe-Separated Values
Most fields use pipe (|) separation for time series:
index 0= Latest quarterindex 1= Previous quarter (Q-1)index 2= 2 quarters back (Q-2)index 3= 3 quarters back (Q-3)index 4= Last year same quarter (for YoY)
Use Cases
1. Pre-Investment Due Diligence
- Consistent QoQ and YoY growth in sales and profits
- Improving or stable OPM
- ROE > 15%, ROCE > 15%
- PEG ratio < 1.5
- Positive FII/DII changes
2. Quarterly Results Analysis
- Latest quarter vs previous quarter (QoQ growth)
- Latest quarter vs last year same quarter (YoY growth)
- Margin expansion or compression
3. Peer Comparison
4. Tracking Portfolio Stocks
Scripting & Automation
Extract Specific Metrics
Batch Processing
JSON Output Conversion
Convert console output to JSON for programmatic use:Limitations
- No Technical Indicators: This script only analyzes fundamental data. For technical analysis (RSI, SMA, RVOL), use the full pipeline output.
-
No OHLCV Data: Price history, returns, and ATH are not available. Use
ohlcv_data/{SYMBOL}.csvfor price data. - Historical P/E Not Available: The script shows “Data Unavailable” for 5-year historical P/E.
-
Static Snapshot: Analyzes data from
fundamental_data.json- runfetch_fundamental_data.pyto refresh. - No News/Events: Corporate actions, announcements, and news are not included. See full pipeline output for these.
Advanced Usage
Modify Calculation Logic
Editsingle_stock_analyzer.py to add custom metrics:
Integration with Full Pipeline
Use as a validation step after pipeline completion:Troubleshooting
”fundamental_data.json not found”
Solution: Fetch the data first:“Stock ‘XYZ’ not found in database”
Causes:- Incorrect symbol (check NSE symbol, not company name)
- Stock recently listed (not in database yet)
- Stock delisted
Zero Values for All Metrics
Cause: Stock exists but has no fundamental data (e.g., newly listed or suspended) Solution: Check if stock is actively traded and has filed quarterly results.Next Steps
- Running Full Pipeline - Generate complete dataset with all metrics
- Incremental Updates - Keep data fresh with daily updates
- Data Fields Reference - Complete list of 86 output fields