Spaces:
Sleeping
Sleeping
import streamlit as st | |
import yfinance as yf | |
import pandas as pd | |
from datetime import date | |
from io import BytesIO | |
import plotly.graph_objects as go | |
st.set_page_config(page_title='Stock Chart') | |
# Hisse senetleri listesi | |
stocks = { | |
'Tesla': 'TSLA', | |
'Apple': 'AAPL', | |
'Nvidia': 'NVDA', | |
'Microsoft': 'MSFT' | |
} | |
# Kullanıcının hisse senedi seçmesi için selectbox | |
sembol = st.sidebar.selectbox("Select a Stock", options=list(stocks.keys())) | |
sembol_kodu = stocks[sembol] | |
st.title(f"{sembol} ({sembol_kodu}) Stock Chart") | |
start_date = st.sidebar.date_input('Start Date', value=date(2023, 1, 1)) | |
end_date = st.sidebar.date_input('End Date', value=date.today()) | |
# Tarih kontrolü | |
if start_date > end_date: | |
st.error('Start date cannot be later than end date.') | |
else: | |
# Veri çekme işlemi | |
df = yf.download(sembol_kodu, start=start_date, end=end_date) | |
if df.empty: | |
st.warning('No data found for selected symbol and date range.') | |
else: | |
# Zaman dilimi bilgisini kaldırma | |
df.index = df.index.tz_localize(None) | |
# Veri çerçevesini gösterme | |
st.subheader('Stock Data') | |
st.write(df) | |
# Grafikler | |
st.subheader("Closing Price Chart") | |
st.line_chart(df['Close']) | |
st.subheader("Volume Price Chart") | |
st.bar_chart(df['Volume']) | |
# Excel dosyasını indirme | |
st.subheader('Stock Data Excel File') | |
def to_excel(df): | |
output = BytesIO() | |
writer = pd.ExcelWriter(output, engine='xlsxwriter') | |
df.to_excel(writer, index=True, sheet_name='Sheet1') | |
writer.close() | |
processed_data = output.getvalue() | |
return processed_data | |
excel_data = to_excel(df) | |
st.download_button( | |
label='Download as Excel', | |
data=excel_data, | |
file_name=f'{sembol_kodu}_data.xlsx', | |
mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' | |
) |