An AI based stock analyzer using LLM and Langchainπ
We Benchmarked 9 LLM Models for Stock Direction Prediction β Results Were Surprising
I tried (and failed) to create an AI model to predict the stock market (Deep Reinforcement Learning)
LLMS/AI for stock market
Videos
An interesting application of Language Models and Langchain in the Finance Domain π-
Sharing a fun weekend project that I recently completed: the "Stock Analyzer Bot". As an investment enthusiastic person without extensive knowledge in the finance domain, I often end up referring to some finance youtuber's videos or a site on the internet for the fundamental analysis of stocks. To assist in such situations, I developed a stock analyzer bot based on LLM, which gathers up-to-date information about stock such as 1) stock price, 2) Company financials 3) Recent company-related news. The bot then considers all this information to conduct analysis using language models. You can even get positives and negatives about the company's financials, which will certainly help when making an investment decision.
You can ask queries like- "Is it a good time to invest in Yes Bank?" or "How are the current financials of reliance industries looking" and boom within a minute you are presented with a comprehensive financial analysis based on recent data. Of course, It is not recommended to rely fully on the analysis provided by the bot. It seems like a good starting point. And yeah, I agree the possibilities are endless with LLMsπ.
GIthub- https://github.com/Pranav082001/stock-analyzer-bot
Blog An AI based stock analyzer using LLM and Langchain π | by Pranav Kushare | Aug, 2023 | Medium
We built an AI-powered trading system that uses LLMs for "Deep Analysis" β feeding technical indicators and news sentiment into a model and asking it to predict 5-day directional bias (bullish/bearish/neutral).
To find the best model, we ran a standardized benchmark: 25 real historical stock cases from 2024-2025 with known outcomes. Each model got the exact same prompt, same data, same JSON output format.
Hardware: Mac Studio M3 Ultra (96GB RAM), all local models via Ollama.
Test Methodology
Dataset
-
25 historical cases from 2024-2025 with known 5-day price outcomes
-
12 bullish cases (price went up >2% in 5 days)
-
10 bearish cases (price went down >2% in 5 days)
-
3 neutral cases (price moved <2% in 5 days)
-
Mix of easy calls, tricky reversals, and genuinely ambiguous cases
What Each Model Received
-
Current price
-
Technical indicators (RSI, MACD, ADX, SMAs, volume ratio, Bollinger position, ATR)
-
News sentiment (score, article counts, key themes)
-
JSON schema to follow
Parameters
-
Temperature: 0.3
-
Format: JSON mode (
format: "json"for Ollama,response_format: json_objectfor GPT-4o) -
Max tokens: 4096 (Ollama) / 2048 (GPT-4o)
-
Each model ran solo on GPU (no concurrent models) for clean timing
-
Claude Opus 4.6 was tested via CLI using the same case data and system prompt rules
-
GPT-4o and Claude Opus 4.6 are API-based models; all others ran locally on the M3 Ultra
Scoring
-
Correct: Model's
overall_biasmatches the actual direction -
Wrong: Model predicted a different direction
-
Failed: Model couldn't produce valid JSON output
Overall Accuracy Ranking
| Rank | Model | Params | Size | Correct | Wrong | Failed | Accuracy | Avg Time | Cost |
|---|---|---|---|---|---|---|---|---|---|
| 1 | Claude Opus 4.6 | Unknown | API | 24 | 1 | 0 | 96.0% | ~5s | ~$0.05/call |
| 2 | QwQ:32b | 32B | 19GB | 23 | 2 | 0 | 92.0% | 14.6s | Free (local) |
| 3 | DeepSeek-R1:32b | 32B | 19GB | 22 | 3 | 0 | 88.0% | 14.2s | Free (local) |
| 3 | DeepSeek-R1:14b | 14B | 9GB | 22 | 3 | 0 | 88.0% | 9.4s | Free (local) |
| 5 | GPT-4o | Unknown | API | 20 | 5 | 0 | 80.0% | 5.2s | ~$0.02/call |
| 6 | Qwen3:32b | 32B | 20GB | 19 | 5 | 1 | 79.2% | 11.5s | Free (local) |
| 7 | Llama 3.3:70b | 70B | 42GB | 19 | 6 | 0 | 76.0% | 18.7s | Free (local) |
| 8 | Qwen3:8b | 8B | 5GB | 17 | 8 | 0 | 68.0% | 2.9s | Free (local) |
| 8 | Palmyra-Fin-70b | 70B | 42GB | 17 | 8 | 0 | 68.0% | 13.4s | Free (local) |
Accuracy by Category
| Model | Bullish (12 cases) | Bearish (10 cases) | Neutral (3 cases) |
|---|---|---|---|
| Claude Opus 4.6 | 100% (12/12) | 90% (9/10) | 100% (3/3) |
| QwQ:32b | 100% (12/12) | 80% (8/10) | 100% (3/3) |
| DeepSeek-R1:32b | 92% (11/12) | 80% (8/10) | 100% (3/3) |
| DeepSeek-R1:14b | 100% (12/12) | 80% (8/10) | 67% (2/3) |
| GPT-4o | 83% (10/12) | 70% (7/10) | 100% (3/3) |
| Qwen3:32b | 82% (9/11) | 70% (7/10) | 100% (3/3) |
| Llama 3.3:70b | 92% (11/12) | 70% (7/10) | 33% (1/3) |
| Qwen3:8b | 83% (10/12) | 40% (4/10) | 100% (3/3) |
| Palmyra-Fin-70b | 100% (12/12) | 50% (5/10) | 0% (0/3) |
Speed Benchmark
| Model | Avg Latency | Tokens/sec | JSON Parse Rate | Run Location |
|---|---|---|---|---|
| Qwen3:8b | 2.9s | 81.1 tok/s | 100% | Local (M3 Ultra) |
| Claude Opus 4.6 | ~5s | N/A (API) | 100% | API (Anthropic) |
| GPT-4o | 5.2s | 63.5 tok/s | 100% | API (OpenAI) |
| DeepSeek-R1:14b | 9.4s | ~45 tok/s | 100% | Local (M3 Ultra) |
| Qwen3:32b | 11.5s | ~45 tok/s | 96% (1 fail) | Local (M3 Ultra) |
| Palmyra-Fin-70b | 13.4s | ~30 tok/s | 100% | Local (M3 Ultra) |
| DeepSeek-R1:32b | 14.2s | 23.8 tok/s | 100% | Local (M3 Ultra) |
| QwQ:32b | 14.6s | ~22 tok/s | 100% | Local (M3 Ultra) |
| Llama 3.3:70b | 18.7s | ~20 tok/s | 100% | Local (M3 Ultra) |
Full Per-Case Breakdown
Legend
-
+= correct prediction -
X= wrong prediction -
F= failed to parse JSON -
bull= predicted bullish,bear= predicted bearish,neut= predicted neutral
Bullish Cases (12)
| # | Symbol | Context | Actual | Claude 4.6 | QwQ:32b | DS-R1:32b | DS-R1:14b | GPT-4o | Qwen3:32b | Llama3.3:70b | Qwen3:8b | Palmyra-Fin |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | NVDA | Nov 2024 β Post-earnings AI boom | +8.2% | +bull | +bull | +bull | +bull | +bull | +bull | +bull | +bull | +bull |
| 2 | META | Jan 2025 β Strong ad revenue | +5.1% | +bull | +bull | +bull | +bull | +bull | +bull | +bull | +bull | +bull |
| 3 | AMZN | Oct 2024 β AWS growth | +4.3% | +bull | +bull | +bull | +bull | +bull | +bull | +bull | +bull | +bull |
| 4 | AAPL | Dec 2024 β iPhone 16 demand | +3.2% | +bull | +bull | +bull | +bull | +bull | F | +bull | +bull | +bull |
| 5 | GOOGL | Oct 2024 β Gemini AI, cloud beat | +6.5% | +bull | +bull | +bull | +bull | +bull | Xunk | +bull | +bull | +bull |
| 11 | TSLA | Nov 2024 β Overbought but ran | +12.4% | +bull | +bull | +bull | +bull | +bull | +bull | +bull | +bull | +bull |
| 13 | COIN | Nov 2024 β Crypto bull run | +15.3% | +bull | +bull | +bull | +bull | +bull | +bull | +bull | +bull | +bull |
| 14 | DIS | Aug 2024 β Surprise earnings beat | +4.8% | +bull | +bull | Xneut | +bull | Xneut | Xbear | Xbear | Xneut | +bull |
| 15 | NFLX | Jan 2025 β Ad tier + password sharing | +5.8% | +bull | +bull | +bull | +bull | +bull | +bull | +bull | +bull | +bull |
| 20 | SNAP | Feb 2024 β Surprise earnings beat | +25.0% | +bull | +bull | +bull | +bull | Xneut | +bull | +bull | Xneut | +bull |
| 21 | BABA | Sep 2024 β China stimulus | +22.0% | +bull | +bull | +bull | +bull | +bull | +bull | +bull | +bull | +bull |
| 24 | WMT | Aug 2024 β Defensive play | +3.5% | +bull | +bull | +bull | +bull | +bull | +bull | +bull | +bull | +bull |
Bearish Cases (10)
| # | Symbol | Context | Actual | Claude 4.6 | QwQ:32b | DS-R1:32b | DS-R1:14b | GPT-4o | Qwen3:32b | Llama3.3:70b | Qwen3:8b | Palmyra-Fin |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 6 | INTC | Aug 2024 β Massive earnings miss | -26.1% | +bear | +bear | +bear | +bear | +bear | +bear | +bear | +bear | +bear |
| 7 | BA | Jan 2024 β Door plug blowout | -8.5% | +bear | +bear | +bear | +bear | +bear | +bear | +bear | +bear | +bear |
| 8 | NKE | Jun 2024 β Guidance cut | -19.8% | +bear | +bear | +bear | +bear | +bear | +bear | +bear | +bear | +bear |
| 9 | PYPL | Feb 2024 β Stagnant growth | -5.2% | +bear | +bear | +bear | +bear | +bear | +bear | +bear | Xneut | +bear |
| 10 | XOM | Sep 2024 β Oil prices dropping | -4.8% | +bear | +bear | +bear | +bear | +bear | +bear | +bear | Xneut | Xbull |
| 12 | SMCI | Mar 2024 β Extreme overbought crash | -18.5% | Xbull | Xbull | Xbull | Xbull | Xbull | Xbull | Xbull | Xbull | Xbull |
| 19 | AMD | Oct 2024 β Bullish technicals, bad guidance | -9.2% | +bear | +bear | +bear | +bear | Xneut | Xneut | Xbull | Xneut | Xbull |
| 22 | CVS | Nov 2024 β Beaten down, kept falling | -6.5% | +bear | +bear | +bear | +bear | +bear | +bear | +bear | +bear | +bear |
| 23 | MSFT | Jul 2024 β Mixed: strong cloud, capex worry | -3.8% | +bear | Xbull | Xneut | Xbull | Xneut | Xneut | Xbull | Xneut | Xbull |
| 25 | RIVN | Nov 2024 β Cash burn concerns | -8.0% | +bear | +bear | +bear | +bear | +bear | +bear | +bear | Xneut | Xbull |
Neutral Cases (3)
| # | Symbol | Context | Actual | Claude 4.6 | QwQ:32b | DS-R1:32b | DS-R1:14b | GPT-4o | Qwen3:32b | Llama3.3:70b | Qwen3:8b | Palmyra-Fin |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 16 | JNJ | Sep 2024 β Defensive, flat market | +0.3% | +neut | +neut | +neut | Xbull | +neut | +neut | Xbull | +neut | Xbull |
| 17 | PG | Oct 2024 β Low volatility period | -0.5% | +neut | +neut | +neut | +neut | +neut | +neut | +neut | +neut | Xbull |
| 18 | KO | Nov 2024 β Post-earnings consolidation | +1.1% | +neut | +neut | +neut | +neut | +neut | +neut | Xbull | +neut | Xbull |
Model Bias Analysis
Bullish Bias (tendency to over-predict bullish)
| Model | Times Predicted Bullish | Actual Bullish Cases | Bullish Bias |
|---|---|---|---|
| Palmyra-Fin-70b | 20/25 (80%) | 12/25 (48%) | Extreme (+32%) |
| Llama 3.3:70b | 17/25 (68%) | 12/25 (48%) | High (+20%) |
| DeepSeek-R1:14b | 14/25 (56%) | 12/25 (48%) | Low (+8%) |
| QwQ:32b | 14/25 (56%) | 12/25 (48%) | Low (+8%) |
| Claude Opus 4.6 | 13/25 (52%) | 12/25 (48%) | Minimal (+4%) |
| DeepSeek-R1:32b | 13/25 (52%) | 12/25 (48%) | Minimal (+4%) |
Neutral Bias (tendency to over-predict neutral)
| Model | Times Predicted Neutral | Actual Neutral Cases | Neutral Bias |
|---|---|---|---|
| Qwen3:8b | 11/25 (44%) | 3/25 (12%) | Extreme (+32%) |
| GPT-4o | 7/25 (28%) | 3/25 (12%) | High (+16%) |
| Qwen3:32b | 6/25 (24%) | 3/25 (12%) | Moderate (+12%) |
| DeepSeek-R1:32b | 5/25 (20%) | 3/25 (12%) | Low (+8%) |
| Claude Opus 4.6 | 3/25 (12%) | 3/25 (12%) | None (0%) |
| QwQ:32b | 3/25 (12%) | 3/25 (12%) | None (0%) |
| DeepSeek-R1:14b | 2/25 (8%) | 3/25 (12%) | None (-4%) |
Hardest Cases β Where Models Disagree
Case #12: SMCI (-18.5%) β ALL 9 models wrong
-
Situation: Extreme overbought (RSI 82, BB 0.98), just added to S&P 500, AI server demand booming
-
Why hard: Every momentum signal was bullish. The crash came from overvaluation + short seller reports
-
Lesson: No model β not even Claude Opus 4.6 β can detect when momentum is about to reverse from extreme overbought. This is a fundamental limitation when the only bearish signal is a minority short-seller view.
Case #23: MSFT (-3.8%) β 8 of 9 models wrong (only Claude correct)
-
Situation: Mixed signals, RSI 55 (neutral), MACD below signal, news split 50/50
-
Why hard: Genuinely ambiguous. The -3.8% move was driven by macro rotation, not company-specific
-
Only correct: Claude Opus 4.6 (detected the MACD bearish crossover + balanced news as a slight bearish tilt)
Case #14: DIS (+4.8%) β 5 of 9 models wrong
-
Situation: Bearish technicals (RSI 42, below all SMAs) but positive news (Disney+ profitable early)
-
Why hard: Conflict between technical bearishness and fundamental positive surprise
-
Only correct: Claude Opus 4.6, QwQ:32b, DeepSeek-R1:14b, Palmyra-Fin-70b
Case #19: AMD (-9.2%) β 5 of 9 models wrong
-
Situation: Bullish technicals (RSI 60.5, above SMAs) but disappointing guidance news
-
Why hard: Technical momentum vs. fundamental disappointment
-
Only correct: Claude Opus 4.6, QwQ:32b, DeepSeek-R1:32b, DeepSeek-R1:14b
Disagreement Analysis
Cases where models disagreed reveal their strengths and weaknesses:
| # | Symbol | Correct | Claude | QwQ | DS-R1:32b | DS-R1:14b | GPT-4o | Qwen3:32b | Llama3.3 | Qwen3:8b | Palmyra |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 9 | PYPL | bear | +bear | +bear | +bear | +bear | +bear | +bear | +bear | Xneut | +bear |
| 10 | XOM | bear | +bear | +bear | +bear | +bear | +bear | +bear | +bear | Xneut | Xbull |
| 14 | DIS | bull | +bull | +bull | Xneut | +bull | Xneut | Xbear | Xbear | Xneut | +bull |
| 16 | JNJ | neut | +neut | +neut | +neut | Xbull | +neut | +neut | Xbull | +neut | Xbull |
| 17 | PG | neut | +neut | +neut | +neut | +neut | +neut | +neut | +neut | +neut | Xbull |
| 18 | KO | neut | +neut | +neut | +neut | +neut | +neut | +neut | Xbull | +neut | Xbull |
| 19 | AMD | bear | +bear | +bear | +bear | +bear | Xneut | Xneut | Xbull | Xneut | Xbull |
| 20 | SNAP | bull | +bull | +bull | +bull | +bull | Xneut | +bull | +bull | Xneut | +bull |
| 23 | MSFT | bear | +bear | Xbull | Xneut | Xbull | Xneut | Xneut | Xbull | Xneut | Xbull |
| 25 | RIVN | bear | +bear | +bear | +bear | +bear | +bear | +bear | +bear | Xneut | Xbull |
Patterns:
-
Claude Opus 4.6 correctly resolved every conflict case except SMCI. It consistently weighted news catalysts appropriately against technical signals.
-
DeepSeek-R1:14b matches the 32b version on most cases, uniquely got DIS right (news > technicals) but missed JNJ neutral (slight bullish bias). Same 3 errors as 32b but on different cases β trades JNJ for DIS.
-
Qwen3:8b defaults to neutral when uncertain β overly cautious, misses directional moves.
-
Palmyra-Fin and Llama 3.3 default to bullish β dangerous, misses bearish signals and neutral consolidation.
-
Reasoning models (Claude, QwQ, DeepSeek-R1) make nuanced calls by weighing technicals against news fundamentals.
Key Findings
1. Reasoning Models Dominate
Claude Opus 4.6 (96%), QwQ:32b (92%), DeepSeek-R1:32b (88%), and DeepSeek-R1:14b (88%) are all chain-of-thought reasoning models that "think through" the analysis. Non-reasoning models (Llama 3.3, Palmyra-Fin) perform significantly worse despite being 2-5x larger.
2. Bigger is NOT Better
-
Llama 3.3:70b (76%) and Palmyra-Fin-70b (68%) are 70B parameter models but scored lower than 32B reasoning models
-
The 70B models use 2x more RAM (42GB vs 19-20GB) and are slower
-
Model architecture (reasoning vs. standard) matters more than parameter count
3. "Finance-Specific" Model Performed Worst
Palmyra-Fin-70b (marketed as finance-optimized) scored 68% with massive bullish bias:
-
Predicted bullish 80% of the time
-
0% accuracy on neutral cases (predicted all as bullish)
-
50% on bearish (predicted half as bullish)
-
Fine-tuning on financial text doesn't help directional prediction
4. Bearish Detection is the Differentiator
All models handle obvious bullish cases well. The key differentiator is detecting bearish signals β the metric that actually prevents losses:
-
Claude Opus 4.6: 90%
-
QwQ / DeepSeek-R1 (32b & 14b): 80%
-
GPT-4o / Qwen3 / Llama: 70%
-
Palmyra-Fin: 50%
-
Qwen3:8b: 40%
5. Distilled Reasoning Preserves Accuracy at Half the Size
-
DeepSeek-R1:14b matches DeepSeek-R1:32b at exactly 88% accuracy
-
Runs 34% faster (9.4s vs 14.2s) and uses half the RAM (9GB vs 19GB)
-
Perfect 100% bullish detection (12/12), strong 80% bearish detection
-
Only weakness vs 32b: missed 1 neutral case (JNJ β predicted bullish)
-
Proves that reasoning knowledge distillation from R1-671B works effectively even at 14B scale
6. Small Models Default to Neutral/Bullish When Confused
-
Qwen3:8b predicted neutral 44% of the time (actual: 12%). It's too cautious.
-
Palmyra-Fin predicted bullish 80% of the time. It can't recognize bearish signals.
-
Both failure modes are dangerous: missing bearish = holding through drops, false neutral = no signal.
Our Production Setup
We run QwQ:32b locally on a Mac Studio M3 Ultra for 24/7 autonomous stock and crypto trading. It processes real-time technical indicators + news sentiment for each symbol, generates directional bias with confidence scores, and feeds that into our execution engine with full risk management.
Why QwQ:32b over Claude/GPT? Zero API cost, zero latency variance, no network dependency, and 92% accuracy is strong enough for production when combined with proper stop-loss, position sizing, and portfolio risk limits.
What we're building: An AI-powered autonomous trading platform that combines real-time technical analysis, news sentiment, and LLM reasoning.