File size: 6,685 Bytes
bc13150
 
 
 
 
1f158b9
bc13150
22c8767
bc13150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ef5352
bc13150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d4686ba
bc13150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d4686ba
 
bc13150
 
 
 
 
 
 
 
 
 
 
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import streamlit as st
import datetime
import requests
import pandas as pd
from streamlit_calendar import calendar
import os

API_KEY = os.getenv("FMP_API_KEY")

def fetch_ipo_confirmed(from_date, to_date):
    url = (
        f"https://financialmodelingprep.com/api/v4/ipo-calendar-confirmed"
        f"?from={from_date}&to={to_date}&apikey={API_KEY}"
    )
    resp = requests.get(url)
    if resp.status_code == 200:
        return resp.json()
    return []

def fetch_ipo_prospectus(from_date, to_date):
    url = (
        f"https://financialmodelingprep.com/api/v4/ipo-calendar-prospectus"
        f"?from={from_date}&to={to_date}&apikey={API_KEY}"
    )
    resp = requests.get(url)
    if resp.status_code == 200:
        return resp.json()
    return []

def fetch_ipo_calendar(from_date, to_date):
    url = (
        f"https://financialmodelingprep.com/api/v3/ipo_calendar"
        f"?from={from_date}&to={to_date}&apikey={API_KEY}"
    )
    resp = requests.get(url)
    if resp.status_code == 200:
        return resp.json()
    return []

def main():
    st.set_page_config(page_title="IPO Calendar", layout="wide")

    # Keep session data
    if "general_data" not in st.session_state:
        st.session_state["general_data"] = []

    st.title("IPO Calendar")
    st.write("This displays three types of IPO events: Confirmed, Prospectus, and Calendar. Set parameters and click run.")

    st.sidebar.title("Input Parameters")

    with st.sidebar.expander("How to Use", expanded=False):
        st.write(
            """
            1. Check the event types you want to see.
            2. Select the date range.
            3. Click the button to retrieve the data.
            4. View the calendar and the table below.
            """
        )

    with st.sidebar.expander("Event Type", expanded=True):
        include_confirmed = st.checkbox("Include IPO Confirmed", value=True, help="Include IPOs that are confirmed and have a scheduled date for going public.")
        include_prospectus = st.checkbox("Include IPO Prospectus", value=True, help="Include IPO prospectuses with detailed company and securities information.")
        include_calendar = st.checkbox("Include IPO Calendar", value=True, help="Include a list of upcoming IPOs with expected dates and price ranges.")


    with st.sidebar.expander("Parameters", expanded=True):
        today = datetime.date.today()
        one_month_later = today + datetime.timedelta(days=30)
        from_date = st.date_input("From Date", value=today, help="Select the start date for the IPO data.")
        to_date = st.date_input("To Date", value=one_month_later, help="Select the end date for the IPO data.")


    if st.sidebar.button("Retrieve Calendar"):
        all_events = []

        if include_confirmed:
            confirmed_data = fetch_ipo_confirmed(from_date, to_date)
            for item in confirmed_data:
                # Choose effectivenessDate if present, else use filingDate
                date_str = item.get("effectivenessDate") or item.get("filingDate") or ""
                if date_str:
                    start_dt = f"{date_str}T00:00:00"
                    end_dt = f"{date_str}T23:59:59"
                    sym = item.get("symbol", "")
                    event_title = f"[IPO Confirmed] {sym}"
                    event_entry = {
                        "start": start_dt,
                        "end": end_dt,
                        "title": event_title,
                        "color": "#3D9DF3",
                        "eventType": "IPO Confirmed"
                    }
                    event_entry.update(item)
                    all_events.append(event_entry)

        if include_prospectus:
            prospectus_data = fetch_ipo_prospectus(from_date, to_date)
            for item in prospectus_data:
                # Use filingDate because ipoDate might not always be a standard format
                date_str = item.get("filingDate", "")
                if date_str:
                    start_dt = f"{date_str}T00:00:00"
                    end_dt = f"{date_str}T23:59:59"
                    sym = item.get("symbol", "")
                    event_title = f"[IPO Prospectus] {sym}"
                    event_entry = {
                        "start": start_dt,
                        "end": end_dt,
                        "title": event_title,
                        "color": "#80C080",
                        "eventType": "IPO Prospectus"
                    }
                    event_entry.update(item)
                    all_events.append(event_entry)

        if include_calendar:
            calendar_data = fetch_ipo_calendar(from_date, to_date)
            for item in calendar_data:
                date_str = item.get("date", "")
                if date_str:
                    start_dt = f"{date_str}T00:00:00"
                    end_dt = f"{date_str}T23:59:59"
                    sym = item.get("symbol", "")
                    event_title = f"[IPO Calendar] {sym}"
                    event_entry = {
                        "start": start_dt,
                        "end": end_dt,
                        "title": event_title,
                        "color": "#FFC870",
                        "eventType": "IPO Calendar"
                    }
                    event_entry.update(item)
                    all_events.append(event_entry)

        st.session_state["general_data"] = all_events

    #st.subheader("Calendar Results")
    data_general = st.session_state["general_data"]
    if data_general:
        # Prepare data for display
        calendar_events = []
        for ev in data_general:
            calendar_events.append({
                "title": ev["title"],
                "start": ev["start"],
                "end": ev["end"],
                "color": ev["color"],
            })

        cal_options = {
            "initialView": "dayGridMonth",
            "headerToolbar": {
                "left": "today prev,next",
                "center": "title",
                "right": "dayGridDay,dayGridWeek,dayGridMonth",
            },
            "navLinks": True,
        }

        calendar(events=calendar_events, options=cal_options, key="ipo_cal")

        st.write("Data Table")
        df_g = pd.DataFrame(data_general)
        st.dataframe(df_g, use_container_width=True)
    else:
        st.write(" ")
        #st.write("No data retrieved. Check your selections and press the button.")

if __name__ == "__main__":
    main()
    
hide_streamlit_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)