AI-Powered Stock Market Prediction & Analysis Platform for Indian Markets
A comprehensive stock prediction platform combining machine learning, real-time market data, and advanced technical analysis for Indian stock market indices (NIFTY 50, BANKNIFTY, NIFTY IT). Built with Flutter for cross-platform mobile/web support and FastAPI for high-performance backend services.
- Live price streaming via WebSocket connections
- Integration with Zerodha Kite API for real-time Indian market data
- Historical data fetching from Yahoo Finance
- Support for NIFTY 50, BANKNIFTY, and NIFTY IT indices
- Machine learning models for price prediction
- Technical indicator-based feature engineering
- Confidence scoring for predictions
- Multi-timeframe analysis
- 20+ technical indicators (SMA, EMA, RSI, MACD, Bollinger Bands, ATR)
- Custom screener with configurable filters
- AI-powered stock screening
- Backtesting framework for strategy validation
- Flutter-based mobile application (iOS & Android)
- Real-time price charts with Syncfusion
- Interactive gauges and visualizations
- Dark mode support
- RESTful API with comprehensive documentation
- WebSocket support for real-time updates
- Docker containerization
- Comprehensive logging and error handling
graph TB
subgraph "Client Layer"
A[Flutter Mobile App]
B[Web Interface]
end
subgraph "API Gateway"
C[FastAPI Backend<br/>Port 8000]
end
subgraph "Services Layer"
D[Price Service]
E[Prediction Service]
F[Screener Service]
G[Kite Service]
H[Backtest Service]
end
subgraph "Data Sources"
I[Zerodha Kite API]
J[Yahoo Finance]
K[Local Cache]
end
subgraph "ML Pipeline"
L[Feature Engineering]
M[Model Loader]
N[Predictor]
end
A -->|REST/WebSocket| C
B -->|REST/WebSocket| C
C --> D
C --> E
C --> F
C --> G
C --> H
D --> I
D --> J
D --> K
E --> L
L --> M
M --> N
G --> I
F --> D
H --> D
style A fill:#4285f4,stroke:#333,stroke-width:2px,color:#fff
style B fill:#4285f4,stroke:#333,stroke-width:2px,color:#fff
style C fill:#0f9d58,stroke:#333,stroke-width:2px,color:#fff
style D fill:#f4b400,stroke:#333,stroke-width:2px
style E fill:#f4b400,stroke:#333,stroke-width:2px
style F fill:#f4b400,stroke:#333,stroke-width:2px
style G fill:#f4b400,stroke:#333,stroke-width:2px
style H fill:#f4b400,stroke:#333,stroke-width:2px
style I fill:#db4437,stroke:#333,stroke-width:2px,color:#fff
style J fill:#db4437,stroke:#333,stroke-width:2px,color:#fff
style K fill:#db4437,stroke:#333,stroke-width:2px,color:#fff
style L fill:#ab47bc,stroke:#333,stroke-width:2px,color:#fff
style M fill:#ab47bc,stroke:#333,stroke-width:2px,color:#fff
style N fill:#ab47bc,stroke:#333,stroke-width:2px,color:#fff
sequenceDiagram
participant User
participant Flutter App
participant FastAPI
participant KiteAPI
participant ML Engine
participant Database
User->>Flutter App: Open App
Flutter App->>FastAPI: GET /api/v1/health
FastAPI-->>Flutter App: System Status
User->>Flutter App: Search Stock
Flutter App->>FastAPI: GET /api/v1/search?query=RELIANCE
FastAPI->>Database: Query Tickers
Database-->>FastAPI: Matching Stocks
FastAPI-->>Flutter App: Search Results
User->>Flutter App: Select Stock
Flutter App->>FastAPI: WebSocket Connect
FastAPI->>KiteAPI: Subscribe to Ticker
loop Real-time Updates
KiteAPI-->>FastAPI: Price Update
FastAPI-->>Flutter App: WebSocket Message
Flutter App->>User: Update Chart
end
User->>Flutter App: Request Prediction
Flutter App->>FastAPI: POST /api/v1/predict
FastAPI->>ML Engine: Generate Features
ML Engine->>ML Engine: Load Model
ML Engine->>ML Engine: Make Prediction
ML Engine-->>FastAPI: Prediction + Confidence
FastAPI-->>Flutter App: Prediction Result
Flutter App->>User: Display Prediction
style User fill:#4285f4,stroke:#333,stroke-width:2px,color:#fff
style Flutter App fill:#02569B,stroke:#333,stroke-width:2px,color:#fff
style FastAPI fill:#009688,stroke:#333,stroke-width:2px,color:#fff
style KiteAPI fill:#db4437,stroke:#333,stroke-width:2px,color:#fff
style ML Engine fill:#ab47bc,stroke:#333,stroke-width:2px,color:#fff
style Database fill:#f4b400,stroke:#333,stroke-width:2px
graph LR
subgraph "Frontend"
A[Flutter 3.9.2]
B[Dart]
C[Syncfusion Charts]
D[Provider State Mgmt]
end
subgraph "Backend"
E[FastAPI 0.115.6]
F[Python 3.14]
G[Uvicorn]
H[WebSockets]
end
subgraph "Data & ML"
I[Pandas]
J[yfinance]
K[Kite Connect]
L[Custom ML Models]
end
subgraph "Infrastructure"
M[Docker]
N[Nginx]
O[SQLite]
end
A --> E
C --> A
D --> A
E --> I
E --> J
E --> K
E --> L
M --> E
N --> E
style A fill:#02569B,stroke:#333,stroke-width:2px,color:#fff
style E fill:#009688,stroke:#333,stroke-width:2px,color:#fff
style F fill:#3776ab,stroke:#333,stroke-width:2px,color:#fff
style I fill:#150458,stroke:#333,stroke-width:2px,color:#fff
style M fill:#2496ed,stroke:#333,stroke-width:2px,color:#fff
stock_predictor/
βββ π± Frontend (Flutter)
β βββ lib/
β β βββ main.dart # App entry point
β β βββ providers/ # State management
β β βββ screens/ # UI screens
β β βββ services/ # API clients
β β βββ widgets/ # Reusable components
β β βββ theme/ # App theming
β βββ android/ # Android platform
β βββ ios/ # iOS platform
β βββ pubspec.yaml # Flutter dependencies
β
βββ π§ Backend (FastAPI)
β βββ app/
β β βββ api/
β β β βββ endpoints/ # API route handlers
β β β βββ health.py # Health checks
β β β βββ predict.py # ML predictions
β β β βββ kite.py # Kite API integration
β β β βββ screener.py # Stock screening
β β β βββ websocket.py # WebSocket handler
β β β βββ ...
β β βββ core/
β β β βββ config.py # App configuration
β β β βββ logging_config.py # Logging setup
β β βββ ml/
β β β βββ feature_engineering.py
β β β βββ model_loader.py
β β β βββ predictor.py
β β βββ services/ # Business logic
β β β βββ kite_service.py
β β β βββ prediction_service.py
β β β βββ screener_service.py
β β β βββ ...
β β βββ models/
β β βββ schemas.py # Pydantic models
β βββ main.py # FastAPI app
β βββ requirements.txt # Python dependencies
β βββ Dockerfile # Container config
β
βββ π Data & ML
β βββ data/
β β βββ raw/ # Raw market data
β β βββ processed/ # Processed features
β βββ models/ # Trained ML models
β βββ notebooks/ # Jupyter notebooks
β β βββ 01_data_ingestion.py
β β βββ 02_feature_engineering.py
β βββ src/ # Core ML modules
β βββ data_ingest.py
β βββ features.py
β βββ utils.py
β
βββ π Deployment
β βββ docker-compose.yml # Multi-container setup
β βββ nginx.conf # Reverse proxy config
β βββ deployment/ # Deployment scripts
β
βββ π Configuration
βββ config.json # App configuration
βββ .env.example # Environment template
βββ setup_env.sh # Environment setup
- Python 3.10+ (3.14 recommended)
- Flutter 3.9.2+
- Docker (optional, for containerized deployment)
- Zerodha Kite API credentials (for live market data)
-
Clone the repository
git clone https://github.com/yourusername/stock_predictor.git cd stock_predictor -
Set up Python environment
# Create virtual environment python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate # Install dependencies cd backend pip install -r requirements.txt
-
Configure environment variables
# Copy example env file cp backend/.env.example backend/.env # Edit .env and add your API keys nano backend/.env
-
Run the backend server
cd backend python run.pyThe API will be available at
http://localhost:8000- API Documentation:
http://localhost:8000/docs - Alternative Docs:
http://localhost:8000/redoc
- API Documentation:
-
Install Flutter dependencies
flutter pub get
-
Run the app
# For mobile (iOS/Android) flutter run # For web flutter run -d chrome # For desktop flutter run -d macos # or windows/linux
# Build and run with Docker Compose
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose downGET /healthReturns system health status and version information.
GET /api/v1/search?query={symbol}Search for stocks by symbol or name.
Example:
curl http://localhost:8000/api/v1/search?query=RELIANCEGET /api/v1/price/{symbol}Get current price and basic information for a stock.
POST /api/v1/predict
Content-Type: application/json
{
"symbol": "RELIANCE",
"timeframe": "1d"
}POST /api/v1/screener
Content-Type: application/json
{
"min_price": 100,
"max_price": 5000,
"min_volume": 100000,
"rsi_min": 30,
"rsi_max": 70
}const ws = new WebSocket('ws://localhost:8000/api/v1/ws/prices');
ws.onopen = () => {
ws.send(JSON.stringify({
action: 'subscribe',
symbols: ['RELIANCE', 'TCS', 'INFY']
}));
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Price update:', data);
};GET /api/v1/kite/loginRedirects to Kite login page for authentication.
GET /api/v1/kite/callback?request_token={token}Callback endpoint after Kite authentication.
The platform includes comprehensive technical analysis with the following indicators:
| Category | Indicators |
|---|---|
| Trend | SMA (20, 50, 200), EMA (12, 26), MACD |
| Momentum | RSI (14), MACD Histogram, Rate of Change |
| Volatility | Bollinger Bands, ATR (14), Standard Deviation |
| Volume | Volume MA, Price-Volume Trend, OBV |
| Custom | Price Returns, Log Returns, Rolling Statistics |
graph LR
A[Raw OHLCV Data] --> B[Price Transformations]
B --> C[Technical Indicators]
C --> D[Lag Features]
D --> E[Rolling Statistics]
E --> F[Feature Matrix]
F --> G[Model Training]
F --> H[Predictions]
style A fill:#4285f4,stroke:#333,stroke-width:2px,color:#fff
style F fill:#0f9d58,stroke:#333,stroke-width:2px,color:#fff
style G fill:#f4b400,stroke:#333,stroke-width:2px
style H fill:#db4437,stroke:#333,stroke-width:2px,color:#fff
| Index | Symbol | Description |
|---|---|---|
| NIFTY 50 | ^NSEI | India's benchmark stock market index |
| BANKNIFTY | ^NSEBANK | Banking sector index |
| NIFTY IT | ^CNXIT | Information Technology sector index |
-
Yahoo Finance (
yfinance)- Historical OHLCV data
- Free, no API key required
- Daily updates
-
Zerodha Kite API
- Real-time market data
- Live price streaming
- Requires API credentials
# Backend tests
cd backend
pytest tests/ -v
# Run specific test
pytest tests/test_search.py -v
# With coverage
pytest --cov=app tests/# Format code
black backend/app/
# Lint
flake8 backend/app/
# Type checking
mypy backend/app/# Automated setup
chmod +x setup_env.sh
./setup_env.sh-
Home Dashboard
- Market overview
- Trending stocks
- Quick access to favorites
-
Stock Detail
- Real-time price chart
- Technical indicators
- AI predictions
- Historical performance
-
Screener
- Custom filters
- AI-powered recommendations
- Saved screens
-
Watchlist
- Personal stock list
- Real-time updates
- Price alerts
Create a .env file in the backend/ directory:
# Environment
ENVIRONMENT=development
DEBUG=True
# Server
HOST=0.0.0.0
PORT=8000
# API Keys
ALPHA_VANTAGE_API_KEY=your_key_here
KITE_API_KEY=your_kite_api_key
KITE_API_SECRET=your_kite_api_secret
KITE_REDIRECT_URL=http://localhost:8000/api/v1/kite/callback
# Database
DATABASE_URL=sqlite:///./stock_predictor.db{
"indices": {
"NIFTY50": "^NSEI",
"BANKNIFTY": "^NSEBANK",
"NIFTYIT": "^CNXIT"
},
"data": {
"start_date": "2020-01-01",
"interval": "1d"
},
"ai": {
"entry_threshold": 0.55,
"exit_threshold": 0.5,
"min_confidence": 0.6
}
}Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow the existing code style
- Write tests for new features
- Update documentation as needed
- Ensure all tests pass before submitting PR
This project is licensed under the MIT License - see the LICENSE file for details.
IMPORTANT: This platform is for educational and research purposes only. Stock market predictions are inherently uncertain and should not be used as the sole basis for investment decisions. Always consult with qualified financial advisors before making any investment decisions. Past performance does not guarantee future results.
- Yahoo Finance for providing free historical market data
- Zerodha Kite for real-time Indian market data API
- FastAPI for the excellent web framework
- Flutter for cross-platform mobile development
- Syncfusion for beautiful chart components
- Add more ML models (LSTM, Transformer)
- Implement portfolio tracking
- Add options chain analysis
- Support for more exchanges (BSE, MCX)
- Mobile push notifications
- Advanced charting tools
- Social sentiment analysis
- Paper trading simulator
β Star this repo if you find it helpful!