AI-powered stock prediction engine using machine learning and technical analysis.
- Real-time Stock Predictions - Predict price movements with confidence scores
- Technical Analysis - RSI, MACD, Bollinger Bands, and more
- AI Insights - Powered by Google Gemini for intelligent market commentary
- Batch Processing - Analyze entire portfolios at once
- Historical Tracking - Track prediction accuracy over time
- Python 3.8+ (you have 3.13.9 β)
- pip (package installer)
- Google Gemini API key (already configured β)
cd C:\Users\2cody\source\repos
git clone <your-ml-service-repo> # Or create new folder
cd Nexus-Signal-ML
# Run setup script (Windows)
setup.batThe setup script will:
- Create a Python virtual environment
- Install all dependencies (TensorFlow, Flask, etc.)
- Create necessary directories
# Activate virtual environment
venv\Scripts\activate.bat
# Start the Flask server
python app.pyThe service will start on http://localhost:5001
Open your browser and go to:
http://localhost:5001/health
You should see:
{
"status": "healthy",
"service": "ML Prediction Service",
"version": "1.0.0"
}GET /health
POST /predict
Content-Type: application/json
{
"symbol": "AAPL",
"days": 7
}
Response:
{
"symbol": "AAPL",
"current_price": 178.32,
"prediction": {
"direction": "UP",
"confidence": 72.5,
"target_price": 182.15,
"price_change_percent": 2.15,
"timeframe_days": 7
},
"signals": [
"RSI oversold (bullish)",
"MACD bullish crossover"
],
"technical_analysis": {
"rsi": 42.3,
"macd_signal": "Bullish",
"volatility": 28.5,
"volume_status": "High"
}
}POST /predict/batch
Content-Type: application/json
{
"symbols": ["AAPL", "GOOGL", "MSFT"],
"days": 7
}
POST /analyze
Content-Type: application/json
{
"symbol": "AAPL"
}
Response includes:
- Prediction
- AI-generated insights from Google Gemini
- Detailed technical analysis
- Trading recommendations
Edit .env file:
PORT=5001
GOOGLE_API_KEY=your_api_key_here
MODEL_PATH=./models/saved_models
LOG_LEVEL=INFO- Uses
yfinanceto get real-time stock data - Fetches 6 months of historical data by default
- Calculates 10+ technical indicators
- RSI, MACD, Bollinger Bands, ATR, OBV, Stochastic
- Rule-based predictions using technical indicators
- Confidence scoring system
- Can be upgraded to LSTM/TensorFlow models
- Google Gemini generates human-readable insights
- Explains "why" behind predictions
- Provides actionable recommendations
The prediction engine uses a weighted scoring system:
Score = RSI_signal + MACD_signal + BB_signal + Momentum_signal + Volume_signal
If score >= 2: Direction = UP, Confidence = 60-85%
If score <= -2: Direction = DOWN, Confidence = 60-85%
Else: Direction = NEUTRAL, Confidence = ~50%
- RSI < 30: Oversold (Bullish) +2 points
- RSI > 70: Overbought (Bearish) -2 points
- MACD > Signal: Bullish +1 point
- Price near lower BB: Bullish +1 point
- High volume: Momentum +0.5 points
Add to your Nexus-Signal-Server:
// server/routes/predictionsRoutes.js
const express = require('express');
const router = express.Router();
const axios = require('axios');
const auth = require('../middleware/authMiddleware');
const ML_SERVICE_URL = 'http://localhost:5001';
router.post('/predict', auth, async (req, res) => {
try {
const { symbol } = req.body;
const response = await axios.post(`${ML_SERVICE_URL}/predict`, { symbol });
res.json(response.data);
} catch (error) {
res.status(500).json({ error: 'Prediction service unavailable' });
}
});
module.exports = router;-
Upgrade to Deep Learning
- Implement LSTM neural networks
- Train on larger datasets
- Add sentiment analysis from news
-
Add More Features
- Options pricing models
- Portfolio optimization
- Risk analysis
-
Improve Accuracy
- Collect prediction results
- Calculate actual accuracy
- Retrain models based on performance
ml-service/
βββ app.py # Flask API server
βββ requirements.txt # Python dependencies
βββ .env # Configuration
βββ models/
β βββ predictor.py # ML prediction engine
β βββ saved_models/ # Trained models
βββ utils/
β βββ technical_indicators.py # Technical analysis
β βββ market_data.py # Data fetching
β βββ ai_insights.py # Gemini AI integration
βββ logs/ # Service logs
Edit utils/technical_indicators.py:
def calculate_your_indicator(self, data):
# Your calculation here
return indicator_values# models/trainer.py (create this file)
from predictor import StockPredictor
predictor = StockPredictor()
symbols = ['AAPL', 'GOOGL', 'MSFT', 'AMZN', 'TSLA']
predictor.train_model(symbols)venv\Scripts\activate.bat
pip install -r requirements.txtChange port in .env:
PORT=5002- Get key from: https://aistudio.google.com/apikey
- Update
.envfile - Restart service
Need help? Check the logs:
tail -f logs/ml_service.logMIT License - Built for Nexus Signal
Ready to predict the future? Let's go! π