Skip to content

MJ665/StoxSight

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StoxSight 📈🧠🔗

AI and Blockchain-Powered Predictive Analytics for Secure Stock and Crypto Markets

StoxSight is a B.Tech project aiming to provide users with advanced stock and cryptocurrency market analysis by leveraging Artificial Intelligence for predictive insights and (planned) Blockchain technology for data integrity. This application integrates data from various sources, processes it through sophisticated ML models, and delivers qualitative and quantitative analysis to aid in investment decision-making.

Live Demo (Frontend): [YOUR_NEXTJS_APP_VERCEL_DEPLOYMENT_URL_HERE] (e.g., https://stox-sight.vercel.app) ML Service API (Backend): https://mj665-stox-sight-ml-service.hf.space

<iframe src="https://player.vimeo.com/video/1085158653?badge=0&autopause=0&player_id=0&app_id=58479" frameborder="0" allow="autoplay; fullscreen; picture-in-picture; clipboard-write; encrypted-media" style="position:absolute;top:0;left:0;width:100%;height:100%;" title="Intro Video - Made with Clipchamp"></iframe>
<script src="https://player.vimeo.com/api/player.js"></script>

Features

LLM-Powered Stock Analysis: Get in-depth qualitative analysis and structured insights for Indian stocks based on user queries, fundamental data (from Screener.in), and market data (from NSE India).

Multi-Model ML Predictions (via separate ML Service):

Accepts historical stock data (CSV).

Trains LSTM, GRU, Transformer, and Polynomial Regression models.

Performs hyperparameter tuning using RandomizedSearchCV.

Generates future price predictions.

Produces a comprehensive PDF report with model results, plots, and AI-driven qualitative analysis.

Sends the PDF report via email.

User Authentication: Secure sign-up and sign-in using Google and Email/Password (NextAuth.js).

Database Integration: User data, analysis requests, and results are stored using Prisma and PostgreSQL.

(Planned) Blockchain Integration: For tamper-proof logging of critical financial events or predictions.

Tech Stack

Main Application (This Repository - StoxSight):

Framework: Next.js 14+ (App Router)

Language: TypeScript

UI: React, Tailwind CSS, shadcn/ui

State Management: React Context / Zustand (or as applicable)

Authentication: NextAuth.js

Database ORM: Prisma

Database: PostgreSQL (e.g., Neon DB, Supabase, or local)

Data Fetching (Frontend to Backend): Fetch API / SWR / React Query

Deployment: Vercel

ML Service (Separate Repository - stox-sight-ml-service):

Framework: FastAPI

Language: Python

Machine Learning: TensorFlow/Keras, Scikit-learn, Pandas, NumPy, SciPy

Hyperparameter Tuning: Scikit-learn (RandomizedSearchCV), Scikeras

Data Fetching (Input): CSV Upload

Report Generation: FPDF2 (for PDFs), Matplotlib (for plots)

AI Qualitative Analysis: Google Generative AI (Gemini)

Email Sending: smtplib, python-decouple

Deployment: Hugging Face Spaces (Docker)

Project Structure (This Repository - Next.js App) stox-sight/ ├── src/ │ ├── app/ # Next.js App Router (pages, layouts, API routes) │ │ ├── api/ │ │ │ ├── auth/ # NextAuth routes │ │ │ ├── llmStockInfo/ # API for direct LLM analysis │ │ │ └── mlService/ # API to trigger and manage ML service jobs │ │ ├── components/ # React components (UI, Appbar, Hero, etc.) │ │ └── (pages like signin, signup, dashboard...) │ ├── lib/ # Shared utilities (e.g., Prisma client instance) │ ├── generated/ # Prisma client output │ └── types/ # TypeScript type definitions (e.g., next-auth.d.ts) ├── prisma/ │ ├── schema.prisma # Database schema │ └── migrations/ # Database migrations ├── public/ # Static assets ├── .env.example # Example environment variables ├── next.config.mjs # Next.js configuration ├── postcss.config.js # PostCSS configuration ├── tailwind.config.js # Tailwind CSS configuration └── tsconfig.json # TypeScript configuration

Getting Started (Local Development - Next.js App) Prerequisites

Node.js (v18.x or later recommended)

npm or yarn

PostgreSQL database instance (local or cloud-hosted)

Git

Setup

Clone the repository:

git clone https://github.com/MJ665/StoxSight.git cd StoxSight IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Bash IGNORE_WHEN_COPYING_END

Install dependencies:

npm install

or

yarn install IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Bash IGNORE_WHEN_COPYING_END

Set up PostgreSQL Database:

Create a PostgreSQL database.

Obtain the connection URL (e.g., postgresql://user:password@host:port/database).

Configure Environment Variables:

Create a .env file in the root of the project by copying .env.example (if provided, otherwise create new).

Add the following variables:

DATABASE_URL="your_postgresql_connection_url"

NextAuth.js Secrets

NEXTAUTH_URL="http://localhost:3000" # For development NEXTAUTH_SECRET="your_super_secret_nextauth_string_here" # Generate a strong random string

Google OAuth Provider (for NextAuth.js)

GOOGLE_CLIENTID="your_google_client_id" GOOGLE_SECRET="your_google_client_secret"

Google Generative AI API Keys (for /api/llmStockInfo)

GOOGLE_API_ONE_IDEA_GENERATOR="your_gemini_api_key_1" GOOGLE_API_TWO_RESPONCE_GENERATOR="your_gemini_api_key_2" GOOGLE_API_THREE_CROSS_VALIDATION_BETTER_RESPONCE="your_gemini_api_key_3"

URL of your deployed FastAPI ML Service

ML_SERVICE_URL="https://mj665-stox-sight-ml-service.hf.space/train-predict/"

For local testing of ML service integration, point to http://127.0.0.1:8000/train-predict/

if your ML service is running locally on port 8000.

IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Env IGNORE_WHEN_COPYING_END

Apply Database Migrations & Generate Prisma Client:

npx prisma migrate dev --name initial_setup npx prisma generate IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Bash IGNORE_WHEN_COPYING_END

(If you already have a PredictionRun or LlmAnalysisRun model, ensure your migration names reflect schema changes, e.g., --name add_llm_analysis_model)

Run the development server:

npm run dev

or

yarn dev IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Bash IGNORE_WHEN_COPYING_END

Open http://localhost:3000 in your browser.

API Endpoints (Next.js Backend)

  1. LLM Stock Info Analysis

Endpoint: POST /api/llmStockInfo

Purpose: Provides direct AI-driven qualitative analysis for a stock using Google Gemini, based on Screener.in data and NSE market data snippets. Results are stored in the LlmAnalysisRun table.

Request Body (JSON):

{ "query": "Your question about the stock, e.g., future outlook?", "symbol": "STOCK_SYMBOL", "market": "INDIA" } IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Json IGNORE_WHEN_COPYING_END

Example curl:

curl -X POST http://localhost:3000/api/llmStockInfo
-H "Content-Type: application/json"
-d '{ "query": "for Tata consultancy services What is the future outlook of this stock tell me indepth stock analysis?", "symbol": "TCS", "market": "INDIA" }' IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Bash IGNORE_WHEN_COPYING_END

Response: JSON object containing success, textual result, and a structured conclusion JSON. (See example output in earlier messages).

  1. Trigger ML Service for Prediction & Report

Endpoint: POST /api/mlService (This Next.js route prepares data and calls the FastAPI ML service)

Purpose: Fetches historical data for a stock, saves it to a temporary CSV, and then calls the separate FastAPI ML service to train models (LSTM, GRU, Transformer, Poly), generate predictions, create plots, and a PDF report. The request and a summary of the ML service's response are stored in the PredictionRun table.

Request Body (JSON):

{ "stockSymbol": "STOCK_SYMBOL", "market": "INDIA", "email": "user_email_for_report@example.com", "startDate": "YYYY-MM-DD", "endDate": "YYYY-MM-DD" } IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Json IGNORE_WHEN_COPYING_END

Example curl:

curl -X POST http://localhost:3000/api/mlService
-H "Content-Type: application/json"
-d '{ "stockSymbol": "INFY", "market": "INDIA", "email": "test@example.com", "startDate": "2020-01-01", "endDate": "2023-12-31" }' IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Bash IGNORE_WHEN_COPYING_END

Response: JSON indicating if the job was successfully submitted to the ML service, along with IDs for tracking.

  1. Get LLM Analysis History

Endpoint: GET /api/llmStockInfo

Purpose: Retrieves past LLM analysis runs. If authenticated, shows runs for the current user. If not, may show recent public/anonymous runs (configurable).

Authentication: Uses NextAuth session.

ML Service Details (FastAPI - Separate Repo)

Repository: https://github.com/MJ665/stox-sight-ml-service

Deployed Endpoint: https://mj665-stox-sight-ml-service.hf.space/train-predict/

Functionality: Receives a CSV of historical stock data and an email address. Trains LSTM, GRU, Transformer, and Polynomial Regression models. Performs hyperparameter tuning via RandomizedSearchCV. Generates future predictions, plots, a comprehensive PDF report, and an AI qualitative summary using Gemini. Attempts to email the PDF report.

Example curl to directly call the deployed ML Service:

curl -X POST "https://mj665-stox-sight-ml-service.hf.space/train-predict/"
-H "accept: application/json"
-H "Content-Type: multipart/form-data"
-F "csv_file=@/path/to/your/local_stock_data.csv"
-F "user_email_to_send_to=your_email@example.com" IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Bash IGNORE_WHEN_COPYING_END

(Replace /path/to/your/local_stock_data.csv with an actual path to a CSV file formatted with 'Date' and 'Close' columns).

Example Response from ML Service:

{ "message": "Processing complete.", "run_id": "unique_run_id_from_ml_service", "stock_symbol": "TCS", "lstm_results": { /* ...metrics, predictions, best_params... / }, "gru_results": { / ... / }, "transformer_results": { / ... / }, "polynomial_results": { / ... / }, "trading_suggestion_tomorrow": { / ... / }, "ai_qualitative_analysis": { / ...Gemini JSON output... / }, "plot_urls": { "lstm_test_plot_url": "/outputs/plots/run_id_lstm_test.png", / ... other plot URLs ... / }, "pdf_report_url": "/outputs/pdfs/run_id_report.pdf", "email_sent_status": "Success" / or "Failed: reason" or "Skipped" */ } IGNORE_WHEN_COPYING_START content_copy download Use code with caution. Json IGNORE_WHEN_COPYING_END

(Note: The /outputs/... URLs are relative to the ML service's base URL).

Future Work & Enhancements

Full Blockchain Integration: Implement tamper-proof logging for critical predictions or transactions.

Crypto Market Analysis: Extend LLM and ML capabilities to cryptocurrencies.

US Stock Market Analysis: Enable analysis for US stocks.

User Dashboard: Display historical prediction runs, portfolio tracking, watchlists.

Advanced ML Model Ensembling: Implement Stacking or Voting Regressors as suggested.

Improved Positional Encoding for Transformer.

More Sophisticated Data Adaptation Layers.

Automated Retraining Pipelines and Concept Drift Detection.

UI/UX Refinements.

Robust Error Handling and User Feedback.

Contributing

This is currently a B.Tech project. Contributions and suggestions are welcome after the initial development phase and hackathon submission. Please feel free to open an issue or a pull request on the respective repositories.

Main App: https://github.com/MJ665/StoxSight

ML Service: https://github.com/MJ665/stox-sight-ml-service

Acknowledgements

Perplexity AI for suggestions on advanced ML models.

The open-source community for libraries like Next.js, FastAPI, TensorFlow, Scikit-learn, Prisma, NextAuth.js, shadcn/ui, and stock-nse-india.

Contact

Meet Jain (MJ665)

Portfolio/Website: https://mj665.in

Resume: [YOUR_RESUME_LINK_HERE]

LinkedIn: [https://www.linkedin.com/in/mj2h/] (Optional)

This README provides a comprehensive overview. You'll need to:

Fill in placeholders: [https://stox-sight.mj665.in/], [https://docs.google.com/document/d/1cVICbw8oGtTHjICeoM5jAZzpx95A4IOZBn1639skvVM/edit?pli=1&tab=t.0], [https://www.linkedin.com/in/mj2h/].

Create an .env.example file in your Next.js project based on the environment variables section.

Consider adding a similar, but more focused, README to your stox-sight-ml-service repository, detailing its specific setup, API, and how to run it locally (e.g., with Uvicorn).

Releases

No releases published

Packages

 
 
 

Contributors