This project is a stock market application built using Flask, a Python-based web framework. It includes functionalities for user registration, login, adding stocks to a wishlist, predicting stock prices, and fetching stock data. The application uses MongoDB for data storage, yfinance for fetching stock data, and scikit-learn for linear regression modeling.
-
Flask Web Framework
- Flask is used to create the web application with various routes to handle user interactions.
-
MongoDB
- MongoDB stores user data and wishlist data.
pymongois used to interact with MongoDB. - Collections:
users_collection: Stores user credentials.wishlist_collection: Stores users' stock wishlists.
- MongoDB stores user data and wishlist data.
-
YFinance
yfinancelibrary is used to fetch stock data for a given ticker.
-
Scikit-Learn
- The
LinearRegressionmodel from scikit-learn is used to predict the next day's stock price based on historical data.
- The
-
User Registration
@app.route('/register', methods=['GET', 'POST'])- Handles user registration. Checks if the username already exists, then saves the new user if the username is unique.
-
User Login
@app.route('/login', methods=['GET', 'POST'])- Handles user login. Verifies user credentials and starts a session if the credentials are valid.
-
Index Page
@app.route('/', methods=['GET'])- The landing page of the application. Redirects to the dashboard if the user is logged in.
-
Dashboard
@app.route('/dashboard', methods=['GET', 'POST'])- Displays the user's dashboard with stock data and wishlist.
-
Add to Wishlist
@app.route('/add_to_wishlist', methods=['POST'])- Allows logged-in users to add a stock ticker to their wishlist.
-
Logout
@app.route('/logout')- Logs out the user by clearing the session.
-
Predict Price
@app.route('/predict_price', methods=['POST'])- Uses the
predict_next_day_pricefunction to predict the next day's stock price for a given ticker.
-
Search Ticker
@app.route('/search_ticker', methods=['POST'])- Fetches and returns stock data for a given ticker.
-
Predict Next Day Price
predict_next_day_price(ticker)- Fetches the last month's stock data, trains a linear regression model, and predicts the next day's closing price.
-
Search Ticker Data
search_ticker_data(ticker)- Fetches the last 6 months of stock data and the current day's stock data. It also predicts the next day's closing price using the
predict_next_day_pricefunction.
- Linear Regression Model
- The model is trained using the historical closing prices of a stock.
- The date is converted to ordinal format to serve as the feature for the model.
- The trained model is used to predict the next day's closing price based on the most recent date.
- Flask: Web framework to handle routing and web requests.
- MongoDB: Database to store user and wishlist information.
- YFinance: Library to fetch historical stock data.
- Scikit-Learn: Machine learning library to build the linear regression model.
- Gunicorn: WSGI HTTP server for running the Flask app in production.