detquantlib 3.8.0__tar.gz → 3.9.0__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.8.0 → detquantlib-3.9.0}/PKG-INFO +1 -1
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/data/databases/detdatabase.py +69 -20
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/figures/plotly_figures.py +12 -11
- {detquantlib-3.8.0 → detquantlib-3.9.0}/pyproject.toml +1 -1
- {detquantlib-3.8.0 → detquantlib-3.9.0}/LICENSE.txt +0 -0
- {detquantlib-3.8.0 → detquantlib-3.9.0}/README.md +0 -0
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/__init__.py +0 -0
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/data/__init__.py +0 -0
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/data/entsoe/entsoe.py +0 -0
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/data/sftp/sftp.py +0 -0
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/dates/__init__.py +0 -0
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/dates/dates.py +0 -0
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/figures/__init__.py +0 -0
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/outputs/__init__.py +0 -0
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/outputs/outputs_interface.py +0 -0
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/stats/__init__.py +0 -0
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/stats/data_analysis.py +0 -0
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/tradable_products/__init__.py +0 -0
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/tradable_products/tradable_products.py +0 -0
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/utils/__init__.py +0 -0
- {detquantlib-3.8.0 → detquantlib-3.9.0}/detquantlib/utils/utils.py +0 -0
|
@@ -100,6 +100,25 @@ class DetDatabase:
|
|
|
100
100
|
|
|
101
101
|
return df
|
|
102
102
|
|
|
103
|
+
@staticmethod
|
|
104
|
+
def get_table_name(def_key: str) -> str:
|
|
105
|
+
"""
|
|
106
|
+
Gets the name of a database table, according to the following logic:
|
|
107
|
+
1) First, try to get the table name from the corresponding environment variable.
|
|
108
|
+
2) If the environment variable is not defined, revert to the default table name.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
def_key: Definitions dictionary key corresponding to the desired table
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
Database table name
|
|
115
|
+
"""
|
|
116
|
+
definition = DetDatabaseDefinitions.DEFINITIONS[def_key]
|
|
117
|
+
table = os.getenv(definition["env_variable"])
|
|
118
|
+
if table is None:
|
|
119
|
+
table = definition["default_table_name"]
|
|
120
|
+
return table
|
|
121
|
+
|
|
103
122
|
def load_entsoe_day_ahead_spot_prices(
|
|
104
123
|
self,
|
|
105
124
|
commodity_name: str,
|
|
@@ -211,7 +230,7 @@ class DetDatabase:
|
|
|
211
230
|
end_date_str = end_delivery_date.strftime("%Y-%m-%d %H:%M:%S")
|
|
212
231
|
|
|
213
232
|
# Create query
|
|
214
|
-
table =
|
|
233
|
+
table = DetDatabase.get_table_name("entsoe_day_ahead_spot_price")
|
|
215
234
|
query = (
|
|
216
235
|
f"SELECT {columns_str} FROM {table} "
|
|
217
236
|
f"WHERE MapCode='{map_code}' "
|
|
@@ -410,7 +429,7 @@ class DetDatabase:
|
|
|
410
429
|
end_date_str = end_delivery_date.strftime("%Y-%m-%d %H:%M:%S")
|
|
411
430
|
|
|
412
431
|
# Create query
|
|
413
|
-
table =
|
|
432
|
+
table = DetDatabase.get_table_name("entsoe_imbalance_price")
|
|
414
433
|
query = (
|
|
415
434
|
f"SELECT {columns_str} FROM {table} "
|
|
416
435
|
f"WHERE MapCode='{map_code}' "
|
|
@@ -543,7 +562,7 @@ class DetDatabase:
|
|
|
543
562
|
end_trading_date_str = end_trading_date.strftime("%Y-%m-%d")
|
|
544
563
|
|
|
545
564
|
# Create query
|
|
546
|
-
table =
|
|
565
|
+
table = DetDatabase.get_table_name("futures_tt")
|
|
547
566
|
query = (
|
|
548
567
|
f"SELECT {columns_str} FROM {table} "
|
|
549
568
|
f"WHERE CommodityName='{commodity_name}' "
|
|
@@ -615,7 +634,7 @@ class DetDatabase:
|
|
|
615
634
|
columns_str = f"[{'], ['.join(columns)}]"
|
|
616
635
|
|
|
617
636
|
# Create query
|
|
618
|
-
table =
|
|
637
|
+
table = DetDatabase.get_table_name("commodity")
|
|
619
638
|
query = f"SELECT {columns_str} FROM {table} {conditions}"
|
|
620
639
|
|
|
621
640
|
# Query db
|
|
@@ -698,7 +717,7 @@ class DetDatabase:
|
|
|
698
717
|
end_trading_date_str = end_trading_date.strftime("%Y-%m-%d")
|
|
699
718
|
|
|
700
719
|
# Create query
|
|
701
|
-
table =
|
|
720
|
+
table = DetDatabase.get_table_name("account_position")
|
|
702
721
|
query = (
|
|
703
722
|
f"SELECT {columns_str} FROM {table} "
|
|
704
723
|
f"WHERE InsertionTimestamp>='{start_trading_date_str}' "
|
|
@@ -756,7 +775,7 @@ class DetDatabase:
|
|
|
756
775
|
identifiers_str = ", ".join(f"'{i}'" for i in identifiers)
|
|
757
776
|
|
|
758
777
|
# Create query
|
|
759
|
-
table =
|
|
778
|
+
table = DetDatabase.get_table_name("instrument")
|
|
760
779
|
query = f"SELECT {columns_str} FROM {table} WHERE [id] IN ({identifiers_str})"
|
|
761
780
|
|
|
762
781
|
# Query db
|
|
@@ -817,7 +836,7 @@ class DetDatabase:
|
|
|
817
836
|
end_trading_date_str = end_trading_date.strftime("%Y-%m-%d")
|
|
818
837
|
|
|
819
838
|
# Create query
|
|
820
|
-
table =
|
|
839
|
+
table = DetDatabase.get_table_name("futures_eex")
|
|
821
840
|
query = (
|
|
822
841
|
f"SELECT {columns_str} FROM {table} "
|
|
823
842
|
f"WHERE Product LIKE '{product_code}' "
|
|
@@ -926,7 +945,7 @@ class DetDatabase:
|
|
|
926
945
|
forecast_date_str = forecast_date.strftime("%Y-%m-%d")
|
|
927
946
|
|
|
928
947
|
# Create query
|
|
929
|
-
table =
|
|
948
|
+
table = DetDatabase.get_table_name("client_volume_forecast")
|
|
930
949
|
query = (
|
|
931
950
|
f"SELECT {columns_str} FROM {table} "
|
|
932
951
|
f"WHERE Profile='{profile}' "
|
|
@@ -1031,7 +1050,7 @@ class DetDatabase:
|
|
|
1031
1050
|
columns_str = f"[{'], ['.join(columns)}]"
|
|
1032
1051
|
|
|
1033
1052
|
# Create query
|
|
1034
|
-
table =
|
|
1053
|
+
table = DetDatabase.get_table_name("client_day_ahead_auction_bids")
|
|
1035
1054
|
query = (
|
|
1036
1055
|
f"SELECT {columns_str} FROM {table} "
|
|
1037
1056
|
f"WHERE ClientId='{client_id}' "
|
|
@@ -1102,7 +1121,7 @@ class DetDatabase:
|
|
|
1102
1121
|
columns_str = f"[{'], ['.join(columns)}]"
|
|
1103
1122
|
|
|
1104
1123
|
# Create query
|
|
1105
|
-
table =
|
|
1124
|
+
table = DetDatabase.get_table_name("client")
|
|
1106
1125
|
query = f"SELECT {columns_str} FROM {table} {conditions}"
|
|
1107
1126
|
|
|
1108
1127
|
# Query db
|
|
@@ -1154,14 +1173,44 @@ class DetDatabaseDefinitions:
|
|
|
1154
1173
|
"""A class containing some hard-coded definitions related to the DET database."""
|
|
1155
1174
|
|
|
1156
1175
|
DEFINITIONS = dict(
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1176
|
+
commodity=dict(
|
|
1177
|
+
env_variable="DET_DB_TABLE_COMMODITY",
|
|
1178
|
+
default_table_name="[META].[Commodity]",
|
|
1179
|
+
),
|
|
1180
|
+
entsoe_day_ahead_spot_price=dict(
|
|
1181
|
+
env_variable="DET_DB_TABLE_ENTSOE_DA",
|
|
1182
|
+
default_table_name="[ENTSOE].[DayAheadSpotPrice]",
|
|
1183
|
+
),
|
|
1184
|
+
entsoe_imbalance_price=dict(
|
|
1185
|
+
env_variable="DET_DB_TABLE_ENTSOE_IB",
|
|
1186
|
+
default_table_name="[ENTSOE].[ImbalancePrice]",
|
|
1187
|
+
),
|
|
1188
|
+
futures_tt=dict(
|
|
1189
|
+
env_variable="DET_DB_TABLE_FUTURES_TT",
|
|
1190
|
+
default_table_name="[VW].[EODSettlementPrice]",
|
|
1191
|
+
),
|
|
1192
|
+
futures_eex=dict(
|
|
1193
|
+
env_variable="DET_DB_TABLE_FUTURES_EEX",
|
|
1194
|
+
default_table_name="[EEX].[EODPrice]",
|
|
1195
|
+
),
|
|
1196
|
+
account_position=dict(
|
|
1197
|
+
env_variable="DET_DB_TABLE_ACCOUNT_POSITION",
|
|
1198
|
+
default_table_name="[TT].[AccountPosition]",
|
|
1199
|
+
),
|
|
1200
|
+
instrument=dict(
|
|
1201
|
+
env_variable="DET_DB_TABLE_INSTRUMENT",
|
|
1202
|
+
default_table_name="[TT].[Instrument]",
|
|
1203
|
+
),
|
|
1204
|
+
client_volume_forecast=dict(
|
|
1205
|
+
env_variable="DET_DB_TABLE_CLIENT_VOLUME_FORECAST",
|
|
1206
|
+
default_table_name="[DISP].[ForecastGold]",
|
|
1207
|
+
),
|
|
1208
|
+
client_day_ahead_auction_bids=dict(
|
|
1209
|
+
env_variable="DET_DB_TABLE_CLIENT_DA_AUCTION_BIDS",
|
|
1210
|
+
default_table_name="[TRADE].[ClientBid]",
|
|
1211
|
+
),
|
|
1212
|
+
client=dict(
|
|
1213
|
+
env_variable="DET_DB_TABLE_CLIENT",
|
|
1214
|
+
default_table_name="[META].[Client]",
|
|
1215
|
+
),
|
|
1167
1216
|
)
|
|
@@ -30,10 +30,7 @@ def set_standard_layout(fig: go.Figure) -> go.Figure:
|
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
def save_plotly_fig_to_json(
|
|
33
|
-
fig: go.Figure,
|
|
34
|
-
filename: str,
|
|
35
|
-
folder_dir: Path = PathDefinitions.get_outputs_plotly_folder_dir(),
|
|
36
|
-
standard_layout: bool = True,
|
|
33
|
+
fig: go.Figure, filename: str, folder_dir: Path = None, standard_layout: bool = True
|
|
37
34
|
):
|
|
38
35
|
"""
|
|
39
36
|
Saves a plotly figure object to a json file.
|
|
@@ -44,6 +41,9 @@ def save_plotly_fig_to_json(
|
|
|
44
41
|
folder_dir: Folder directory where the json file will be saved
|
|
45
42
|
standard_layout: If true, enforces a standard plotly layout
|
|
46
43
|
"""
|
|
44
|
+
if folder_dir is None:
|
|
45
|
+
PathDefinitions.get_outputs_plotly_folder_dir()
|
|
46
|
+
|
|
47
47
|
# Create plotly folder if it doesn't exist yet
|
|
48
48
|
folder_dir.mkdir(parents=True, exist_ok=True)
|
|
49
49
|
|
|
@@ -61,10 +61,7 @@ def save_plotly_fig_to_json(
|
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
def save_plotly_fig_to_html(
|
|
64
|
-
fig: go.Figure,
|
|
65
|
-
filename: str,
|
|
66
|
-
folder_dir: Path = PathDefinitions.get_outputs_plotly_folder_dir(),
|
|
67
|
-
standard_layout: bool = True,
|
|
64
|
+
fig: go.Figure, filename: str, folder_dir: Path = None, standard_layout: bool = True
|
|
68
65
|
):
|
|
69
66
|
"""
|
|
70
67
|
Saves a plotly figure object to an html file.
|
|
@@ -75,6 +72,9 @@ def save_plotly_fig_to_html(
|
|
|
75
72
|
folder_dir: Folder directory where the html file will be saved
|
|
76
73
|
standard_layout: If true, enforces a standard plotly layout
|
|
77
74
|
"""
|
|
75
|
+
if folder_dir is None:
|
|
76
|
+
folder_dir = PathDefinitions.get_outputs_plotly_folder_dir()
|
|
77
|
+
|
|
78
78
|
# Create plotly folder if it doesn't exist yet
|
|
79
79
|
folder_dir.mkdir(parents=True, exist_ok=True)
|
|
80
80
|
|
|
@@ -89,9 +89,7 @@ def save_plotly_fig_to_html(
|
|
|
89
89
|
fig.write_html(file_dir)
|
|
90
90
|
|
|
91
91
|
|
|
92
|
-
def show_plotly_fig_json(
|
|
93
|
-
filename: str, folder_dir: Path = PathDefinitions.get_outputs_plotly_folder_dir()
|
|
94
|
-
):
|
|
92
|
+
def show_plotly_fig_json(filename: str, folder_dir: Path = None):
|
|
95
93
|
"""
|
|
96
94
|
Short helper function to display a plotly figure stored in a json file.
|
|
97
95
|
|
|
@@ -99,6 +97,9 @@ def show_plotly_fig_json(
|
|
|
99
97
|
filename: Name of json file containing the plotly figure
|
|
100
98
|
folder_dir: Folder directory containing the json file
|
|
101
99
|
"""
|
|
100
|
+
if folder_dir is None:
|
|
101
|
+
PathDefinitions.get_outputs_plotly_folder_dir()
|
|
102
|
+
|
|
102
103
|
# Get json file directory
|
|
103
104
|
file_dir = folder_dir.joinpath(f"{filename}.json")
|
|
104
105
|
|
|
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
|