Spaces:
Sleeping
Sleeping
File size: 5,821 Bytes
4a645e8 139d9d7 31adc25 523ea93 31adc25 a8615dc a697707 a8615dc a697707 31adc25 a8615dc 31adc25 01978cf 31adc25 a8615dc 31adc25 a8615dc 31adc25 a8615dc a697707 a8615dc 31adc25 a8615dc a697707 31adc25 a8615dc 31adc25 a697707 dff71a5 a8615dc a697707 dff71a5 a8615dc a697707 a8615dc a697707 523ea93 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
---
title: QueryStockAI
emoji: 📈
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
license: mit
short_description: AI-powered financial analysis and trading assistant
---
# QueryStockAI
A comprehensive financial analysis tool that provides stock data, news analysis, and AI-powered insights through an interactive Streamlit web interface. Features advanced machine learning-based stock price predictions using Ridge Regression with comprehensive technical indicators and an AI agent which answers user's queries based on stock dayta and news sentiment.
## Features
- **Stock Data**: Fetch historical stock prices and performance metrics using Yahoo Finance
- **Interactive Stock Charts**: Visualize stock performance with Plotly charts showing 1 year of data
- **Advanced ML Predictions**: Ridge Regression model with 5 years of training data and 30-day forecasts
- **Comprehensive Technical Indicators**: 35+ technical indicators including RSI, MACD, Bollinger Bands, Stochastic, Williams %R, CCI, and more
- **Latest News Analysis**: Get recent news headlines for selected stocks
- **AI-Powered Chat Interface**: Chat with a financial agent powered by mistral via OpenRouter
- **MCP Server Integration**: Modular architecture with separate MCP servers for stock data and news
- **System Resource Monitoring**: Real-time monitoring of CPU, memory, disk, and network usage
- **Stock Search & Discovery**: Search for custom tickers and browse popular stocks
- **Caching & Performance**: Intelligent caching for charts and news to improve performance
- **Feature Scaling**: StandardScaler for optimal model performance
- **Cross-Validation**: GridSearchCV for hyperparameter tuning
## Machine Learning Model
### Ridge Regression with Enhanced Features
- **Training Data**: 5 years of historical stock data
- **Display Data**: Last 1 year shown in charts
- **Prediction Period**: 30 trading days
- **Features**: 35+ technical indicators including:
- Moving Averages (SMA 10, 20, 50, 200)
- Momentum Indicators (RSI, MACD, Stochastic, Williams %R, CCI)
- Volatility Indicators (Bollinger Bands, Price Volatility)
- Volume Analysis (Volume Change, Volume-Price Trend)
- Support/Resistance Levels
- Time-Based Features (Day of Week, Month, Quarter)
- Market Sentiment Indicators
### Model Performance
- **Regularization**: Ridge Regression with L2 regularization
- **Hyperparameter Tuning**: GridSearchCV with cross-validation
- **Feature Scaling**: StandardScaler for optimal performance
- **Accuracy**: Typically 80-95% R² score on historical data
- **Training Time**: ~2-5 seconds per stock
## Setup
1. **Install dependencies**:
```bash
uv sync
```
Or using pip:
```bash
pip install -r requirements.txt
```
2. **Create a `.env` file** with your API keys:
```
GROQ_API_KEY="your_groq_api_key_here"
MODEL="moonshotai/kimi-k2-instruct" # or any model of your choice
```
3. **Run the Streamlit app**:
```bash
streamlit run Home.py
```
or using uv:
```bash
uv run streamlit run Home.py
```
## Usage
1. Open the web interface in your browser
2. Select a stock ticker from the dropdown in the sidebar or search for a custom ticker
3. View the interactive stock price chart showing:
- Last 1 year of historical data
- 30-day Ridge Regression predictions
- Model performance metrics
4. Start chatting with the financial agent about the selected stock
5. Ask questions like:
- "How is this stock performing?"
- "What's the latest news about this company?"
- "Should I invest in this stock?"
- "What are the recent trends?"
## Architecture
- **Frontend**: Streamlit web interface with interactive charts
- **Backend**: Python with OpenRouter integration
- **ML Pipeline**: Ridge Regression with scikit-learn
- **Data Sources**:
- Stock data via `yfinance`
- News data via `gnews`
- **AI Model**: mistral-small-3.2-24b-instruct via OpenRouter
- **MCP Servers**: Modular servers for stock data and news
## Files
- `Home.py`: Main Streamlit web application with ML predictions
- `Dockerfile`: Docker configuration for Railway deployment
- `docker-compose.yml`: Local development setup
- `railway.toml`: Railway deployment configuration
- `requirements.txt`: Python dependencies
- `pyproject.toml`: Project configuration
## Dependencies
- **Streamlit**: Web interface framework
- **yfinance**: Stock data fetching
- **gnews**: News data fetching
- **plotly**: Interactive charts
- **scikit-learn**: Machine learning (Ridge Regression, StandardScaler, GridSearchCV)
- **pandas**: Data manipulation
- **numpy**: Numerical computations
- **openai**: AI model integration
- **fastmcp**: MCP server framework
## Technical Indicators Used
### Price-Based Features
- Simple Moving Averages (10, 20, 50, 200-day)
- Price Change (1, 5, 20-day)
- Price Volatility and Range
- Support/Resistance Levels
### Momentum Indicators
- Relative Strength Index (RSI)
- Moving Average Convergence Divergence (MACD)
- Stochastic Oscillator (K% and D%)
- Williams %R
- Commodity Channel Index (CCI)
### Volatility Indicators
- Bollinger Bands (Standard Deviation, Position, Squeeze)
- Price Volatility
- Price Range
### Volume Analysis
- Volume Change and Trends
- Volume-Price Relationship
- Volume Moving Averages
- Volume Spikes
### Market Sentiment
- Moving Average Crossovers
- Price vs Long-term Averages
- Time-based Patterns
## System Requirements
- Python 3.10 or higher
- OpenRouter API key
- Internet connection for real-time data
## Disclaimer
Stock predictions have approximately 70% accuracy. These forecasts are for informational purposes only and should not be used as the sole basis for investment decisions. Always conduct your own research and consider consulting with financial advisors.
|