Skip to content

Commit e5a3592

Browse files
authored
V0.0.17.0 ipo calendar (#25)
* update version * added ipo calendar and tests * update versions
1 parent 590b1ef commit e5a3592

File tree

4 files changed

+364
-26
lines changed

4 files changed

+364
-26
lines changed

poetry.lock

Lines changed: 25 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "fmp-py"
3-
version = "0.0.16.0"
3+
version = "0.0.17.0"
44
description = "Python package for Financial Modeling Prep API"
55
authors = ["TexasCoding <[email protected]>"]
66
readme = "README.md"

src/fmp_py/fmp_ipo_calendar.py

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
import pandas as pd
2+
from fmp_py.fmp_base import FmpBase
3+
import os
4+
import pendulum
5+
from dotenv import load_dotenv
6+
7+
load_dotenv()
8+
9+
10+
"""
11+
This class provides methods for retrieving IPO calendar data from the Financial Modeling Prep API.
12+
Ref: https://site.financialmodelingprep.com/developer/docs#ipo-calendar
13+
14+
def ipo_calendar_by_symbol(self, from_date: str, to_date: str) -> pd.DataFrame:
15+
Reference: https://site.financialmodelingprep.com/developer/docs#ipo-confirmed-ipo-calendar
16+
17+
def ipo_prospectus(self, from_date: str, to_date: str) -> pd.DataFrame:
18+
Reference: https://site.financialmodelingprep.com/developer/docs#ipo-prospectus-ipo-calendar
19+
20+
def ipo_confirmed(self, from_date: str, to_date: str) -> pd.DataFrame:
21+
Reference: https://site.financialmodelingprep.com/developer/docs#ipo-calender-by-ipo-calendar
22+
"""
23+
24+
25+
class FmpIpoCalendar(FmpBase):
26+
def __init__(self, api_key: str = os.getenv("FMP_API_KEY")):
27+
super().__init__(api_key)
28+
29+
#############################
30+
# IPO Calendar by Symbol
31+
#############################
32+
def ipo_calendar_by_symbol(self, from_date: str, to_date: str) -> pd.DataFrame:
33+
"""
34+
Retrieves IPO calendar data for a specific symbol within a given date range.
35+
Args:
36+
from_date (str): The starting date of the date range in "YYYY-MM-DD" format.
37+
to_date (str): The ending date of the date range in "YYYY-MM-DD" format.
38+
Returns:
39+
pd.DataFrame: A DataFrame containing IPO calendar data for the specified symbol within the given date range.
40+
"""
41+
42+
from_date = pendulum.parse(from_date).format("YYYY-MM-DD")
43+
to_date = pendulum.parse(to_date).format("YYYY-MM-DD")
44+
if from_date > to_date:
45+
raise ValueError("from_date must be less than or equal to to_date")
46+
47+
url = "v3/ipo_calendar"
48+
params = {"from": from_date, "to": to_date}
49+
50+
response = self.get_request(url, params)
51+
52+
if not response:
53+
raise ValueError("Error fetching IPO calendar data")
54+
55+
data_df = (
56+
pd.DataFrame(response)
57+
.fillna(0)
58+
.rename(
59+
columns={
60+
"date": "date",
61+
"company": "company",
62+
"symbol": "symbol",
63+
"exchange": "exchange",
64+
"actions": "actions",
65+
"shares": "shares",
66+
"priceRange": "price_range",
67+
"marketCap": "market_cap",
68+
}
69+
)
70+
.astype(
71+
{
72+
"date": "datetime64[ns]",
73+
"company": "str",
74+
"symbol": "str",
75+
"exchange": "str",
76+
"actions": "str",
77+
"shares": "int",
78+
"price_range": "string",
79+
"market_cap": "int",
80+
}
81+
)
82+
.sort_values(by="date", ascending=True)
83+
.reset_index(drop=True)
84+
)
85+
86+
return data_df
87+
88+
#############################
89+
# IPO Prspectus
90+
#############################
91+
def ipo_prospectus(self, from_date: str, to_date: str) -> pd.DataFrame:
92+
"""
93+
Retrieves IPO prospectus data from the specified date range.
94+
Args:
95+
from_date (str): The starting date of the date range in "YYYY-MM-DD" format.
96+
to_date (str): The ending date of the date range in "YYYY-MM-DD" format.
97+
Returns:
98+
pd.DataFrame: A DataFrame containing IPO prospectus data with the following columns:
99+
- symbol (str): The symbol of the IPO.
100+
- cik (str): The CIK (Central Index Key) of the IPO.
101+
- form (str): The form type of the IPO.
102+
- filing_date (datetime64[ns]): The filing date of the IPO.
103+
- accepted_date (datetime64[ns]): The accepted date of the IPO.
104+
- ipo_date (datetime64[ns]): The IPO date.
105+
- price_public_per_share (float): The price per share for the public offering.
106+
- price_public_total (float): The total price for the public offering.
107+
- discounts_and_commissions_per_share (float): The discounts and commissions per share.
108+
- discounts_and_commissions_total (float): The total discounts and commissions.
109+
- proceeds_before_expenses_per_share (float): The proceeds per share before expenses.
110+
- proceeds_before_expenses_total (float): The total proceeds before expenses.
111+
- url (str): The URL of the IPO prospectus.
112+
Raises:
113+
ValueError: If from_date is greater than to_date or if there is an error fetching the IPO calendar data.
114+
"""
115+
116+
from_date = pendulum.parse(from_date).format("YYYY-MM-DD")
117+
to_date = pendulum.parse(to_date).format("YYYY-MM-DD")
118+
if from_date > to_date:
119+
raise ValueError("from_date must be less than or equal to to_date")
120+
121+
url = "v4/ipo-calendar-prospectus"
122+
params = {"from": from_date, "to": to_date}
123+
124+
response = self.get_request(url, params)
125+
126+
if not response:
127+
raise ValueError("Error fetching IPO calendar data")
128+
129+
data_df = (
130+
pd.DataFrame(response)
131+
.fillna("")
132+
.rename(
133+
columns={
134+
"symbol": "symbol",
135+
"cik": "cik",
136+
"form": "form",
137+
"filingDate": "filing_date",
138+
"acceptedDate": "accepted_date",
139+
"ipoDate": "ipo_date",
140+
"pricePublicPerShare": "price_public_per_share",
141+
"pricePublicTotal": "price_public_total",
142+
"discountsAndCommissionsPerShare": "discounts_and_commissions_per_share",
143+
"discountsAndCommissionsTotal": "discounts_and_commissions_total",
144+
"proceedsBeforeExpensesPerShare": "proceeds_before_expenses_per_share",
145+
"proceedsBeforeExpensesTotal": "proceeds_before_expenses_total",
146+
"url": "url",
147+
}
148+
)
149+
.astype(
150+
{
151+
"symbol": "str",
152+
"cik": "str",
153+
"form": "str",
154+
"filing_date": "datetime64[ns]",
155+
"accepted_date": "datetime64[ns]",
156+
"ipo_date": "datetime64[ns]",
157+
"price_public_per_share": "float",
158+
"price_public_total": "float",
159+
"discounts_and_commissions_per_share": "float",
160+
"discounts_and_commissions_total": "float",
161+
"proceeds_before_expenses_per_share": "float",
162+
"proceeds_before_expenses_total": "float",
163+
"url": "str",
164+
}
165+
)
166+
.sort_values(by="filing_date", ascending=True)
167+
.reset_index(drop=True)
168+
)
169+
170+
return data_df
171+
172+
#############################
173+
# IPO Confirmed
174+
#############################
175+
def ipo_confirmed(self, from_date: str, to_date: str) -> pd.DataFrame:
176+
"""
177+
Retrieves the IPO calendar data for confirmed IPOs within the specified date range.
178+
Args:
179+
from_date (str): The start date of the date range in the format "YYYY-MM-DD".
180+
to_date (str): The end date of the date range in the format "YYYY-MM-DD".
181+
Returns:
182+
pd.DataFrame: A DataFrame containing the IPO calendar data for confirmed IPOs, sorted by filing date.
183+
Raises:
184+
ValueError: If from_date is greater than to_date or if there is an error fetching the IPO calendar data.
185+
"""
186+
187+
from_date = pendulum.parse(from_date).format("YYYY-MM-DD")
188+
to_date = pendulum.parse(to_date).format("YYYY-MM-DD")
189+
if from_date > to_date:
190+
raise ValueError("from_date must be less than or equal to to_date")
191+
192+
url = "v4/ipo-calendar-confirmed"
193+
params = {"from": from_date, "to": to_date}
194+
195+
response = self.get_request(url, params)
196+
197+
if not response:
198+
raise ValueError("Error fetching IPO calendar data")
199+
200+
data_df = (
201+
pd.DataFrame(response)
202+
.fillna("")
203+
.rename(
204+
columns={
205+
"symbol": "symbol",
206+
"cik": "cik",
207+
"form": "form",
208+
"filingDate": "filing_date",
209+
"acceptedDate": "accepted_date",
210+
"effectivenessDate": "effectiveness_date",
211+
"url": "url",
212+
}
213+
)
214+
.astype(
215+
{
216+
"symbol": "string",
217+
"cik": "string",
218+
"form": "string",
219+
"filing_date": "datetime64[ns]",
220+
"accepted_date": "datetime64[ns]",
221+
"effectiveness_date": "datetime64[ns]",
222+
"url": "string",
223+
}
224+
)
225+
.sort_values(by="filing_date", ascending=True)
226+
.reset_index(drop=True)
227+
)
228+
229+
return data_df

0 commit comments

Comments
 (0)