File size: 2,941 Bytes
d8c1d78
f558d11
b4b6e66
d8c1d78
b4b6e66
f558d11
9a408e2
 
71af6f7
ad28108
 
 
 
 
d3529cc
ad28108
 
a3139c0
ad28108
 
 
f558d11
b4b6e66
ad28108
 
f558d11
b4b6e66
d8c1d78
 
5b1bbef
d3529cc
a57a319
5b1bbef
a57a319
238ed09
a57a319
238ed09
9a408e2
 
 
 
 
3109327
9a408e2
 
 
 
 
 
 
d3529cc
a57a319
a3f6dd5
 
238ed09
a57a319
238ed09
a57a319
238ed09
 
 
 
a57a319
238ed09
 
 
 
a57a319
238ed09
 
 
 
 
 
9a408e2
 
 
 
 
 
 
 
 
 
 
 
a57a319
 
d3529cc
 
 
 
 
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
import streamlit as st
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt

# Set a title for the app
st.title("Stock Price Prediction")

# Load the stock data from the CSV files
data1 = pd.read_csv('Google_test_data.csv')
data2 = pd.read_csv('tesla.csv')

# Combine the datasets into a dictionary
datasets = {'Google': data1, 'Tesla': data2}

# Get the user's dataset selection
selected_dataset = st.selectbox('Select Stock', list(datasets.keys()))

# Retrieve the selected dataset
selected_data = datasets[selected_dataset]

# Prepare the data for prediction
X = np.arange(len(selected_data)).reshape(-1, 1)
y = selected_data['Close']

# Train the linear regression model
model = LinearRegression()
model.fit(X, y)

# Define a flag for displaying the graphs and table
display_graphs = False

# Create a submit button
if st.button('Submit'):
    display_graphs = True

# Display the image as the background
st.markdown(
    """
    <style>
    .stApp {
        background-image: url('https://img.etimg.com/thumb/msid-96018223,width-1200,height-900,imgsize-117108,resizemode-8,quality-100/markets/stocks/news/traders-guide-these-2-stocks-have-up-to-6-upside-scope.jpg');
        background-size: cover;
    }
    </style>
    """,
    unsafe_allow_html=True
)

# Display the graphs and table if the submit button is clicked
if display_graphs:
    # Create subplots with increased spacing between subplots
    fig, axes = plt.subplots(3, 1, figsize=(10, 20), sharex=True, gridspec_kw={'hspace': 0.5})

    # Plot 1: Actual and Predicted Stock Prices
    axes[0].plot(selected_data['Date'], y, label='Actual')
    axes[0].plot(selected_data['Date'], model.predict(X), label='Predicted')
    axes[0].set_ylabel('Stock Price')
    axes[0].set_title(f'{selected_dataset} Stock Price Prediction')
    axes[0].legend()

    # Plot 2: Volume of Trades
    axes[1].plot(selected_data['Date'], selected_data['Volume'])
    axes[1].set_ylabel('Volume')
    axes[1].set_title(f'{selected_dataset} Volume of Trades')

    # Plot 3: Daily Percentage Change in Stock Prices
    daily_returns = selected_data['Close'].pct_change() * 100
    axes[2].plot(selected_data['Date'], daily_returns)
    axes[2].set_xlabel('Date')
    axes[2].set_ylabel('Percentage Change')
    axes[2].set_title(f'{selected_dataset} Daily Percentage Change in Stock Prices')

    # Remove the background image
    st.markdown(
        """
        <style>
        .stApp {
            background-image: none;
        }
        </style>
        """,
        unsafe_allow_html=True
    )

    # Display the graphs in Streamlit
    st.pyplot(fig)

    # Display the table of price details and predicted prices
    st.subheader("Price Details and Predicted Prices")
    price_table = pd.DataFrame({'Date': selected_data['Date'], 'Actual Price': y, 'Predicted Price': model.predict(X)})
    st.dataframe(price_table)