Spaces:
Sleeping
Sleeping
File size: 10,008 Bytes
65308f4 0475bbf 65308f4 0475bbf 65308f4 0475bbf 65308f4 edbf119 65308f4 edbf119 65308f4 edbf119 |
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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
---
title: Stocks Platform
emoji: ๐
colorFrom: red
colorTo: red
sdk: docker
app_port: 8501
tags:
- streamlit
pinned: false
short_description: h2h assignment
---
# ๐ 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
```bash
Python 3.8+
pip package manager
```
### Installation
1. **Clone the repository**
```bash
git clone https://github.com/yourusername/stock-trading-platform.git
cd stock-trading-platform
```
2. **Install dependencies**
```bash
pip install -r requirements.txt
```
3. **Set up the project structure**
```bash
mkdir -p src/logs src/models
```
4. **Download or train the ML models**
```bash
# Place your trained models in src/models/
# - logistic_regression_model.pkl
# - scaler.pkl
```
5. **Run the application**
```bash
streamlit run app.py
```
6. **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
```python
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
```python
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
1. Select a stock from the dropdown menu
2. Choose your date range and technical indicator periods
3. View the ML model's next-day price prediction
4. Analyze confidence levels and technical charts
5. Export prediction data for further analysis
### 2. Trading Dashboard
1. Configure your trading strategy (SMA or EMA based)
2. Set backtesting parameters and risk management rules
3. Run the backtest and analyze performance metrics
4. Compare strategy performance vs buy-and-hold
5. Review detailed trade analysis and export results
### 3. Technical Analysis
1. Examine multiple technical indicators simultaneously
2. Identify trading signals and market trends
3. Analyze volume patterns and momentum indicators
4. Use Bollinger Bands for volatility analysis
5. 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
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](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:
1. **Check the Documentation**: Review this README and code comments
2. **Search Issues**: Look through existing GitHub issues
3. **Create New Issue**: Submit a detailed bug report or feature request
4. **Contact Developer**: Reach out via email for urgent matters
---
โญ **Star this repository if you find it helpful!** โญ
---
*Last Updated: August 2025*
|