detquantlib 3.0.1__tar.gz → 3.1.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: detquantlib
3
- Version: 3.0.1
3
+ Version: 3.1.0
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
@@ -19,29 +19,30 @@ Description-Content-Type: text/markdown
19
19
 
20
20
  # DET Quant Library
21
21
 
22
- ## Table of contents
22
+ ## Table of Contents
23
23
 
24
24
  <!--TOC-->
25
25
 
26
26
  - [DET Quant Library](#det-quant-library)
27
- - [Table of contents](#table-of-contents)
27
+ - [Table of Contents](#table-of-contents)
28
28
  - [Overview](#overview)
29
- - [Exposed symbols](#exposed-symbols)
30
- - [List of exposed symbols](#list-of-exposed-symbols)
29
+ - [Exposed Symbols](#exposed-symbols)
30
+ - [List of Exposed Symbols](#list-of-exposed-symbols)
31
31
  - [Configuration](#configuration)
32
+ - [Project Structure](#project-structure)
32
33
  - [Dependencies](#dependencies)
33
- - [Dependency manager](#dependency-manager)
34
+ - [Dependency Manager](#dependency-manager)
34
35
  - [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)
36
+ - [GitHub Actions](#github-actions)
37
+ - [Workflow: Continuous Integration (CI)](#workflow-continuous-integration-ci)
38
+ - [Invoke Tasks](#invoke-tasks)
39
+ - [CI Check: Testing](#ci-check-testing)
40
+ - [CI Check: Code Formatting](#ci-check-code-formatting)
41
+ - [Workflow: Package Publisher](#workflow-package-publisher)
42
+ - [Checking Version Updates](#checking-version-updates)
43
+ - [Creating Version Tags](#creating-version-tags)
44
+ - [Publishing Package Updates to PyPI](#publishing-package-updates-to-pypi)
45
+ - [Release Notes](#release-notes)
45
46
 
46
47
  <!--TOC-->
47
48
 
@@ -50,7 +51,7 @@ Description-Content-Type: text/markdown
50
51
  The DET Quant Library is an internal library containing functions and classes that can be used
51
52
  across Quant models.
52
53
 
53
- ## Exposed symbols
54
+ ## Exposed Symbols
54
55
 
55
56
  Some of the package's symbols (i.e. functions, classes, modules, etc.) are exposed via
56
57
  `__init__.py` files. They can therefore be imported with a more concise notation that does not
@@ -66,7 +67,7 @@ terminal:
66
67
  poetry run python docs.py
67
68
  ```
68
69
 
69
- ### List of exposed symbols
70
+ ### List of Exposed Symbols
70
71
 
71
72
  <!-- START EXPOSED SYMBOLS AUTO-GENERATED -->
72
73
 
@@ -86,13 +87,9 @@ Classes:
86
87
 
87
88
  ## Configuration
88
89
 
89
- ### Dependencies
90
-
91
- #### Dependency manager
90
+ ### Project Structure
92
91
 
93
- Project dependencies are managed by [Poetry](https://python-poetry.org/).
94
-
95
- The project follows the standard Poetry structure:
92
+ The project mainly follows the standard Poetry structure:
96
93
 
97
94
  ```
98
95
  detquantlib
@@ -104,17 +101,23 @@ detquantlib
104
101
  └── __init__.py
105
102
  ```
106
103
 
104
+ ### Dependencies
105
+
106
+ #### Dependency Manager
107
+
108
+ Project dependencies are managed by [Poetry](https://python-poetry.org/).
109
+
107
110
  #### Dependabot
108
111
 
109
112
  Automated dependency updates are executed with
110
113
  [Dependabot](https://docs.github.com/en/code-security/dependabot).
111
114
 
112
- ### GitHub actions
115
+ ### GitHub Actions
113
116
 
114
117
  The project's CI/CD pipeline is enforced with [GitHub actions](https://docs.github.com/en/actions)
115
118
  workflows.
116
119
 
117
- #### Workflow: Continuous integration (CI)
120
+ #### Workflow: Continuous Integration (CI)
118
121
 
119
122
  The continuous integration (CI) workflow runs tests to check the integrity of the codebase's
120
123
  content, and linters to check the consistency of its format.
@@ -126,7 +129,7 @@ The workflow was inspired by the following preconfigured templates:
126
129
  - [Poetry action](https://github.com/marketplace/actions/install-poetry-action): A GitHub action
127
130
  for installing and configuring Poetry.
128
131
 
129
- ##### Invoke tasks
132
+ ##### Invoke Tasks
130
133
 
131
134
  The workflow's checks and linters are specified with [Invoke](https://www.pyinvoke.org/) tasks,
132
135
  defined in a tasks.py file.
@@ -146,7 +149,7 @@ Use the `-h` (or `--help`) argument for help about a particular Invoke task. For
146
149
  inv lint -h
147
150
  ```
148
151
 
149
- ##### CI check: Testing
152
+ ##### CI Check: Testing
150
153
 
151
154
  Code changes are tested with the [Pytest](https://github.com/pytest-dev/pytest) package.
152
155
 
@@ -156,7 +159,7 @@ The CI check is executed with the following Invoke task:
156
159
  inv test -c
157
160
  ```
158
161
 
159
- ##### CI check: Code formatting
162
+ ##### CI Check: Code Formatting
160
163
 
161
164
  Linters are used to check that the code is properly formatted:
162
165
 
@@ -181,12 +184,12 @@ This command fixes the parts of the code that should be reformatted. Adding the
181
184
  `--check`) optional argument instructs the command to only _check_ if parts of the code should be
182
185
  reformatted, without applying any actual changes.
183
186
 
184
- #### Workflow: Package publisher
187
+ #### Workflow: Package Publisher
185
188
 
186
189
  The package publisher workflow checks the validity of package version updates, creates version
187
190
  tags, and publishes package updates to PyPI.
188
191
 
189
- ##### Checking version updates
192
+ ##### Checking Version Updates
190
193
 
191
194
  The workflow enforces version control:
192
195
 
@@ -198,17 +201,17 @@ The workflow enforces version control:
198
201
  - `Y` increments represent minor, backward compatible functionality updates.
199
202
  - `Z` increments represent patch/bugfix, backward compatible updates.
200
203
 
201
- ##### Creating version tags
204
+ ##### Creating Version Tags
202
205
 
203
206
  If the new package version is valid, the workflow automatically creates a new tag for every new
204
207
  master commit.
205
208
 
206
- ##### Publishing package updates to PyPI
209
+ ##### Publishing Package Updates to PyPI
207
210
 
208
211
  The workflow automatically publishes every new master commit to
209
212
  [PyPI](https://pypi.org/project/detquantlib/).
210
213
 
211
- ### Release notes
214
+ ### Release Notes
212
215
 
213
216
  When deemed necessary (especially in case of major updates), developers can document code
214
217
  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
  )
@@ -78,8 +78,8 @@ def calc_months_diff(
78
78
  date and end date, irrespective of the day. For example, suppose that start date
79
79
  is 15-Jan-2025 and end date is 3-Mar-2025. Then, the month difference between
80
80
  Jan-2025 and Mar-2025 is 2.
81
- - diff_method="time": Counts the month difference, accounting the day and time of the
82
- start and end dates. For example:
81
+ - diff_method="time": Counts the month difference, accounting for the day and time
82
+ of the start and end dates. For example:
83
83
  - Suppose that start date is 15-Jan-2025 and end date is 3-Mar-2025. Then:
84
84
  - start date + 1 months = 15-Feb-2025
85
85
  - start date + 2 months = 15-Mar-2025
@@ -103,7 +103,7 @@ def calc_months_diff(
103
103
  ValueError: Raises an error when the input argument 'diff_method' is invalid
104
104
  """
105
105
  # Input validation
106
- if end_date < start_date:
106
+ if end_date < start_date and diff_method != "month":
107
107
  raise ValueError("End date cannot be smaller than start date.")
108
108
 
109
109
  # Calculate month difference
@@ -34,13 +34,6 @@ def convert_delivery_start_date_to_maturity(
34
34
  # Make input product string lower case only
35
35
  product = product.lower()
36
36
 
37
- # Validate input dates
38
- if delivery_start_date < trading_date:
39
- raise ValueError(
40
- "Input argument 'delivery_start_date' cannot be smaller than input argument "
41
- "'trading_date'."
42
- )
43
-
44
37
  if product == "month":
45
38
  maturity = calc_months_diff(
46
39
  start_date=trading_date,
@@ -49,13 +42,13 @@ def convert_delivery_start_date_to_maturity(
49
42
  )
50
43
 
51
44
  elif product == "quarter":
52
- quarter = pd.Timestamp(trading_date).quarter
53
- year_start_date = datetime(trading_date.year, 1, 1)
54
- trading_quarter_start_date = year_start_date + relativedelta(months=((quarter - 1) * 3))
45
+ trading_quarter_start_date = convert_maturity_to_delivery_start_date(
46
+ trading_date=trading_date, maturity=0, product="quarter"
47
+ )
55
48
 
56
- quarter = pd.Timestamp(delivery_start_date).quarter
57
- year_start_date = datetime(delivery_start_date.year, 1, 1)
58
- delivery_quarter_start_date = year_start_date + relativedelta(months=((quarter - 1) * 3))
49
+ delivery_quarter_start_date = convert_maturity_to_delivery_start_date(
50
+ trading_date=delivery_start_date, maturity=0, product="quarter"
51
+ )
59
52
 
60
53
  months_diff = calc_months_diff(
61
54
  start_date=trading_quarter_start_date,
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "detquantlib"
3
- version = "3.0.1"
3
+ version = "3.1.0"
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"
File without changes