Skip to content

com00geek/Stock_Suggestion_Python

Repository files navigation

AI Stock Advisor Web Application

A modern, elegant web application for AI-powered stock recommendations with a sophisticated frontend and Flask backend.

Requirements

Python Dependencies

Create a requirements.txt file with the following:

flask>=2.0.0
flask-cors>=3.0.0
pandas>=1.5.0
numpy>=1.20.0
scikit-learn>=1.0.0
lightgbm>=3.0.0
joblib>=1.0.0
yfinance>=0.1.0

Installation

# Install dependencies
pip install -r requirements.txt

# Or install individually:
pip install flask flask-cors pandas numpy scikit-learn lightgbm joblib yfinance

File Structure

Your project directory should look like this:

ai-stock-advisor/
├── server.py                          # Flask backend server
├── index.html                         # Frontend web interface  
├── requirements.txt                   # Python dependencies
├── feature_engineered_data.csv        # Your processed data
├── short_term_model.joblib            # 30-day model
├── medium_term_model.joblib           # 90-day model
├── long_term_model.joblib             # 365-day model
└── README.md                          # This file

Quick Start

  1. Ensure your models and data are ready:

    • Run your existing Jupyter notebook to generate the required files
    • Make sure you have: feature_engineered_data.csv and the three .joblib model files
  2. Save the frontend:

    • Save the HTML code as index.html in your project directory
  3. Save the backend:

    • Save the Python server code as server.py
  4. Install dependencies:

    pip install -r requirements.txt
  5. Start the server:

    python server.py
  6. Open your browser:

    • Navigate to http://localhost:5000
    • The modern web interface will load automatically

API Endpoints

POST /api/recommendations

Get stock recommendations based on user preferences.

Request Body:

{
    "risk_level": "Medium",
    "time_horizon": "medium", 
    "num_stocks": 10
}

Response:

{
    "success": true,
    "recommendations": [
        {
            "symbol": "RELIANCE.NS",
            "price": 2456.75,
            "volatility": 0.0234,
            "volume": 1234567,
            "rsi": 65.4,
            "macd": 12.3
        }
    ],
    "parameters": {
        "risk_level": "Medium",
        "time_horizon": "medium",
        "num_stocks": 10
    }
}

GET /api/chart/{symbol}

Get historical price data for charting.

Response:

{
    "symbol": "RELIANCE.NS",
    "dates": ["2023-01-01", "2023-01-02", ...],
    "close": [2400, 2405, ...],
    "sma_20": [2390, 2392, ...],
    "sma_50": [2385, 2387, ...],
    "volume": [1000000, 1100000, ...]
}

GET /api/status

Check server status and loaded data.

Features

Frontend

  • Modern Design: Glass-morphism effects, gradients, and smooth animations
  • Responsive Layout: Works perfectly on desktop, tablet, and mobile
  • Interactive Controls: Intuitive sliders and dropdowns for user preferences
  • Real-time Charts: Interactive price charts using Chart.js
  • Loading States: Professional loading indicators and transitions
  • Error Handling: Graceful error messages and troubleshooting guides

Backend

  • RESTful API: Clean, well-documented endpoints
  • Model Integration: Seamlessly loads and uses your trained models
  • Data Processing: Handles feature engineering and predictions
  • Error Handling: Comprehensive error catching and logging
  • CORS Support: Enables frontend-backend communication

Key Improvements over Streamlit

  1. Performance: Much faster loading and response times
  2. Customization: Full control over UI/UX design
  3. Scalability: Can handle multiple concurrent users
  4. Professional Look: Modern, polished interface
  5. API-First: Easy to integrate with mobile apps or other services

Troubleshooting

Common Issues

  1. "Model files not found"

    • Ensure you've run your Jupyter notebook to generate the .joblib files
    • Check that all three model files are in the same directory as server.py
  2. "Feature-engineered data not found"

    • Run the feature engineering script from your notebook
    • Verify feature_engineered_data.csv exists and has data
  3. "Connection refused" or API errors

    • Make sure the Flask server is running: python server.py
    • Check that no other service is using port 5000
    • Try accessing http://localhost:5000/api/status directly
  4. Charts not loading

    • Ensure the backend is returning chart data
    • Check browser console for JavaScript errors
    • Verify the stock symbol exists in your dataset

Development Tips

  • Debug Mode: The server runs in debug mode by default for development
  • Logging: Check the console output for detailed request/response information
  • Data Validation: The server includes comprehensive input validation
  • Model Performance: Each prediction includes performance metrics

Production Deployment

For production use:

  1. Set debug=False in the Flask app
  2. Use a production WSGI server like Gunicorn
  3. Add proper authentication if needed
  4. Set up HTTPS with SSL certificates
  5. Configure CORS for your production domain

Security Considerations

  • The current setup is for development/demo purposes
  • Add input validation and rate limiting for production
  • Consider authentication for sensitive financial data
  • Use HTTPS in production environments

Next Steps

  1. Add More Features: Portfolio optimization, backtesting, alerts
  2. Mobile App: Use the API to create a mobile application
  3. Real-time Data: Integrate live market data feeds
  4. User Accounts: Add user registration and portfolio tracking
  5. Advanced Charts: Add more technical indicators and chart types

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages