detquantlib 3.0.2__tar.gz → 3.1.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: detquantlib
3
- Version: 3.0.2
3
+ Version: 3.1.1
4
4
  Summary: An internal library containing functions and classes that can be used across Quant models.
5
5
  Author: DET
6
6
  Requires-Python: >=3.10,<4.0
@@ -14,34 +14,36 @@ Requires-Dist: pandas (>=2.2.3,<3.0.0)
14
14
  Requires-Dist: paramiko (>=3.5.1,<4.0.0)
15
15
  Requires-Dist: plotly (>=6.0.1,<7.0.0)
16
16
  Requires-Dist: pyodbc (>=5.2.0,<6.0.0)
17
+ Requires-Dist: python-dotenv (>=1.1.0,<2.0.0)
17
18
  Project-URL: Repository, https://github.com/Dynamic-Energy-Trading/detquantlib
18
19
  Description-Content-Type: text/markdown
19
20
 
20
21
  # DET Quant Library
21
22
 
22
- ## Table of contents
23
+ ## Table of Contents
23
24
 
24
25
  <!--TOC-->
25
26
 
26
27
  - [DET Quant Library](#det-quant-library)
27
- - [Table of contents](#table-of-contents)
28
+ - [Table of Contents](#table-of-contents)
28
29
  - [Overview](#overview)
29
- - [Exposed symbols](#exposed-symbols)
30
- - [List of exposed symbols](#list-of-exposed-symbols)
30
+ - [Exposed Symbols](#exposed-symbols)
31
+ - [List of Exposed Symbols](#list-of-exposed-symbols)
31
32
  - [Configuration](#configuration)
33
+ - [Project Structure](#project-structure)
32
34
  - [Dependencies](#dependencies)
33
- - [Dependency manager](#dependency-manager)
35
+ - [Dependency Manager](#dependency-manager)
34
36
  - [Dependabot](#dependabot)
35
- - [GitHub actions](#github-actions)
36
- - [Workflow: Continuous integration (CI)](#workflow-continuous-integration-ci)
37
- - [Invoke tasks](#invoke-tasks)
38
- - [CI check: Testing](#ci-check-testing)
39
- - [CI check: Code formatting](#ci-check-code-formatting)
40
- - [Workflow: Package publisher](#workflow-package-publisher)
41
- - [Checking version updates](#checking-version-updates)
42
- - [Creating version tags](#creating-version-tags)
43
- - [Publishing package updates to PyPI](#publishing-package-updates-to-pypi)
44
- - [Release notes](#release-notes)
37
+ - [GitHub Actions](#github-actions)
38
+ - [Workflow: Continuous Integration (CI)](#workflow-continuous-integration-ci)
39
+ - [Invoke Tasks](#invoke-tasks)
40
+ - [CI Check: Testing](#ci-check-testing)
41
+ - [CI Check: Code Formatting](#ci-check-code-formatting)
42
+ - [Workflow: Package Publisher](#workflow-package-publisher)
43
+ - [Checking Version Updates](#checking-version-updates)
44
+ - [Creating Version Tags](#creating-version-tags)
45
+ - [Publishing Package Updates to PyPI](#publishing-package-updates-to-pypi)
46
+ - [Release Notes](#release-notes)
45
47
 
46
48
  <!--TOC-->
47
49
 
@@ -50,7 +52,7 @@ Description-Content-Type: text/markdown
50
52
  The DET Quant Library is an internal library containing functions and classes that can be used
51
53
  across Quant models.
52
54
 
53
- ## Exposed symbols
55
+ ## Exposed Symbols
54
56
 
55
57
  Some of the package's symbols (i.e. functions, classes, modules, etc.) are exposed via
56
58
  `__init__.py` files. They can therefore be imported with a more concise notation that does not
@@ -66,7 +68,7 @@ terminal:
66
68
  poetry run python docs.py
67
69
  ```
68
70
 
69
- ### List of exposed symbols
71
+ ### List of Exposed Symbols
70
72
 
71
73
  <!-- START EXPOSED SYMBOLS AUTO-GENERATED -->
72
74
 
@@ -86,13 +88,9 @@ Classes:
86
88
 
87
89
  ## Configuration
88
90
 
89
- ### Dependencies
90
-
91
- #### Dependency manager
91
+ ### Project Structure
92
92
 
93
- Project dependencies are managed by [Poetry](https://python-poetry.org/).
94
-
95
- The project follows the standard Poetry structure:
93
+ The project mainly follows the standard Poetry structure:
96
94
 
97
95
  ```
98
96
  detquantlib
@@ -104,17 +102,23 @@ detquantlib
104
102
  └── __init__.py
105
103
  ```
106
104
 
105
+ ### Dependencies
106
+
107
+ #### Dependency Manager
108
+
109
+ Project dependencies are managed by [Poetry](https://python-poetry.org/).
110
+
107
111
  #### Dependabot
108
112
 
109
113
  Automated dependency updates are executed with
110
114
  [Dependabot](https://docs.github.com/en/code-security/dependabot).
111
115
 
112
- ### GitHub actions
116
+ ### GitHub Actions
113
117
 
114
118
  The project's CI/CD pipeline is enforced with [GitHub actions](https://docs.github.com/en/actions)
115
119
  workflows.
116
120
 
117
- #### Workflow: Continuous integration (CI)
121
+ #### Workflow: Continuous Integration (CI)
118
122
 
119
123
  The continuous integration (CI) workflow runs tests to check the integrity of the codebase's
120
124
  content, and linters to check the consistency of its format.
@@ -126,7 +130,7 @@ The workflow was inspired by the following preconfigured templates:
126
130
  - [Poetry action](https://github.com/marketplace/actions/install-poetry-action): A GitHub action
127
131
  for installing and configuring Poetry.
128
132
 
129
- ##### Invoke tasks
133
+ ##### Invoke Tasks
130
134
 
131
135
  The workflow's checks and linters are specified with [Invoke](https://www.pyinvoke.org/) tasks,
132
136
  defined in a tasks.py file.
@@ -146,7 +150,7 @@ Use the `-h` (or `--help`) argument for help about a particular Invoke task. For
146
150
  inv lint -h
147
151
  ```
148
152
 
149
- ##### CI check: Testing
153
+ ##### CI Check: Testing
150
154
 
151
155
  Code changes are tested with the [Pytest](https://github.com/pytest-dev/pytest) package.
152
156
 
@@ -156,7 +160,7 @@ The CI check is executed with the following Invoke task:
156
160
  inv test -c
157
161
  ```
158
162
 
159
- ##### CI check: Code formatting
163
+ ##### CI Check: Code Formatting
160
164
 
161
165
  Linters are used to check that the code is properly formatted:
162
166
 
@@ -181,12 +185,12 @@ This command fixes the parts of the code that should be reformatted. Adding the
181
185
  `--check`) optional argument instructs the command to only _check_ if parts of the code should be
182
186
  reformatted, without applying any actual changes.
183
187
 
184
- #### Workflow: Package publisher
188
+ #### Workflow: Package Publisher
185
189
 
186
190
  The package publisher workflow checks the validity of package version updates, creates version
187
191
  tags, and publishes package updates to PyPI.
188
192
 
189
- ##### Checking version updates
193
+ ##### Checking Version Updates
190
194
 
191
195
  The workflow enforces version control:
192
196
 
@@ -198,17 +202,17 @@ The workflow enforces version control:
198
202
  - `Y` increments represent minor, backward compatible functionality updates.
199
203
  - `Z` increments represent patch/bugfix, backward compatible updates.
200
204
 
201
- ##### Creating version tags
205
+ ##### Creating Version Tags
202
206
 
203
207
  If the new package version is valid, the workflow automatically creates a new tag for every new
204
208
  master commit.
205
209
 
206
- ##### Publishing package updates to PyPI
210
+ ##### Publishing Package Updates to PyPI
207
211
 
208
212
  The workflow automatically publishes every new master commit to
209
213
  [PyPI](https://pypi.org/project/detquantlib/).
210
214
 
211
- ### Release notes
215
+ ### Release Notes
212
216
 
213
217
  When deemed necessary (especially in case of major updates), developers can document code
214
218
  changes in dedicated GitHub release notes.
@@ -1,28 +1,29 @@
1
1
  # DET Quant Library
2
2
 
3
- ## Table of contents
3
+ ## Table of Contents
4
4
 
5
5
  <!--TOC-->
6
6
 
7
7
  - [DET Quant Library](#det-quant-library)
8
- - [Table of contents](#table-of-contents)
8
+ - [Table of Contents](#table-of-contents)
9
9
  - [Overview](#overview)
10
- - [Exposed symbols](#exposed-symbols)
11
- - [List of exposed symbols](#list-of-exposed-symbols)
10
+ - [Exposed Symbols](#exposed-symbols)
11
+ - [List of Exposed Symbols](#list-of-exposed-symbols)
12
12
  - [Configuration](#configuration)
13
+ - [Project Structure](#project-structure)
13
14
  - [Dependencies](#dependencies)
14
- - [Dependency manager](#dependency-manager)
15
+ - [Dependency Manager](#dependency-manager)
15
16
  - [Dependabot](#dependabot)
16
- - [GitHub actions](#github-actions)
17
- - [Workflow: Continuous integration (CI)](#workflow-continuous-integration-ci)
18
- - [Invoke tasks](#invoke-tasks)
19
- - [CI check: Testing](#ci-check-testing)
20
- - [CI check: Code formatting](#ci-check-code-formatting)
21
- - [Workflow: Package publisher](#workflow-package-publisher)
22
- - [Checking version updates](#checking-version-updates)
23
- - [Creating version tags](#creating-version-tags)
24
- - [Publishing package updates to PyPI](#publishing-package-updates-to-pypi)
25
- - [Release notes](#release-notes)
17
+ - [GitHub Actions](#github-actions)
18
+ - [Workflow: Continuous Integration (CI)](#workflow-continuous-integration-ci)
19
+ - [Invoke Tasks](#invoke-tasks)
20
+ - [CI Check: Testing](#ci-check-testing)
21
+ - [CI Check: Code Formatting](#ci-check-code-formatting)
22
+ - [Workflow: Package Publisher](#workflow-package-publisher)
23
+ - [Checking Version Updates](#checking-version-updates)
24
+ - [Creating Version Tags](#creating-version-tags)
25
+ - [Publishing Package Updates to PyPI](#publishing-package-updates-to-pypi)
26
+ - [Release Notes](#release-notes)
26
27
 
27
28
  <!--TOC-->
28
29
 
@@ -31,7 +32,7 @@
31
32
  The DET Quant Library is an internal library containing functions and classes that can be used
32
33
  across Quant models.
33
34
 
34
- ## Exposed symbols
35
+ ## Exposed Symbols
35
36
 
36
37
  Some of the package's symbols (i.e. functions, classes, modules, etc.) are exposed via
37
38
  `__init__.py` files. They can therefore be imported with a more concise notation that does not
@@ -47,7 +48,7 @@ terminal:
47
48
  poetry run python docs.py
48
49
  ```
49
50
 
50
- ### List of exposed symbols
51
+ ### List of Exposed Symbols
51
52
 
52
53
  <!-- START EXPOSED SYMBOLS AUTO-GENERATED -->
53
54
 
@@ -67,13 +68,9 @@ Classes:
67
68
 
68
69
  ## Configuration
69
70
 
70
- ### Dependencies
71
-
72
- #### Dependency manager
71
+ ### Project Structure
73
72
 
74
- Project dependencies are managed by [Poetry](https://python-poetry.org/).
75
-
76
- The project follows the standard Poetry structure:
73
+ The project mainly follows the standard Poetry structure:
77
74
 
78
75
  ```
79
76
  detquantlib
@@ -85,17 +82,23 @@ detquantlib
85
82
  └── __init__.py
86
83
  ```
87
84
 
85
+ ### Dependencies
86
+
87
+ #### Dependency Manager
88
+
89
+ Project dependencies are managed by [Poetry](https://python-poetry.org/).
90
+
88
91
  #### Dependabot
89
92
 
90
93
  Automated dependency updates are executed with
91
94
  [Dependabot](https://docs.github.com/en/code-security/dependabot).
92
95
 
93
- ### GitHub actions
96
+ ### GitHub Actions
94
97
 
95
98
  The project's CI/CD pipeline is enforced with [GitHub actions](https://docs.github.com/en/actions)
96
99
  workflows.
97
100
 
98
- #### Workflow: Continuous integration (CI)
101
+ #### Workflow: Continuous Integration (CI)
99
102
 
100
103
  The continuous integration (CI) workflow runs tests to check the integrity of the codebase's
101
104
  content, and linters to check the consistency of its format.
@@ -107,7 +110,7 @@ The workflow was inspired by the following preconfigured templates:
107
110
  - [Poetry action](https://github.com/marketplace/actions/install-poetry-action): A GitHub action
108
111
  for installing and configuring Poetry.
109
112
 
110
- ##### Invoke tasks
113
+ ##### Invoke Tasks
111
114
 
112
115
  The workflow's checks and linters are specified with [Invoke](https://www.pyinvoke.org/) tasks,
113
116
  defined in a tasks.py file.
@@ -127,7 +130,7 @@ Use the `-h` (or `--help`) argument for help about a particular Invoke task. For
127
130
  inv lint -h
128
131
  ```
129
132
 
130
- ##### CI check: Testing
133
+ ##### CI Check: Testing
131
134
 
132
135
  Code changes are tested with the [Pytest](https://github.com/pytest-dev/pytest) package.
133
136
 
@@ -137,7 +140,7 @@ The CI check is executed with the following Invoke task:
137
140
  inv test -c
138
141
  ```
139
142
 
140
- ##### CI check: Code formatting
143
+ ##### CI Check: Code Formatting
141
144
 
142
145
  Linters are used to check that the code is properly formatted:
143
146
 
@@ -162,12 +165,12 @@ This command fixes the parts of the code that should be reformatted. Adding the
162
165
  `--check`) optional argument instructs the command to only _check_ if parts of the code should be
163
166
  reformatted, without applying any actual changes.
164
167
 
165
- #### Workflow: Package publisher
168
+ #### Workflow: Package Publisher
166
169
 
167
170
  The package publisher workflow checks the validity of package version updates, creates version
168
171
  tags, and publishes package updates to PyPI.
169
172
 
170
- ##### Checking version updates
173
+ ##### Checking Version Updates
171
174
 
172
175
  The workflow enforces version control:
173
176
 
@@ -179,17 +182,17 @@ The workflow enforces version control:
179
182
  - `Y` increments represent minor, backward compatible functionality updates.
180
183
  - `Z` increments represent patch/bugfix, backward compatible updates.
181
184
 
182
- ##### Creating version tags
185
+ ##### Creating Version Tags
183
186
 
184
187
  If the new package version is valid, the workflow automatically creates a new tag for every new
185
188
  master commit.
186
189
 
187
- ##### Publishing package updates to PyPI
190
+ ##### Publishing Package Updates to PyPI
188
191
 
189
192
  The workflow automatically publishes every new master commit to
190
193
  [PyPI](https://pypi.org/project/detquantlib/).
191
194
 
192
- ### Release notes
195
+ ### Release Notes
193
196
 
194
197
  When deemed necessary (especially in case of major updates), developers can document code
195
198
  changes in dedicated GitHub release notes.
@@ -639,6 +639,71 @@ class DetDatabase:
639
639
 
640
640
  return commodity_info
641
641
 
642
+ def load_account_positions(
643
+ self,
644
+ start_trading_date: datetime,
645
+ end_trading_date: datetime,
646
+ columns: list = None,
647
+ ) -> pd.DataFrame:
648
+ """
649
+ Loads account positions from the database, over a user-defined range of trading dates.
650
+
651
+ Args:
652
+ start_trading_date: Start trading date
653
+ end_trading_date: End trading date
654
+ columns: Requested database table columns. Set columns=["*"] (i.e. as list) to get
655
+ all columns.
656
+
657
+ Returns:
658
+ Dataframe containing quarterly account positions
659
+
660
+ Raises:
661
+ ValueError: Raises an error if no account position data is found for user inputs
662
+ """
663
+ # Set default column values
664
+ if columns is None:
665
+ columns = ["*"]
666
+
667
+ # Convert columns from list to string
668
+ if len(columns) == 1:
669
+ columns_str = str(columns[0])
670
+ else:
671
+ columns_str = f"[{'], ['.join(columns)}]"
672
+
673
+ # Convert dates from datetime to string
674
+ start_trading_date_str = start_trading_date.strftime("%Y-%m-%d")
675
+ end_trading_date_str = end_trading_date.strftime("%Y-%m-%d")
676
+
677
+ # Create query
678
+ table = DetDatabaseDefinitions.DEFINITIONS["table_name_account_position"]
679
+ query = (
680
+ f"SELECT {columns_str} FROM {table} "
681
+ f"WHERE CAST ([InsertionTimestamp] AS DATE) IN ('{start_trading_date_str}', "
682
+ f"'{end_trading_date_str}') "
683
+ )
684
+
685
+ # Query db
686
+ self.open_connection()
687
+ df = self.query_db(query)
688
+ self.close_connection()
689
+
690
+ if df.empty:
691
+ raise ValueError("No account position data found for user-defined inputs.")
692
+
693
+ # Sort data
694
+ df.sort_values(
695
+ by=["InsertionTimestamp"],
696
+ axis=0,
697
+ ascending=True,
698
+ inplace=True,
699
+ ignore_index=True,
700
+ )
701
+
702
+ # Convert dates from datetime.date to pd.Timestamp
703
+ df["InsertionTimestamp"] = pd.DatetimeIndex(df["InsertionTimestamp"])
704
+
705
+ return df
706
+
642
707
 
643
708
  class DetDatabaseDefinitions:
644
709
  """A class containing some hard-coded definitions related to the DET database."""
@@ -648,4 +713,5 @@ class DetDatabaseDefinitions:
648
713
  table_name_entsoe_day_ahead_spot_price="[ENTSOE].[DayAheadSpotPrice]",
649
714
  table_name_entsoe_imbalance_price="[ENTSOE].[ImbalancePrice]",
650
715
  table_name_futures_eod_settlement_price="[VW].[EODSettlementPrice]",
716
+ table_name_account_position="[TT].[AccountPosition]",
651
717
  )
@@ -0,0 +1 @@
1
+ # Empty file required by poetry. Do not delete.
@@ -0,0 +1 @@
1
+ # Empty file required by poetry. Do not delete.
@@ -0,0 +1 @@
1
+ # Empty file required by poetry. Do not delete.
@@ -0,0 +1 @@
1
+ # Empty file required by poetry. Do not delete.
@@ -0,0 +1 @@
1
+ # Empty file required by poetry. Do not delete.
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "detquantlib"
3
- version = "3.0.2"
3
+ version = "3.1.1"
4
4
  description = "An internal library containing functions and classes that can be used across Quant models."
5
5
  authors = ["DET"]
6
6
  readme = "README.md"
@@ -16,6 +16,7 @@ numpy = "^2.2.4"
16
16
  pandas = "^2.2.3"
17
17
  plotly = "^6.0.1"
18
18
  pyodbc = "^5.2.0"
19
+ python-dotenv = "^1.1.0"
19
20
 
20
21
  [tool.poetry.group.dev.dependencies]
21
22
  toml = "^0.10.2"
File without changes