Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Streamlit Web Interface for Stock Market Prediction #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions FiFo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import streamlit as st
import yfinance as yf
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
import numpy as np
import datetime
from art import text2art

# Function to download historical data and make predictions
def predict_prices(symbol):
today = datetime.date.today()
data = yf.download(symbol, start='2010-07-17', end=today)
predictions = {}

for price_type in ['High', 'Low', 'Close']:
temp_data = data.copy()
temp_data['Prediction'] = temp_data[price_type].shift(-1)
temp_data.dropna(inplace=True)
X = np.array(temp_data.drop(['Prediction'], axis=1))
Y = np.array(temp_data['Prediction'])

x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.2)
model = LinearRegression()
model.fit(x_train, y_train)
temp_data['Prediction'] = model.predict(np.array(temp_data.drop(['Prediction'], axis=1)))
predictions[price_type] = temp_data['Prediction']

return predictions, data

# Streamlit app
def main():
st.set_page_config(
page_title="Stock Market Prediction",
page_icon=":chart_with_upwards_trend:",
layout="centered",
initial_sidebar_state="expanded",
)

st.title(":chart_with_upwards_trend: Stock Market Prediction")
st.image("stock.jpg")

st.sidebar.title("User Input")
symbol = st.sidebar.text_input("Enter the symbol of the stock (e.g., AAPL, META, etc)")

if st.sidebar.button("Predict", key="predict_button"):
if not symbol:
st.warning("Please enter a symbol.")
else:
try:
predictions, data = predict_prices(symbol.upper())

st.subheader("Predicted Prices")
for i in [1, 7, 30, 365, 3650]:
if len(data) > i:
with st.expander(f"{i} day(s) from now"):
st.write(f"- High: {predictions['High'].iloc[-i]:.2f}")
st.write(f"- Low: {predictions['Low'].iloc[-i]:.2f}")
st.write(f"- Close: {predictions['Close'].iloc[-i]:.2f}")
except Exception as e:
st.error(f"An error occurred: {e}")

if __name__ == "__main__":
main()