Overview
The LSTM Stock Predictor is an advanced AI-powered financial analysis platform that uses Long Short-Term Memory (LSTM) neural networks to predict stock prices. The system is built with TensorFlow.js for real-time browser-based inference and provides professional-grade accuracy for financial market analysis.
Key Capabilities
- Real-Time Predictions: Live NQ futures price prediction using 1-minute data intervals
- Historical Analysis: Backtesting and performance evaluation on historical market data
- Exceptional Accuracy: 99.91% statistical accuracy with $9.10 Mean Absolute Error
- Browser-Based: Zero-latency predictions running entirely in your browser
- Professional Visualization: Interactive charts with detailed performance metrics
Exceptional Performance Highlights
Hit Rate Analysis
99.95% of predictions within 1% accuracy
99.99% of predictions within 2% accuracy
100.00% of predictions within 5% accuracy
Statistical Accuracy
Above Mean: 99.91% accuracy
Below Mean: 99.92% accuracy
Overall: 99.91% statistical accuracy
Correlation Metrics
Correlation: 1.0000 (Perfect)
R-squared: 1.0000 (Perfect fit)
MAPE: 0.06% (Exceptional)
Production Ready
Status: Exceptional Model
Assessment: Ready for production
Bias: Low bias, well-centered
Important: This platform is designed for educational and research purposes. Always conduct your own financial analysis before making investment decisions.
Getting Started
Quick Start Guide
- Dashboard: Start at the main dashboard to understand the platform capabilities
- Historical Analysis: View backtesting results and model performance metrics
- Real-Time Predictions: Set up live market data feed for real-time analysis
System Requirements
- Modern web browser (Chrome, Firefox, Safari, Edge)
- JavaScript enabled
- Stable internet connection for real-time data
- Twelve Data API key (free tier: 800 requests/day)
First Time Setup
For real-time predictions, you'll need a free API key from Twelve Data:
- Visit twelvedata.com
- Sign up for a free account (800 requests/day)
- Copy your API key
- Navigate to the Real-Time page and enter your API key
Features & Pages
Dashboard
Overview of the platform with key statistics, feature highlights, and quick access to all tools. Displays model accuracy, mean absolute error, and technology stack information.
Historical Analysis
Backtesting interface showing actual vs predicted prices on historical data. Includes performance metrics like MAE, RMSE, and accuracy percentages with interactive charts.
Real-Time Predictions
Live market analysis with 1-minute NQ futures data via QQQ scaling. Features real-time charts, prediction confidence, and market status indicators.
Page-Specific Features
Historical Analysis Page
- Interactive prediction vs actual price charts
- Performance statistics (MAE, RMSE, Accuracy)
- Model evaluation metrics
- Refresh functionality for new analysis
Real-Time Page
- Live NQ futures price tracking via QQQ
- 5-minute ahead LSTM predictions
- Real-time accuracy monitoring
- Market session status
- API response time tracking
- Persistent prediction history
Model Architecture
LSTM Neural Network Design
- Architecture: 64-unit LSTM layer with dropout regularization
- Input Shape: (batch_size, 20, 5) - 20 time steps with 5 features
- Output: 5-step ahead price prediction
- Training: 60 epochs with batch size 64
- Optimization: Adam optimizer with 0.0005 learning rate
Feature Engineering
The model uses 5 key features for each time step:
- Close Price: Primary target variable
- High Price: Session high price
- Low Price: Session low price
- Open Price: Session opening price
- Volume: Trading volume indicator
Data Preprocessing
# MinMaxScaler normalization
scaled_features = (features - data_min) / data_range
scaled_price = (price - price_min) / price_range
# Sequence creation (20 time steps)
X = sequences[:-1] # Input sequences
y = prices[20:] # Target prices
Model Performance
- Statistical Accuracy: 99.91%
- Mean Absolute Error: $9.10
- Root Mean Square Error: $15.93
- Mean Absolute Percentage Error: 0.06%
- Correlation Coefficient: 1.0000
- R-squared: 1.0000
- Prediction Horizon: 5 steps ahead
- Sequence Length: 20 historical time steps
Data Processing
Data Sources
- Training Data: Historical NQ futures data (2007-2025 prices)
- Real-Time Data: QQQ ETF scaled to NQ futures (QQQ × 41.36)
- API Provider: Twelve Data (free tier: 800 requests/day)
- Data Frequency: 1-minute intervals for real-time analysis
NQ Futures Tracking
Since direct NQ futures data requires expensive subscriptions, we use QQQ ETF as a proxy:
NQ_price ≈ QQQ_price × 41.36
QQQ tracks the NASDAQ-100 index, which the NQ E-mini futures contract is based on, providing an excellent correlation for prediction purposes.
Data Pipeline
- Fetch: Real-time QQQ data from Twelve Data API
- Scale: Apply QQQ to NQ scaling factor
- Feature Engineering: Calculate technical indicators
- Normalize: Apply MinMaxScaler transformation
- Sequence: Create 20-step input sequences
- Predict: Run LSTM inference
- Inverse Scale: Convert back to price units
Rate Limiting: The free Twelve Data API allows 800 requests per day. The system is optimized for 1-minute intervals to maximize usage efficiency.
Real-Time Setup
API Configuration
- Navigate to the Real-Time page
- Enter your Twelve Data API key in the configuration section
- The system is pre-configured for 1-minute intervals
- Click "Connect & Start" to begin real-time analysis
Market Hours
NQ futures trade nearly 24/7 with brief maintenance windows:
- Regular Trading: 9:30 AM - 4:00 PM ET
- Extended Hours: 6:00 PM - 9:30 AM ET (next day)
- Maintenance: Daily 4:00 PM - 6:00 PM ET
Real-Time Features
Live Price Tracking
Current QQQ price scaled to NQ futures with real-time updates every minute.
5-Min Predictions
LSTM model predicts price 5 minutes ahead with confidence intervals.
Performance Metrics
Live accuracy tracking, API response times, and prediction error analysis.
Interactive Charts
Real-time visualization with 25-candle history and persistent predictions.
Troubleshooting Real-Time Issues
- No Data: Check API key validity and request limits
- Rate Limiting: Wait for rate limit reset (daily at midnight UTC)
- Market Closed: Limited activity during maintenance windows
- Connection Issues: Verify internet connectivity
API Reference
Twelve Data Integration
The platform integrates with Twelve Data's time series API:
GET https://api.twelvedata.com/time_series
?symbol=QQQ
&interval=1min
&outputsize=100
&apikey=YOUR_API_KEY
Response Format
{
"meta": {
"symbol": "QQQ",
"interval": "1min",
"currency": "USD",
"exchange_timezone": "America/New_York"
},
"values": [
{
"datetime": "2024-01-15 16:00:00",
"open": "450.12",
"high": "450.45",
"low": "449.98",
"close": "450.23",
"volume": "1234567"
}
]
}
Model Inference API
The LSTM model runs locally using TensorFlow.js:
// Load model
const model = await tf.loadLayersModel('tfjs_model/model/model.json');
// Prepare input (batch_size=1, sequence_length=20, features=5)
const input = tf.tensor3d([sequence], [1, 20, 5]);
// Make prediction
const prediction = model.predict(input);
const scaledPrice = prediction.dataSync()[0];
// Inverse scale to get actual price
const actualPrice = scaledPrice * data_range + data_min;
Error Handling
- Rate Limit (429): Display warning and pause requests
- Invalid API Key (401): Prompt user to check credentials
- No Data (404): Handle market closure or invalid symbol
- Network Error: Retry with exponential backoff
Troubleshooting
Common Issues
Model Loading Problems
- Issue: "Failed to load model" error
- Solution: Ensure TensorFlow.js files are accessible and not blocked by browser
- Check: Browser console for detailed error messages
Real-Time Data Issues
- No Data Received: Verify API key and check rate limits
- Outdated Predictions: Markets may be closed or in maintenance
- High Error Rates: Market volatility can affect prediction accuracy
Performance Issues
- Slow Loading: Clear browser cache and refresh
- Memory Usage: Close other browser tabs for optimal performance
- Chart Rendering: Disable browser extensions that might interfere
Browser Compatibility
Recommended Browsers:
- Chrome 90+ (Best performance)
- Firefox 88+
- Safari 14+
- Edge 90+
Debug Mode
Open browser developer tools (F12) to access detailed logging:
- Model loading progress
- API request/response details
- Prediction accuracy metrics
- Performance timing information
Technical Specifications
Model Specifications
- Framework: TensorFlow 2.x / Keras
- Runtime: TensorFlow.js 4.10.0
- Model Size: ~2.5MB (optimized for web)
- Inference Speed: <50ms per prediction
- Memory Usage: ~100MB RAM
Data Specifications
- Training Dataset: 5.9 Million historical data points
- Time Resolution: 1-minute intervals
- Feature Count: 5 engineered features per time step
- Sequence Length: 20 historical time steps
Performance Benchmarks
- Statistical Accuracy: 99.91% overall accuracy
- Mean Absolute Error: $9.10
- Root Mean Square Error: $15.93
- Hit Rate (within 1%): 99.95%
- Hit Rate (within 2%): 99.99%
- Hit Rate (within 5%): 100.00%
- Median Absolute Error: $5.20
- Prediction Bias: -0.00% (well-centered)
- Real-Time Latency: <1 second end-to-end
System Requirements
- CPU: Modern multi-core processor
- RAM: 4GB+ available memory
- Network: Stable broadband connection
- Storage: 50MB for model and assets
Disclaimer: This platform is for educational and research purposes only. Past performance does not guarantee future results. Always consult with financial professionals before making investment decisions.