detquantlib 3.4.0__tar.gz → 3.5.1__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.
- {detquantlib-3.4.0 → detquantlib-3.5.1}/PKG-INFO +1 -1
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/data/databases/detdatabase.py +76 -49
- {detquantlib-3.4.0 → detquantlib-3.5.1}/pyproject.toml +1 -1
- {detquantlib-3.4.0 → detquantlib-3.5.1}/LICENSE.txt +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/README.md +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/__init__.py +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/data/__init__.py +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/data/entsoe/entsoe.py +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/data/sftp/sftp.py +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/dates/__init__.py +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/dates/dates.py +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/figures/__init__.py +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/figures/plotly_figures.py +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/outputs/__init__.py +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/outputs/outputs_interface.py +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/stats/__init__.py +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/stats/data_analysis.py +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/tradable_products/__init__.py +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/tradable_products/tradable_products.py +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/utils/__init__.py +0 -0
- {detquantlib-3.4.0 → detquantlib-3.5.1}/detquantlib/utils/utils.py +0 -0
|
@@ -109,6 +109,7 @@ class DetDatabase:
|
|
|
109
109
|
end_delivery_date: datetime = None,
|
|
110
110
|
columns: list = None,
|
|
111
111
|
process_data: bool = True,
|
|
112
|
+
timezone_aware_dates: bool = False,
|
|
112
113
|
) -> pd.DataFrame:
|
|
113
114
|
"""
|
|
114
115
|
Loads entsoe day-ahead spot prices from the database.
|
|
@@ -128,6 +129,8 @@ class DetDatabase:
|
|
|
128
129
|
columns: Requested database table columns. Set columns=["*"] (i.e. as list) to get
|
|
129
130
|
all columns.
|
|
130
131
|
process_data: Indicates if data should be processed convert to standardized format
|
|
132
|
+
timezone_aware_dates: If true, returns all dates as timezone-aware. Otherwise,
|
|
133
|
+
returns them as timezone-naive.
|
|
131
134
|
|
|
132
135
|
Returns:
|
|
133
136
|
Dataframe containing day-ahead spot prices
|
|
@@ -137,8 +140,6 @@ class DetDatabase:
|
|
|
137
140
|
compatible
|
|
138
141
|
ValueError: Raises an error if the combination of trading dates and delivery dates
|
|
139
142
|
is not valid.
|
|
140
|
-
ValueError: Raises an error if match with input commodity name is not unique
|
|
141
|
-
ValueError: Raises an error if input commodity is not supported
|
|
142
143
|
ValueError: Raises an error if no price data is found for user inputs
|
|
143
144
|
"""
|
|
144
145
|
# Input validation
|
|
@@ -181,21 +182,13 @@ class DetDatabase:
|
|
|
181
182
|
# Note: The local timezone is important because ENTSOE provides all prices in the UTC
|
|
182
183
|
# timezone. We first convert the dates from UTC to the local timezone, and then filter
|
|
183
184
|
# for the requested delivery period.
|
|
184
|
-
commodity_info = self.
|
|
185
|
-
|
|
185
|
+
commodity_info = self.get_commodity_info(
|
|
186
|
+
filter_column="Name",
|
|
187
|
+
filter_value=commodity_name,
|
|
188
|
+
info_columns=["Timezone", "EntsoeMapCode"],
|
|
186
189
|
)
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
elif commodity_info.shape[0] == 0:
|
|
190
|
-
supported_commodities = self.load_commodities(columns=["Name"])
|
|
191
|
-
supported_commodities_str = ", ".join(f"'{x}'" for x in supported_commodities["Name"])
|
|
192
|
-
raise ValueError(
|
|
193
|
-
f"Commodity '{commodity_name}' is not supported. Supported commodities: "
|
|
194
|
-
f"{supported_commodities_str}."
|
|
195
|
-
)
|
|
196
|
-
else:
|
|
197
|
-
map_code = commodity_info.loc[0, "EntsoeMapCode"]
|
|
198
|
-
timezone = commodity_info.loc[0, "Timezone"]
|
|
190
|
+
map_code = commodity_info["EntsoeMapCode"]
|
|
191
|
+
timezone = commodity_info["Timezone"]
|
|
199
192
|
|
|
200
193
|
# Convert start trading date to start delivery date
|
|
201
194
|
if start_trading_date is not None:
|
|
@@ -239,11 +232,20 @@ class DetDatabase:
|
|
|
239
232
|
by=["DateTime(UTC)"], axis=0, ascending=True, inplace=True, ignore_index=True
|
|
240
233
|
)
|
|
241
234
|
|
|
235
|
+
# Convert date columns to timezone-aware dates
|
|
236
|
+
cols_date_utc = ["DateTime(UTC)", "UpdateTime(UTC)", "InsertionTimestamp"]
|
|
237
|
+
for c in cols_date_utc:
|
|
238
|
+
if c in df.columns:
|
|
239
|
+
df[c] = df[c].dt.tz_localize("UTC")
|
|
240
|
+
|
|
242
241
|
# Add column with delivery date expressed in local timezone
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
242
|
+
df[f"DateTime({timezone})"] = df["DateTime(UTC)"].dt.tz_convert(timezone)
|
|
243
|
+
|
|
244
|
+
if not timezone_aware_dates:
|
|
245
|
+
cols_date_all = cols_date_utc + [f"DateTime({timezone})"]
|
|
246
|
+
for c in cols_date_all:
|
|
247
|
+
if c in df.columns:
|
|
248
|
+
df[c] = df[c].dt.tz_localize(None)
|
|
247
249
|
|
|
248
250
|
# Process raw data and convert it to standardized format
|
|
249
251
|
if process_data:
|
|
@@ -266,6 +268,8 @@ class DetDatabase:
|
|
|
266
268
|
Returns:
|
|
267
269
|
Processed dataframe containing day-ahead spot prices
|
|
268
270
|
"""
|
|
271
|
+
df_in.reset_index(drop=True, inplace=True)
|
|
272
|
+
|
|
269
273
|
# Initialize output dataframe
|
|
270
274
|
df_out = pd.DataFrame()
|
|
271
275
|
|
|
@@ -277,7 +281,7 @@ class DetDatabase:
|
|
|
277
281
|
df_out["TradingDate"] = trading_date
|
|
278
282
|
|
|
279
283
|
# Set delivery start date
|
|
280
|
-
df_out["DeliveryStart"] = df_in[f"DateTime({timezone})"]
|
|
284
|
+
df_out["DeliveryStart"] = df_in[f"DateTime({timezone})"]
|
|
281
285
|
|
|
282
286
|
# Set delivery end date
|
|
283
287
|
delivery_end = [d + relativedelta(hours=1) for d in df_in[f"DateTime({timezone})"]]
|
|
@@ -300,6 +304,7 @@ class DetDatabase:
|
|
|
300
304
|
end_delivery_date: datetime = None,
|
|
301
305
|
columns: list = None,
|
|
302
306
|
process_data: bool = True,
|
|
307
|
+
timezone_aware_dates: bool = False,
|
|
303
308
|
) -> pd.DataFrame:
|
|
304
309
|
"""
|
|
305
310
|
Loads entsoe imbalance prices from the database.
|
|
@@ -319,6 +324,8 @@ class DetDatabase:
|
|
|
319
324
|
columns: Requested database table columns. Set columns=["*"] (i.e. as list) to get
|
|
320
325
|
all columns.
|
|
321
326
|
process_data: Indicates if data should be processed convert to standardized format
|
|
327
|
+
timezone_aware_dates: If true, returns all dates as timezone-aware. Otherwise,
|
|
328
|
+
returns them as timezone-naive.
|
|
322
329
|
|
|
323
330
|
Returns:
|
|
324
331
|
Dataframe containing imbalance prices
|
|
@@ -328,8 +335,6 @@ class DetDatabase:
|
|
|
328
335
|
compatible
|
|
329
336
|
ValueError: Raises an error if the combination of trading dates and delivery dates
|
|
330
337
|
is not valid.
|
|
331
|
-
ValueError: Raises an error if match with input commodity name is not unique
|
|
332
|
-
ValueError: Raises an error if input commodity is not supported
|
|
333
338
|
ValueError: Raises an error if no price data is found for user inputs
|
|
334
339
|
"""
|
|
335
340
|
# Input validation
|
|
@@ -378,21 +383,13 @@ class DetDatabase:
|
|
|
378
383
|
# Note: The local timezone is important because ENTSOE provides all prices in the UTC
|
|
379
384
|
# timezone. We first convert the dates from UTC to the local timezone, and then filter
|
|
380
385
|
# for the requested delivery period.
|
|
381
|
-
commodity_info = self.
|
|
382
|
-
|
|
386
|
+
commodity_info = self.get_commodity_info(
|
|
387
|
+
filter_column="Name",
|
|
388
|
+
filter_value=commodity_name,
|
|
389
|
+
info_columns=["Timezone", "EntsoeMapCode"],
|
|
383
390
|
)
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
elif commodity_info.shape[0] == 0:
|
|
387
|
-
supported_commodities = self.load_commodities(columns=["Name"])
|
|
388
|
-
supported_commodities_str = ", ".join(f"'{x}'" for x in supported_commodities["Name"])
|
|
389
|
-
raise ValueError(
|
|
390
|
-
f"Commodity '{commodity_name}' is not supported. Supported commodities: "
|
|
391
|
-
f"{supported_commodities_str}."
|
|
392
|
-
)
|
|
393
|
-
else:
|
|
394
|
-
map_code = commodity_info.loc[0, "EntsoeMapCode"]
|
|
395
|
-
timezone = commodity_info.loc[0, "Timezone"]
|
|
391
|
+
map_code = commodity_info["EntsoeMapCode"]
|
|
392
|
+
timezone = commodity_info["Timezone"]
|
|
396
393
|
|
|
397
394
|
# Convert start trading date to start delivery date
|
|
398
395
|
if start_trading_date is not None:
|
|
@@ -435,11 +432,20 @@ class DetDatabase:
|
|
|
435
432
|
by=["DateTime(UTC)"], axis=0, ascending=True, inplace=True, ignore_index=True
|
|
436
433
|
)
|
|
437
434
|
|
|
435
|
+
# Convert date columns to timezone-aware dates
|
|
436
|
+
cols_date_utc = ["DateTime(UTC)", "UpdateTime(UTC)", "InsertionTimestamp"]
|
|
437
|
+
for c in cols_date_utc:
|
|
438
|
+
if c in df.columns:
|
|
439
|
+
df[c] = df[c].dt.tz_localize("UTC")
|
|
440
|
+
|
|
438
441
|
# Add column with delivery date expressed in local timezone
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
442
|
+
df[f"DateTime({timezone})"] = df["DateTime(UTC)"].dt.tz_convert(timezone)
|
|
443
|
+
|
|
444
|
+
if not timezone_aware_dates:
|
|
445
|
+
cols_date_all = cols_date_utc + [f"DateTime({timezone})"]
|
|
446
|
+
for c in cols_date_all:
|
|
447
|
+
if c in df.columns:
|
|
448
|
+
df[c] = df[c].dt.tz_localize(None)
|
|
443
449
|
|
|
444
450
|
# Process raw data and convert it to standardized format
|
|
445
451
|
if process_data:
|
|
@@ -462,6 +468,8 @@ class DetDatabase:
|
|
|
462
468
|
Returns:
|
|
463
469
|
Processed dataframe containing imbalance prices
|
|
464
470
|
"""
|
|
471
|
+
df_in.reset_index(drop=True, inplace=True)
|
|
472
|
+
|
|
465
473
|
# Initialize output dataframe
|
|
466
474
|
df_out = pd.DataFrame()
|
|
467
475
|
|
|
@@ -469,10 +477,10 @@ class DetDatabase:
|
|
|
469
477
|
df_out["CommodityName"] = [commodity_name] * df_in.shape[0]
|
|
470
478
|
|
|
471
479
|
# Set trading date
|
|
472
|
-
df_out["TradingDate"] = df_in[f"DateTime({timezone})"].dt.floor("D")
|
|
480
|
+
df_out["TradingDate"] = df_in[f"DateTime({timezone})"].dt.floor("D")
|
|
473
481
|
|
|
474
482
|
# Set delivery start date
|
|
475
|
-
df_out["DeliveryStart"] = df_in[f"DateTime({timezone})"]
|
|
483
|
+
df_out["DeliveryStart"] = df_in[f"DateTime({timezone})"]
|
|
476
484
|
|
|
477
485
|
# Set delivery end date
|
|
478
486
|
delivery_end = [d + relativedelta(minutes=15) for d in df_in[f"DateTime({timezone})"]]
|
|
@@ -495,6 +503,7 @@ class DetDatabase:
|
|
|
495
503
|
tenors: list,
|
|
496
504
|
delivery_type: str,
|
|
497
505
|
columns: list = None,
|
|
506
|
+
timezone_aware_dates: bool = False,
|
|
498
507
|
) -> pd.DataFrame:
|
|
499
508
|
"""
|
|
500
509
|
Loads futures end-of-day settlement prices from the database, over a user-defined range
|
|
@@ -508,6 +517,8 @@ class DetDatabase:
|
|
|
508
517
|
delivery_type: Delivery type ("Base", "Peak", "Offpeak")
|
|
509
518
|
columns: Requested database table columns. Set columns=["*"] (i.e. as list) to get
|
|
510
519
|
all columns.
|
|
520
|
+
timezone_aware_dates: If true, returns all dates as timezone-aware. Otherwise,
|
|
521
|
+
returns them as timezone-naive.
|
|
511
522
|
|
|
512
523
|
Returns:
|
|
513
524
|
Dataframe containing futures end-of-day settlement prices
|
|
@@ -561,9 +572,24 @@ class DetDatabase:
|
|
|
561
572
|
)
|
|
562
573
|
|
|
563
574
|
# Convert dates from datetime.date to pd.Timestamp
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
575
|
+
cols_date = ["TradingDate", "DeliveryStart", "DeliveryEnd"]
|
|
576
|
+
for c in cols_date:
|
|
577
|
+
if c in df.columns:
|
|
578
|
+
df[c] = pd.DatetimeIndex(df[c])
|
|
579
|
+
|
|
580
|
+
if timezone_aware_dates:
|
|
581
|
+
# Get local timezone
|
|
582
|
+
commodity_info = self.get_commodity_info(
|
|
583
|
+
filter_column="Name", filter_value=commodity_name, info_columns=["Timezone"]
|
|
584
|
+
)
|
|
585
|
+
timezone = commodity_info["Timezone"]
|
|
586
|
+
|
|
587
|
+
# Convert timezone-naive to timezone-aware dates
|
|
588
|
+
df["InsertionTimestamp"] = df["InsertionTimestamp"].dt.tz_localize("UTC")
|
|
589
|
+
cols_local_tz = ["TradingDate", "DeliveryStart", "DeliveryEnd"]
|
|
590
|
+
for c in cols_local_tz:
|
|
591
|
+
if c in df.columns:
|
|
592
|
+
df[c] = df[c].dt.tz_localize(timezone)
|
|
567
593
|
|
|
568
594
|
return df
|
|
569
595
|
|
|
@@ -826,9 +852,10 @@ class DetDatabase:
|
|
|
826
852
|
)
|
|
827
853
|
|
|
828
854
|
# Convert dates from datetime.date to pd.Timestamp
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
855
|
+
cols_date = ["TradingDate", "Delivery Start", "Delivery End"]
|
|
856
|
+
for c in cols_date:
|
|
857
|
+
if c in df.columns:
|
|
858
|
+
df[c] = pd.DatetimeIndex(df[c])
|
|
832
859
|
|
|
833
860
|
# Drop duplicates
|
|
834
861
|
df = df.drop_duplicates()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|