Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import yfinance as yf
|
3 |
+
import pandas as pd
|
4 |
+
from datetime import date
|
5 |
+
from io import BytesIO
|
6 |
+
|
7 |
+
st.set_page_config(page_title='Hisse Senedi Grafiği')
|
8 |
+
|
9 |
+
# Hisse senetleri listesi
|
10 |
+
stocks = {
|
11 |
+
'Tesla': 'TSLA',
|
12 |
+
'Apple': 'AAPL',
|
13 |
+
'Nvidia': 'NVDA',
|
14 |
+
'Microsoft': 'MSFT'
|
15 |
+
}
|
16 |
+
|
17 |
+
# Kullanıcının hisse senedi seçmesi için selectbox
|
18 |
+
sembol = st.sidebar.selectbox("Hisse Senedi Seçiniz", options=list(stocks.keys()))
|
19 |
+
sembol_kodu = stocks[sembol]
|
20 |
+
st.title(f"{sembol} ({sembol_kodu}) Hisse Senedi Grafiği")
|
21 |
+
|
22 |
+
start_date = st.sidebar.date_input('Başlangıç Tarihi', value=date(2023, 1, 1))
|
23 |
+
end_date = st.sidebar.date_input('Bitiş Tarihi', value=date.today())
|
24 |
+
|
25 |
+
# Tarih kontrolü
|
26 |
+
if start_date > end_date:
|
27 |
+
st.error('Başlangıç tarihi bitiş tarihinden sonra olamaz.')
|
28 |
+
else:
|
29 |
+
# Veri çekme işlemi
|
30 |
+
df = yf.download(sembol_kodu, start=start_date, end=end_date)
|
31 |
+
|
32 |
+
if df.empty:
|
33 |
+
st.warning('Seçilen sembol ve tarih aralığı için veri bulunamadı.')
|
34 |
+
else:
|
35 |
+
# Zaman dilimi bilgisini kaldırma
|
36 |
+
df.index = df.index.tz_localize(None)
|
37 |
+
|
38 |
+
# Veri çerçevesini gösterme
|
39 |
+
st.subheader('Hisse Senedi Verileri')
|
40 |
+
st.write(df)
|
41 |
+
|
42 |
+
# Grafik çizme
|
43 |
+
st.subheader('Kapanış Fiyatı Grafiği')
|
44 |
+
st.line_chart(df['Close'])
|
45 |
+
|
46 |
+
# Excel dosyasını indirme
|
47 |
+
st.subheader('Hisse Senedi Verileri Excel Dosyası')
|
48 |
+
|
49 |
+
def to_excel(df):
|
50 |
+
output = BytesIO()
|
51 |
+
writer = pd.ExcelWriter(output, engine='xlsxwriter')
|
52 |
+
df.to_excel(writer, index=True, sheet_name='Sheet1')
|
53 |
+
writer.close()
|
54 |
+
processed_data = output.getvalue()
|
55 |
+
return processed_data
|
56 |
+
|
57 |
+
excel_data = to_excel(df)
|
58 |
+
st.download_button(
|
59 |
+
label='Excel olarak indir',
|
60 |
+
data=excel_data,
|
61 |
+
file_name=f'{sembol_kodu}_data.xlsx',
|
62 |
+
mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
63 |
+
)
|