Spaces:
Sleeping
๐ Complete Stock Trading & Prediction Platform
A sophisticated web-based stock trading platform that combines machine learning price predictions with rule-based trading strategies. Built with Streamlit, this platform offers comprehensive technical analysis, backtesting capabilities, and interactive visualizations for Indian stock markets.
๐ Features
๐ฎ Price Prediction Engine
- Machine Learning Model: Logistic regression with 59+ technical features
- Advanced Features: Volatility ratios, momentum indicators, lag features
- Confidence Analysis: Prediction probability with visual confidence gauge
- Technical Indicators: RSI, MACD, SMA, EMA, Bollinger Bands
๐ Trading Dashboard
- Multiple Strategies: SMA-based and EMA-based trading strategies
- Comprehensive Backtesting: Historical performance analysis with risk metrics
- Risk Management: Configurable stop-loss, take-profit, and position sizing
- Interactive Visualizations: Plotly-powered charts and analysis tools
๐ Technical Analysis
- 50+ Indian Stocks: Pre-configured NSE stock symbols
- Real-time Data: Yahoo Finance integration with reliable data fetching
- Multiple Timeframes: Customizable periods for technical indicators
- Advanced Charts: Candlestick patterns, volume analysis, drawdown charts
๐ Quick Start
Prerequisites
Python 3.8+
pip package manager
Installation
- Clone the repository
git clone https://github.com/yourusername/stock-trading-platform.git
cd stock-trading-platform
- Install dependencies
pip install -r requirements.txt
- Set up the project structure
mkdir -p src/logs src/models
- Download or train the ML models
# Place your trained models in src/models/
# - logistic_regression_model.pkl
# - scaler.pkl
- Run the application
streamlit run app.py
- Access the platform
Open your browser and navigate to http://localhost:8501
๐ Project Structure
stock-trading-platform/
โ
โโโ app.py # Main Streamlit application
โโโ requirements.txt # Python dependencies
โโโ README.md # Project documentation
โ
โโโ src/
โ โโโ indicators/ # Technical indicator modules
โ โ โโโ __init__.py
โ โ โโโ rsi.py # RSI calculation
โ โ โโโ sma.py # Simple Moving Average
โ โ โโโ ema.py # Exponential Moving Average
โ โ โโโ macd.py # MACD indicator
โ โ โโโ enhanced_features.py # Advanced feature engineering
โ โ
โ โโโ strategy/ # Trading strategy modules
โ โ โโโ __init__.py
โ โ โโโ rule_based_strategy.py # SMA/EMA trading strategies
โ โ
โ โโโ utils/ # Utility modules
โ โ โโโ __init__.py
โ โ โโโ backtester.py # Backtesting engine
โ โ โโโ logger.py # Logging configuration
โ โ
โ โโโ models/ # ML models and scalers
โ โ โโโ logistic_regression_model.pkl
โ โ โโโ scaler.pkl
โ โ
โ โโโ logs/ # Application logs
โ โโโ trading_app.log
โ
โโโ data/ # Data storage (optional)
โโโ processed/
๐ ๏ธ Dependencies
Core Libraries
streamlit>=1.28.0 # Web application framework
pandas>=1.5.0 # Data manipulation
numpy>=1.24.0 # Numerical computing
plotly>=5.15.0 # Interactive visualizations
yfinance>=0.2.18 # Stock data fetching
scikit-learn>=1.3.0 # Machine learning
Additional Dependencies
curl-cffi>=0.5.10 # HTTP requests with browser impersonation
pickle>=4.0 # Model serialization
datetime # Date/time handling
warnings # Warning management
logging # Application logging
๐ Supported Stocks
The platform supports 50+ major Indian stocks including:
Banking & Finance
- HDFCBANK.NS, ICICIBANK.NS, AXISBANK.NS, KOTAKBANK.NS, SBIN.NS
Technology
- TCS.NS, INFY.NS, HCLTECH.NS, TECHM.NS, WIPRO.NS
Energy & Materials
- RELIANCE.NS, ONGC.NS, COALINDIA.NS, NTPC.NS, POWERGRID.NS
Consumer Goods
- HINDUNILVR.NS, ITC.NS, NESTLEIND.NS, TATACONSUM.NS, BRITANNIA.NS
And many more...
๐ง Configuration
Technical Indicators
- RSI Period: 5-30 days (default: 14)
- Short-term SMA/EMA: 5-50 days (default: 20)
- Long-term SMA/EMA: 50-200 days (default: 50)
Trading Parameters
- Initial Capital: โน10,000 - โน10,00,000 (default: โน1,00,000)
- Transaction Cost: 0.0% - 1.0% (default: 0.1%)
- Stop Loss: 0% - 20% (default: 5%)
- Take Profit: 0% - 50% (default: 15%)
Risk Management
- Position sizing based on available capital
- Automatic stop-loss and take-profit execution
- Transaction cost simulation
- Drawdown analysis and monitoring
๐ฏ Usage Guide
1. Price Prediction
- Select a stock from the dropdown menu
- Choose your date range and technical indicator periods
- View the ML model's next-day price prediction
- Analyze confidence levels and technical charts
- Export prediction data for further analysis
2. Trading Dashboard
- Configure your trading strategy (SMA or EMA based)
- Set backtesting parameters and risk management rules
- Run the backtest and analyze performance metrics
- Compare strategy performance vs buy-and-hold
- Review detailed trade analysis and export results
3. Technical Analysis
- Examine multiple technical indicators simultaneously
- Identify trading signals and market trends
- Analyze volume patterns and momentum indicators
- Use Bollinger Bands for volatility analysis
- Monitor drawdown and risk metrics
๐ Model Performance
Machine Learning Metrics
- Accuracy: 55.0%
- F1 Score: 0.4839
- AUC Score: 0.5370
- Average Precision: 0.5300
Feature Engineering
- Total Features: 59 technical indicators
- Feature Categories: Price, Volume, Volatility, Momentum, Position
- Data Processing: StandardScaler normalization
- Model Type: Logistic Regression with regularization
๐ Advanced Features
Enhanced Technical Analysis
- Volatility Features: Multi-timeframe volatility ratios and rankings
- Lag Features: Historical price and indicator dependencies
- Volume Analysis: Volume-price relationships and momentum
- Position Features: Price position relative to historical ranges
Backtesting Engine
- Performance Metrics: Sharpe ratio, maximum drawdown, win rate
- Trade Analysis: Individual trade performance and statistics
- Risk Assessment: Drawdown analysis and volatility measures
- Comparison Tools: Strategy vs buy-and-hold performance
Interactive Visualizations
- Real-time Charts: Dynamic price action with technical overlays
- Signal Visualization: Buy/sell signals on price charts
- Performance Tracking: Portfolio value progression over time
- Distribution Analysis: Trade returns and risk metrics
๐จ Disclaimer
Important: This platform is designed for educational and research purposes only. Stock market investments carry inherent risks, and past performance does not guarantee future results.
Risk Warning:
- Always conduct your own research before making investment decisions
- Consider consulting with a qualified financial advisor
- Never invest more than you can afford to lose
- Markets can be volatile and unpredictable
๐ค Contributing
We welcome contributions to improve the platform! Here's how you can help:
Areas for Contribution
- New Trading Strategies: Implement additional algorithmic strategies
- Enhanced ML Models: Add new prediction models and features
- UI/UX Improvements: Enhance the user interface and experience
- Performance Optimization: Improve code efficiency and speed
- Bug Fixes: Report and fix issues in the codebase
Contribution Process
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐จโ๐ป Author
Zane Vijay Falcao
- Email: [email protected]
- LinkedIn: [Your LinkedIn Profile]
- GitHub: [Your GitHub Profile]
๐ Acknowledgments
- Yahoo Finance for providing reliable stock market data
- Streamlit for the excellent web application framework
- Plotly for interactive visualization capabilities
- Scikit-learn for machine learning tools and utilities
๐ Support
If you encounter any issues or have questions:
- Check the Documentation: Review this README and code comments
- Search Issues: Look through existing GitHub issues
- Create New Issue: Submit a detailed bug report or feature request
- Contact Developer: Reach out via email for urgent matters
โญ Star this repository if you find it helpful! โญ
Last Updated: August 2025