-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
111 lines (79 loc) · 3.78 KB
/
app.py
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import streamlit as st
import yfinance as yf
import pandas as pd
from vega_datasets import data
import plotly.graph_objects as go
from streamlit_extras.colored_header import colored_header
from streamlit_extras.mention import mention
from datetime import date
# Set page title
# تحديد الكلمات المفتاحية المستهدفة لموقعك
keywords = ["Rasheed Al-qadhi", "Rasheed al qadhi", "project to obtain the stock market data"]
# إنشاء عنوان صفحة موقعك مع تضمين الكلمات المفتاحية
st.title("Hello, I'm RASHEED AL-QADHI. This is a project to obtain the stock market data .")
# إنشاء محتوى الصفحة مع تضمين الكلمات المفتاحية
st.write("Streamlit is an open-source app framework for Machine Learning and Data Science teams. Create beautiful web apps in minutes. The software libraries used in the project are streamlit , yfinance, pandas, vega_datasets, plotly, streamlit_extras")
# colored_header(
# label="Hi , i'm RASHEED AL-QADHI ",
# description="",
# color_name="orange-70",
# )
# Set up social media icons
with st.container():
col1, col2, col3 = st.columns(3)
col1.markdown("[](https://twitter.com/shadowYEM)")
col2.markdown("[](https://github.com/shadowYEM)")
col3.markdown("[](https://t.me/ShadowYE)")
# col4.markdown("[](https://kaggle.com/shadowYE)")
colored_header(
label="A project containing 20 stock exchange shares",
description="",
color_name="orange-70",
)
st.sidebar.title('Stock Data :part_alternation_mark:')
# Set page title
# Define the user inputs
tickers = st.sidebar.selectbox('Select Tickers', ['AAPL','MSFT', 'AMZN', 'GOOGL', 'META', 'TSLA', 'BRK.A', 'BRK.B',
'NVDA', 'JPM', 'JNJ', 'V', 'PG', 'DIS','INTC', 'PFE', 'KO', 'XOM', 'MCD', 'IBM' ], index=0, format_func=lambda x: x.upper())
today = date.today()
start_date = st.sidebar.date_input('Start date', value=pd.to_datetime('2022-03-22'))
end_date = st.sidebar.date_input('End date', value=today)
# Fetch stock data from Yahoo
data = yf.download(tickers, start=start_date, end=end_date)
# Display stock data
st.header(f'Stock data for :red[{tickers}]')
st.dataframe(data, width=1000)
st.title('Data visualization :zap:')
# Set up plotly figure
fig = go.Figure()
# Add candlestick trace for stock prices
fig.add_trace(go.Candlestick(x=data.index,
open=data['Open'],
high=data['High'],
low=data['Low'],
close=data['Close'],
name="Stock Prices"))
# Add moving average trace for 50-day period
fig.add_trace(go.Scatter(x=data.index,
y=data['Close'],
mode='lines',
name='Moving Average (50 days)'))
# Add plotly layout
fig.update_layout(title=f"{tickers} Stock Prices",
xaxis_title="Date",
yaxis_title="Price (USD)")
# Render plotly figure using streamlit
st.plotly_chart(fig)
# Add download button to download data
@st.cache_resource
def convert_df(df):
st.title(f'Data :red[{tickers}] Download ')
# IMPORTANT: Cache the conversion to prevent computation on every rerun
return df.to_csv().encode('utf-8')
csv = convert_df(data)
st.download_button(
label="Download data as CSV",
data=csv,
file_name=f'{tickers}.csv',
mime='text/csv',
)