QuantumLearner commited on
Commit
bc13150
·
verified ·
1 Parent(s): dbcee09

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +178 -0
app.py ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import datetime
3
+ import requests
4
+ import pandas as pd
5
+ from streamlit_calendar import calendar
6
+
7
+ API_KEY = "b431ec171262073909ebf8c0c4afba71"
8
+
9
+ def fetch_ipo_confirmed(from_date, to_date):
10
+ url = (
11
+ f"https://financialmodelingprep.com/api/v4/ipo-calendar-confirmed"
12
+ f"?from={from_date}&to={to_date}&apikey={API_KEY}"
13
+ )
14
+ resp = requests.get(url)
15
+ if resp.status_code == 200:
16
+ return resp.json()
17
+ return []
18
+
19
+ def fetch_ipo_prospectus(from_date, to_date):
20
+ url = (
21
+ f"https://financialmodelingprep.com/api/v4/ipo-calendar-prospectus"
22
+ f"?from={from_date}&to={to_date}&apikey={API_KEY}"
23
+ )
24
+ resp = requests.get(url)
25
+ if resp.status_code == 200:
26
+ return resp.json()
27
+ return []
28
+
29
+ def fetch_ipo_calendar(from_date, to_date):
30
+ url = (
31
+ f"https://financialmodelingprep.com/api/v3/ipo_calendar"
32
+ f"?from={from_date}&to={to_date}&apikey={API_KEY}"
33
+ )
34
+ resp = requests.get(url)
35
+ if resp.status_code == 200:
36
+ return resp.json()
37
+ return []
38
+
39
+ def main():
40
+ st.set_page_config(page_title="IPO Calendar", layout="wide")
41
+
42
+ # Keep session data
43
+ if "general_data" not in st.session_state:
44
+ st.session_state["general_data"] = []
45
+
46
+ st.title("IPO Calendar")
47
+ st.write("This displays three types of IPO events: Confirmed, Prospectus, and Calendar.")
48
+
49
+ st.sidebar.title("Input Parameters")
50
+
51
+ with st.sidebar.expander("How to Use", expanded=False):
52
+ st.write(
53
+ """
54
+ 1. Check the event types you want to see.
55
+ 2. Select the date range.
56
+ 3. Click the button to retrieve the data.
57
+ 4. View the calendar and the table below.
58
+ """
59
+ )
60
+
61
+ with st.sidebar.expander("Event Type", expanded=True):
62
+ include_confirmed = st.checkbox("Include IPO Confirmed", value=True, help="Include IPOs that are confirmed and have a scheduled date for going public.")
63
+ include_prospectus = st.checkbox("Include IPO Prospectus", value=True, help="Include IPO prospectuses with detailed company and securities information.")
64
+ include_calendar = st.checkbox("Include IPO Calendar", value=True, help="Include a list of upcoming IPOs with expected dates and price ranges.")
65
+
66
+
67
+ with st.sidebar.expander("Parameters", expanded=True):
68
+ today = datetime.date.today()
69
+ one_month_later = today + datetime.timedelta(days=30)
70
+ from_date = st.date_input("From Date", value=today, help="Select the start date for the IPO data.")
71
+ to_date = st.date_input("To Date", value=one_month_later, help="Select the end date for the IPO data.")
72
+
73
+
74
+ if st.sidebar.button("Retrieve Calendar"):
75
+ all_events = []
76
+
77
+ if include_confirmed:
78
+ confirmed_data = fetch_ipo_confirmed(from_date, to_date)
79
+ for item in confirmed_data:
80
+ # Choose effectivenessDate if present, else use filingDate
81
+ date_str = item.get("effectivenessDate") or item.get("filingDate") or ""
82
+ if date_str:
83
+ start_dt = f"{date_str}T00:00:00"
84
+ end_dt = f"{date_str}T23:59:59"
85
+ sym = item.get("symbol", "")
86
+ event_title = f"[IPO Confirmed] {sym}"
87
+ event_entry = {
88
+ "start": start_dt,
89
+ "end": end_dt,
90
+ "title": event_title,
91
+ "color": "#3D9DF3",
92
+ "eventType": "IPO Confirmed"
93
+ }
94
+ event_entry.update(item)
95
+ all_events.append(event_entry)
96
+
97
+ if include_prospectus:
98
+ prospectus_data = fetch_ipo_prospectus(from_date, to_date)
99
+ for item in prospectus_data:
100
+ # Use filingDate because ipoDate might not always be a standard format
101
+ date_str = item.get("filingDate", "")
102
+ if date_str:
103
+ start_dt = f"{date_str}T00:00:00"
104
+ end_dt = f"{date_str}T23:59:59"
105
+ sym = item.get("symbol", "")
106
+ event_title = f"[IPO Prospectus] {sym}"
107
+ event_entry = {
108
+ "start": start_dt,
109
+ "end": end_dt,
110
+ "title": event_title,
111
+ "color": "#80C080",
112
+ "eventType": "IPO Prospectus"
113
+ }
114
+ event_entry.update(item)
115
+ all_events.append(event_entry)
116
+
117
+ if include_calendar:
118
+ calendar_data = fetch_ipo_calendar(from_date, to_date)
119
+ for item in calendar_data:
120
+ date_str = item.get("date", "")
121
+ if date_str:
122
+ start_dt = f"{date_str}T00:00:00"
123
+ end_dt = f"{date_str}T23:59:59"
124
+ sym = item.get("symbol", "")
125
+ event_title = f"[IPO Calendar] {sym}"
126
+ event_entry = {
127
+ "start": start_dt,
128
+ "end": end_dt,
129
+ "title": event_title,
130
+ "color": "#FFC870",
131
+ "eventType": "IPO Calendar"
132
+ }
133
+ event_entry.update(item)
134
+ all_events.append(event_entry)
135
+
136
+ st.session_state["general_data"] = all_events
137
+
138
+ st.subheader("Calendar Results")
139
+ data_general = st.session_state["general_data"]
140
+ if data_general:
141
+ # Prepare data for display
142
+ calendar_events = []
143
+ for ev in data_general:
144
+ calendar_events.append({
145
+ "title": ev["title"],
146
+ "start": ev["start"],
147
+ "end": ev["end"],
148
+ "color": ev["color"],
149
+ })
150
+
151
+ cal_options = {
152
+ "initialView": "dayGridMonth",
153
+ "headerToolbar": {
154
+ "left": "today prev,next",
155
+ "center": "title",
156
+ "right": "dayGridDay,dayGridWeek,dayGridMonth",
157
+ },
158
+ "navLinks": True,
159
+ }
160
+
161
+ calendar(events=calendar_events, options=cal_options, key="ipo_cal")
162
+
163
+ st.write("Data Table")
164
+ df_g = pd.DataFrame(data_general)
165
+ st.dataframe(df_g, use_container_width=True)
166
+ else:
167
+ st.write("No data retrieved. Check your selections and press the button.")
168
+
169
+ if __name__ == "__main__":
170
+ main()
171
+
172
+ hide_streamlit_style = """
173
+ <style>
174
+ #MainMenu {visibility: hidden;}
175
+ footer {visibility: hidden;}
176
+ </style>
177
+ """
178
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)