PYield 0.2.11__tar.gz → 0.2.13__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PYield
3
- Version: 0.2.11
3
+ Version: 0.2.13
4
4
  Summary: A Python library for analysis of fixed income instruments in Brazil
5
5
  Keywords: fixed-income, brazil, finance, analysis, bonds
6
6
  Author-Email: Carlos Carvalho <cr.cj@outlook.com>
@@ -0,0 +1 @@
1
+ __version__ = "0.2.13"
@@ -188,7 +188,11 @@ def process_di(df: pd.DataFrame, reference_date: pd.Timestamp) -> pd.DataFrame:
188
188
  "ÚLT.OF. VENDA": "last_offer_rate",
189
189
  }
190
190
  )
191
- reference_date = pd.Timestamp(reference_date)
191
+
192
+ df.insert(0, "reference_date", reference_date)
193
+ # Convert to datetime64[ns] since it is pandas default type for timestamps
194
+ df["reference_date"] = df["reference_date"].astype("datetime64[ns]")
195
+
192
196
  # Contract code format was changed in 22/05/2006
193
197
  if reference_date < pd.Timestamp("2006-05-22"):
194
198
  df["expiration"] = df["contract_code"].apply(
@@ -232,6 +236,7 @@ def process_di(df: pd.DataFrame, reference_date: pd.Timestamp) -> pd.DataFrame:
232
236
  # Order columns
233
237
  df = df[
234
238
  [
239
+ "reference_date",
235
240
  "contract_code",
236
241
  "expiration",
237
242
  "bdays",
@@ -34,14 +34,19 @@ def extract_xml_file(zip_file: io.BytesIO) -> io.BytesIO:
34
34
 
35
35
  # Then, read the inner file
36
36
  with zipfile.ZipFile(outer_file, "r") as inner_zip:
37
- inner_file_name = inner_zip.namelist()[0]
38
- inner_file_content = inner_zip.read(inner_file_name)
37
+ filenames = inner_zip.namelist()
38
+ # Get first file that ends with ".xml"
39
+ xml_filename = [name for name in filenames if name.endswith(".xml")][0]
40
+ inner_file_content = inner_zip.read(xml_filename)
39
41
 
40
42
  return io.BytesIO(inner_file_content)
41
43
 
42
44
 
43
45
  def parse_xml_file(xml_file: io.BytesIO) -> list:
44
- tree = etree.parse(xml_file)
46
+ parser = etree.XMLParser(
47
+ ns_clean=True, remove_blank_text=True, remove_comments=True, recover=True
48
+ )
49
+ tree = etree.parse(xml_file, parser)
45
50
  # Definir os namespaces (substitua 'ns' pelo prefixo apropriado se necessário)
46
51
  namespaces = {"ns": "urn:bvmf.217.01.xsd"}
47
52
 
@@ -92,13 +97,17 @@ def process_df(df_raw: pd.DataFrame, reference_date: pd.Timestamp) -> pd.DataFra
92
97
  # Remover colunas cujos dados são constantes: MktDataStrmId, AdjstdQtStin e PrvsAdjstdQtStin
93
98
  df.drop(columns=["MktDataStrmId", "AdjstdQtStin", "PrvsAdjstdQtStin"], inplace=True)
94
99
 
100
+ df.insert(0, "RptDt", reference_date)
101
+ # Convert to datetime64[ns] since it is pandas default type for timestamps
102
+ df["RptDt"] = df["RptDt"].astype("datetime64[ns]")
103
+
95
104
  expiration = df["TckrSymb"].str[3:].apply(dif.get_expiration_date)
96
105
  # Insert the column at the beginning
97
- df.insert(1, "ExpDt", expiration)
106
+ df.insert(2, "ExpDt", expiration)
98
107
 
99
108
  business_days = brc.count_bdays(reference_date, df["ExpDt"])
100
109
  # Insert the column at the beginning
101
- df.insert(2, "BDaysToExp", business_days)
110
+ df.insert(3, "BDaysToExp", business_days)
102
111
  # Convert to nullable integer, since other columns use this data type
103
112
  df["BDaysToExp"] = df["BDaysToExp"].astype(pd.Int64Dtype())
104
113
  # Remove expired contracts
@@ -31,7 +31,7 @@ dependencies = [
31
31
  "lxml",
32
32
  ]
33
33
  dynamic = []
34
- version = "0.2.11"
34
+ version = "0.2.13"
35
35
 
36
36
  [project.license]
37
37
  file = "LICENSE"
@@ -1 +0,0 @@
1
- __version__ = "0.2.11"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes