PSX AI Assistance is an intelligent financial analytics app that integrates Pakistan Stock Exchange (PSX) data, company fundamentals, and financial reports with LLM-powered summarization, embedding-based retrieval (RAG), and interactive visualizations.
Built with Streamlit, Ollama, and ChromaDB, it enables users to:
- Fetch real-time market and company data from PSX APIs
- Download and process company financial PDFs
- Extract tables and text for semantic understanding
- Summarize complex financial data into human-readable insights
- Query embedded knowledge for interactive AI-assisted analysis
1112.mov
✅ Real-Time Market Data
Fetches and displays live data for indices (KSE100, KSE30, PSXDIV20, ALLSHR)
✅ Company Financial Details
Retrieves fundamentals, dividends, and K-Line data from PSX APIs
✅ PDF Financial Reports Parsing
Automatically downloads recent company PDFs from PSX
Extracts text and tables using pdfplumber
✅ AI Summarization
Summarizes structured and unstructured financial data using Ollama models
Supports multiple LLM backends (Qwen, DeepSeek, Kimi, GPT-OSS)
✅ RAG-Enabled Conversational Assistant
Uses ChromaDB for local vector storage of summaries
Users can chat with embedded financial knowledge
✅ Data Visualization
Interactive candlestick charts and metrics using Plotly and Streamlit
📊 PSX API + 📄 PDF Reports
│
▼
Data Collection Layer
(Requests, BeautifulSoup)
│
▼
PDF Parsing & Structuring
(pdfplumber, table extraction)
│
▼
LLM Summarization (Ollama)
Functions used:
summarize_table()summarize_ticker_detail()summary_ai_assistance()
│
▼
Embedding (ChromaDB + embeddinggemma)
│
▼
RAG Query & AI Response
Functions used:ai_assistance()embedd_prompt()
│
▼
Streamlit UI
Modules:- charts, metrics, chat interface
| Category | Technology |
|---|---|
| Frontend | Streamlit, Plotly |
| Backend | Python 3.10+, Requests, BeautifulSoup, asyncio |
| AI Models | Ollama (Qwen, DeepSeek, Kimi, GPT-OSS), embeddinggemma |
| Vector DB | ChromaDB |
| PDF Parsing | pdfplumber, PyPDF |
| Data Sources | PSX Terminal API, DPS PSX |
git clone https://github.com/<your-username>/psx-ai-assistance.git
cd psx-ai-assistancepython -m venv venv source venv/bin/activate # (Linux/macOS) venv\Scripts\activate # (Windows)
streamlit run main.py
You may need to configure Ollama or adjust models: response = ollama.chat( model="qwen3-coder:latest", # or "deepseek-v3.1:671b-cloud" messages=[...] )
client = chromadb.PersistentClient() collection = client.get_or_create_collection("my_db")
| Function | Purpose |
|---|---|
makeMarketRequest() |
Fetch index data (KSE100, KSE30, etc.) |
makeApiRequest(ticker) |
Fetch company fundamentals, dividends, and K-Line data |
getPdfFiles(ticker, session_data) |
Download and parse company PDFs |
summarize_ticker_detail() |
Summarize financial reports using LLMs |
embedd_text() |
Store summaries in ChromaDB |
embedd_prompt() |
Retrieve context embeddings and answer user queries |
ai_assistance() |
LLM reasoning based on embedded context |
root() |
Streamlit entry point that loads both data columns and UI |
- Select a symbol (e.g., OGDC) in the sidebar
- App fetches fundamentals, K-Line, and dividends
- Downloads the company’s latest financial PDFs
- Extracts tables and text, summarizes, and embeds them
- Ask natural language questions like: “What is OGDC’s profit growth over the last year?” “Summarize the company’s recent dividend trends.”
- The app answers using embedded summaries and AI reasoning