A curated collection of practical AI projects implementing OCR systems, RAG, AI agents, and other AI use cases.
π Stock Portfolio Analyst
Powered by DeepSeek-V4-Flash via NVIDIA API for fast, cost-efficient reasoning and real-time financial analysis

Overview
An AI-powered portfolio analysis agent that evaluates stock holdings using live market data. Enter your tickers, share counts, and average purchase prices, and the agent fetches real-time pricing and fundamentals via YFinance, searches for recent news via DuckDuckGo, and generates a comprehensive portfolio review, streamed live in the UI as it builds.
The report covers P&L per position, portfolio-level metrics, concentration and valuation risk flags, sector breakdown, and specific rebalancing recommendations.
Features
- Live Market Data: Fetches real-time prices, fundamentals, and analyst ratings via YFinance for every holding
- P&L Calculations: Unrealized gain/loss per position (absolute and percentage) plus portfolio totals
- Risk Assessment: Flags concentration risk (positions > 20%), valuation extremes (P/E > 40), and negative news sentiment
- Sector Breakdown: Visualizes portfolio weight across sectors to identify diversification gaps
- Rebalancing Recommendations: Specific, data-driven suggestions on what to trim, hold, or add
- Streaming Output: Analysis streams in real time as the agent works through each holding
- Pre-loaded Example Portfolio: A 7-stock portfolio is ready to analyze on first launch
- Quick Question Buttons: One-click common analysis queries in the sidebar
Tech Stack
Framework & Tools:
- Agno: Agent framework orchestrating tool use and LLM reasoning
- YFinanceTools: Live stock prices, fundamentals, analyst recommendations, company news
- DuckDuckGoTools: Real-time web search for market context and headlines
- CalculatorTools: Precise P&L and concentration calculations
Model:
- DeepSeek-V4-Flash (
deepseek-ai/deepseek-v4-flash): fast and cost-efficient reasoning via the NVIDIA API
UI:
- Gradio: Interactive web interface with streaming markdown output
Prerequisites
- Python 3.10 or higher
- uv (recommended) or pip
- An NVIDIA API key (free tier available)
Installation
1. Clone the Repository
git clone https://github.com/Sumanth077/Hands-On-AI-Engineering.git
cd Hands-On-AI-Engineering/ai_agents/stock_portfolio_analyst
2. Set Up Environment Variables
cp .env.example .env
Open .env and add your NVIDIA API key:
NVIDIA_API_KEY=your_nvidia_api_key_here
Get your API key at build.nvidia.com.
3. Install Dependencies
uv sync
Usage
uv run python app.py
Navigate to http://localhost:7860 in your browser.
- Edit the portfolio table β update tickers, share counts, and average purchase prices
- Type a question or leave it blank for a full portfolio review
- Click Analyze Portfolio β the report streams in real time as the agent fetches data
- Use the Quick Question buttons for common one-click analyses
- Click Reset to restore the example portfolio
How It Works
User Portfolio Input
β
βΌ
YFinanceTools β live price, fundamentals, analyst ratings per ticker
β
βΌ
DuckDuckGoTools β recent news and market context
β
βΌ
CalculatorTools β P&L, weight, concentration calculations
β
βΌ
DeepSeek-V4-Flash β synthesizes data into structured markdown report
β
βΌ
Streamed Report β Summary Β· Holdings Β· Risk Flags Β· Rebalancing
Project Structure
stock_portfolio_analyst/
βββ app.py # Gradio UI and streaming interface
βββ agent.py # Agno agent, DeepSeek-V4-Flash model, tool config, prompt
βββ assets/
β βββ demo.png # App screenshot
βββ .env.example # API key template
βββ pyproject.toml # Project dependencies (uv)
βββ README.md
Disclaimer
This tool is for educational and informational purposes only. Nothing in this application constitutes financial advice. Always consult a qualified financial advisor before making investment decisions.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License. See the LICENSE file for details.