-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 714b60f
Showing
8 changed files
with
394 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
run = ["bash", "main.sh"] | ||
|
||
entrypoint = "main.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: streamlit run main.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
altair==4.2.0 | ||
argon2-cffi==21.3.0 | ||
argon2-cffi-bindings==21.2.0 | ||
astor==0.8.1 | ||
asttokens==2.0.5 | ||
attrs==21.4.0 | ||
backcall==0.2.0 | ||
base58==2.1.1 | ||
beautifulsoup4==4.10.0 | ||
bleach==4.1.0 | ||
blinker==1.4 | ||
cachetools==5.0.0 | ||
certifi==2021.10.8 | ||
cffi==1.15.0 | ||
charset-normalizer==2.0.12 | ||
click==8.0.4 | ||
debugpy==1.5.1 | ||
decorator==5.1.1 | ||
defusedxml==0.7.1 | ||
entrypoints==0.4 | ||
executing==0.8.3 | ||
gitdb==4.0.9 | ||
GitPython==3.1.27 | ||
idna==3.3 | ||
importlib-metadata==4.11.3 | ||
ipykernel==6.9.2 | ||
ipython==8.1.1 | ||
ipython-genutils==0.2.0 | ||
ipywidgets==7.7.0 | ||
jedi==0.18.1 | ||
Jinja2==3.0.3 | ||
jsonschema==4.4.0 | ||
jupyter-client==7.1.2 | ||
jupyter-core==4.9.2 | ||
jupyterlab-pygments==0.1.2 | ||
jupyterlab-widgets==1.1.0 | ||
lxml==4.8.0 | ||
MarkupSafe==2.1.1 | ||
matplotlib-inline==0.1.3 | ||
mistune==0.8.4 | ||
multitasking==0.0.10 | ||
nbclient==0.5.13 | ||
nbconvert==6.4.4 | ||
nbformat==5.2.0 | ||
nest-asyncio==1.5.4 | ||
notebook==6.4.10 | ||
numpy==1.22.3 | ||
packaging==21.3 | ||
pandas==1.4.1 | ||
pandocfilters==1.5.0 | ||
parso==0.8.3 | ||
pexpect==4.8.0 | ||
pickleshare==0.7.5 | ||
Pillow==9.0.1 | ||
prometheus-client==0.13.1 | ||
prompt-toolkit==3.0.28 | ||
protobuf==3.19.4 | ||
psutil==5.9.0 | ||
ptyprocess==0.7.0 | ||
pure-eval==0.2.2 | ||
pyarrow==7.0.0 | ||
pycparser==2.21 | ||
pydeck==0.7.1 | ||
Pygments==2.11.2 | ||
Pympler==1.0.1 | ||
pyparsing==3.0.7 | ||
pyrsistent==0.18.1 | ||
python-dateutil==2.8.2 | ||
pytz==2022.1 | ||
pytz-deprecation-shim==0.1.0.post0 | ||
pyzmq==22.3.0 | ||
requests==2.27.1 | ||
semver==2.13.0 | ||
Send2Trash==1.8.0 | ||
six==1.16.0 | ||
smmap==5.0.0 | ||
soupsieve==2.3.1 | ||
stack-data==0.2.0 | ||
streamlit==1.8.1 | ||
tenacity==8.0.1 | ||
terminado==0.13.3 | ||
testpath==0.6.0 | ||
toml==0.10.2 | ||
toolz==0.11.2 | ||
tornado==6.1 | ||
traitlets==5.1.1 | ||
tzdata==2022.1 | ||
tzlocal==4.1 | ||
urllib3==1.26.9 | ||
validators==0.18.2 | ||
watchdog==2.1.6 | ||
wcwidth==0.2.5 | ||
webencodings==0.5.1 | ||
widgetsnbextension==3.6.0 | ||
yfinance==0.1.70 | ||
zipp==3.7.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import streamlit as st | ||
import pandas as pd | ||
import yfinance as yf | ||
import datetime | ||
import calendar | ||
from PIL import Image | ||
|
||
|
||
|
||
def calculate_next_month_date(start_date : datetime) -> datetime: | ||
year = start_date.year | ||
month = start_date.month | ||
if month == 12: | ||
month = 1 | ||
year = year + 1 | ||
else: | ||
month = month + 1 | ||
first_day, last_day = calendar.monthrange(year, month) | ||
return datetime.date(year, month, 1), datetime.date(year, month, last_day) | ||
|
||
def calculate_back_month_date(start_date : datetime) -> datetime: | ||
year = start_date.year | ||
month = start_date.month | ||
if month == 1: | ||
month = 12 | ||
year = year - 1 | ||
else: | ||
month = month - 1 | ||
first_day, last_day = calendar.monthrange(year, month) | ||
return datetime.date(year, month, 1), datetime.date(year, month, last_day) | ||
|
||
def calculate_end_date(): | ||
year = st.session_state["start_date"].year | ||
month = st.session_state["start_date"].month | ||
first_day, last_day = calendar.monthrange(year, month) | ||
st.session_state["end_date"] = datetime.date(year, month, last_day) | ||
|
||
|
||
def get_next_dates(): | ||
new_start_date, new_end_date = calculate_next_month_date(st.session_state["start_date"]) | ||
st.session_state["start_date"] = new_start_date | ||
st.session_state["end_date"] = new_end_date | ||
|
||
def get_back_dates(): | ||
new_start_date, new_end_date = calculate_back_month_date(st.session_state["start_date"]) | ||
st.session_state["start_date"] = new_start_date | ||
st.session_state["end_date"] = new_end_date | ||
|
||
def df_to_csv(data): | ||
return data.to_csv().encode('utf-8') | ||
|
||
|
||
def final_calculation(symbol, org): | ||
if ("start_date" not in st.session_state) and ("end_date" not in st.session_state): | ||
today = datetime.date.today() | ||
previous_start_day, previous_end_day = calculate_back_month_date(today) | ||
st.session_state["start_date"] = previous_start_day | ||
st.session_state["end_date"] = previous_end_day | ||
|
||
|
||
|
||
st.title(f'{org}({symbol})') | ||
start_date_col, end_date_col = st.columns(2) | ||
start_date = start_date_col.date_input("Start Date", st.session_state["start_date"], key="start_date", on_change=calculate_end_date) | ||
end_date = end_date_col.date_input("End Date", st.session_state["end_date"], key="end_date") | ||
data = yf.download(symbol, start=start_date, end=end_date) | ||
data = data.reset_index() | ||
st.markdown("") | ||
df_expander = st.expander(label='DataFrame') | ||
with df_expander: | ||
st.dataframe(data) | ||
csv = df_to_csv(data) | ||
st.download_button( | ||
label="Download CSV", | ||
data=csv, | ||
file_name='large_df.csv', | ||
mime='text/csv', | ||
) | ||
st.markdown("") | ||
# st.session_state | ||
next_button_col, back_button_col = st.columns(2) | ||
current_date = datetime.date.today() | ||
|
||
if start_date.year == current_date.year and start_date.month == current_date.month: | ||
next_button_col.button("Next", on_click=get_next_dates, disabled=True) | ||
else: | ||
next_button_col.button("Next", on_click=get_next_dates) | ||
back_button_col.button("Back", on_click=get_back_dates) | ||
|
||
data.set_index("Date", inplace=True) | ||
|
||
st.line_chart(data=data[["Open","High", "Low", "Close"]]) | ||
st.bar_chart(data=data["Volume"]) | ||
|
||
|
||
|
||
|
||
|
||
def main(): | ||
with open("style.css") as f: | ||
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True) | ||
|
||
st.markdown('''<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet">''', unsafe_allow_html=True) | ||
|
||
tickers = pd.read_csv("tickers.csv", encoding="ISO-8859-1") | ||
tickers.sort_values(by=['Name'], inplace=True) | ||
image = Image.open('logo.png') | ||
st.sidebar.image(image) | ||
|
||
st.sidebar.title("YFinance!") | ||
org = st.sidebar.selectbox("Choose Listing:", tickers["Name"]) | ||
symbol = tickers[tickers["Name"] == org]["Symbol"].values[0] | ||
final_calculation(symbol, org) | ||
|
||
|
||
if __name__ == "__main__": | ||
st.set_page_config( | ||
page_title="Share Market App", | ||
page_icon="logo.png", | ||
layout="wide", | ||
initial_sidebar_state="expanded", | ||
) | ||
|
||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ pkgs }: { | ||
deps = [ | ||
pkgs.bashInteractive | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
*{ | ||
|
||
font-family: 'Roboto', sans-serif; | ||
|
||
} | ||
|
||
/* #MainMenu{ | ||
visibility: hidden; | ||
} */ | ||
|
||
|
||
#microsoft{ | ||
color: rgb(78, 83, 85); | ||
font-size: 35px; | ||
text-decoration: underline; | ||
|
||
} | ||
|
||
.main{ | ||
background-color: #F5F5F5; | ||
} | ||
|
||
div.stDateInput > label{ | ||
|
||
font-weight: bold; | ||
|
||
} | ||
|
||
input[placeholder="YYYY/MM/DD"]{ | ||
|
||
border: 1px pink solid; | ||
} | ||
|
||
div.stDataFrame{ | ||
|
||
border: 2px pink solid; | ||
|
||
} | ||
|
||
div.stDataFrame > div:first-of-type > div:first-of-type{ | ||
font-weight: bold; | ||
} | ||
|
||
img{ | ||
|
||
width: 50%; | ||
|
||
} | ||
|
||
footer{ | ||
|
||
visibility: visible; | ||
|
||
} | ||
|
||
footer::after{ | ||
content: 'Developed by Vivek Khandelwal'; | ||
display: block; | ||
position: relative; | ||
color: rgb(189, 184, 184); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.