Skip to content

Commit 4b622fa

Browse files
committed
more minor fixes to nordpool parsing
1 parent 5397eaa commit 4b622fa

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

bitepy/data.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,12 @@ def _read_id_table_2021(self, timestamp, datapath):
234234

235235

236236
def _read_nordpool_table(self, date, marketdatapath):
237-
"""Read and process NordPool parquet files for a specific date."""
238-
year = str(date.year)
239-
month = f"{date.month:02d}"
240-
day = f"{date.day:02d}"
241-
folder_path = Path(marketdatapath) / year / month / day
237+
"""Read and process NordPool parquet files for a specific date.
238+
Nordpool contains flags for full and partial execution of orders. We disregard this, as it will become apparent in our backtesting LOB traversal. After partial execution, orders are sometimes modified, deleted etc., this all stays relevant and is handled.
239+
We also currently still disregard FoK and IoC orders (treat them as 0 validity duration). They have all the same updateTime in their message-chain.
240+
"""
241+
date_folder = date.strftime("%Y%m%d")
242+
folder_path = Path(marketdatapath) / date_folder
242243

243244
if not folder_path.exists():
244245
raise FileNotFoundError(f"Folder not found: {folder_path}")
@@ -259,6 +260,7 @@ def _read_nordpool_table(self, date, marketdatapath):
259260
# Convert timestamps (needed for subsequent filtering and processing)
260261
df = (df
261262
.assign(createdTime=lambda x: pd.to_datetime(x['createdTime'], format='ISO8601'))
263+
.assign(updatedTime=lambda x: pd.to_datetime(x['updatedTime'], format='ISO8601'))
262264
.assign(expirationTime=lambda x: pd.to_datetime(x['expirationTime'], format='ISO8601'))
263265
.assign(deliveryStart=lambda x: pd.to_datetime(x['deliveryStart'], format='ISO8601'))
264266
.assign(deliveryEnd=lambda x: pd.to_datetime(x['deliveryEnd'], format='ISO8601'))
@@ -340,6 +342,7 @@ def replace_letters(order_id):
340342
df["df_index_copy"] = df.index
341343
merged = pd.merge(cancel_messages, df.loc[indexer_messA_with_cancel], on='order')
342344
df.loc[merged["df_index_copy"].to_numpy(), "validity"] = merged["transaction_x"].to_numpy()
345+
df.drop("df_index_copy", axis=1, inplace=True)
343346

344347
df = df.loc[lambda x: ~(x["action"] == "D")]
345348

@@ -366,6 +369,9 @@ def replace_letters(order_id):
366369
df["start"] = df["start"].dt.strftime('%Y-%m-%dT%H:%M:%SZ')
367370
df["transaction"] = df["transaction"].dt.strftime('%Y-%m-%dT%H:%M:%S.%f').str[:-3] + 'Z'
368371
df["validity"] = df["validity"].dt.strftime('%Y-%m-%dT%H:%M:%S.%f').str[:-3] + 'Z'
372+
373+
# rename side to all uppercase
374+
df['side'] = df['side'].str.upper()
369375

370376
# Select and order final columns
371377
df = df[['initial', 'side', 'start', 'transaction', 'validity', 'price', 'quantity']]
@@ -446,6 +452,10 @@ def parse_market_data(self, start_date_str: str, end_date_str: str, marketdatapa
446452
df = df.sort_values(by='transaction')
447453
df['transaction_date'] = pd.to_datetime(df['transaction']).dt.date
448454
grouped = df.groupby('transaction_date')
455+
456+
# round price to 2 decimals and quantity to 1 decimal
457+
df['price'] = df['price'].round(2)
458+
df['quantity'] = df['quantity'].round(1)
449459

450460
save_date = dt1.date()
451461
group = grouped.get_group(save_date)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ build-backend = "scikit_build_core.build"
99

1010
[project]
1111
name = "bitepy"
12-
version = "0.6.2"
12+
version = "0.6.3"
1313
authors = [
1414
{ name="David Schaurecker", email="dschaurecker@gmail.com" },
1515
]

0 commit comments

Comments
 (0)