detquantlib 2.0.4__py3-none-any.whl
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/__init__.py +1 -0
- detquantlib/data/databases/detdatabase.py +535 -0
- detquantlib/data/entsoe/entsoe.py +174 -0
- detquantlib/data/sftp/sftp.py +89 -0
- detquantlib/dates/dates.py +154 -0
- detquantlib/figures/plotly_figures.py +82 -0
- detquantlib/stats/data_analysis.py +143 -0
- detquantlib/tradable_products/tradable_products.py +117 -0
- detquantlib/utils/utils.py +11 -0
- detquantlib-2.0.4.dist-info/LICENSE.txt +3 -0
- detquantlib-2.0.4.dist-info/METADATA +153 -0
- detquantlib-2.0.4.dist-info/RECORD +13 -0
- detquantlib-2.0.4.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Python built-in packages
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
# Third-party packages
|
|
6
|
+
import pandas as pd
|
|
7
|
+
from dateutil.relativedelta import *
|
|
8
|
+
|
|
9
|
+
# Internal modules
|
|
10
|
+
from detquantlib.dates.dates import calc_months_diff
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def convert_delivery_start_date_to_maturity(
|
|
14
|
+
trading_date: datetime,
|
|
15
|
+
delivery_start_date: datetime,
|
|
16
|
+
product: Literal["month", "quarter", "year"],
|
|
17
|
+
) -> int:
|
|
18
|
+
"""
|
|
19
|
+
Calculates the number of maturities between the input trading date and the input delivery
|
|
20
|
+
date, based on the input product type.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
trading_date: Trading date
|
|
24
|
+
delivery_start_date: Delivery start date
|
|
25
|
+
product: Product type (e.g. "month", "quarter", "year")
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
Product maturity
|
|
29
|
+
|
|
30
|
+
Raises:
|
|
31
|
+
ValueError: Raises an error when the delivery start date is older than the trading date
|
|
32
|
+
ValueError: Raises an error when the input product type is not recognized
|
|
33
|
+
"""
|
|
34
|
+
# Make input product string lower case only
|
|
35
|
+
product = product.lower()
|
|
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
|
+
if product == "month":
|
|
45
|
+
maturity = calc_months_diff(
|
|
46
|
+
start_date=trading_date,
|
|
47
|
+
end_date=delivery_start_date,
|
|
48
|
+
diff_method="month",
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
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))
|
|
55
|
+
|
|
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))
|
|
59
|
+
|
|
60
|
+
months_diff = calc_months_diff(
|
|
61
|
+
start_date=trading_quarter_start_date,
|
|
62
|
+
end_date=delivery_quarter_start_date,
|
|
63
|
+
diff_method="month",
|
|
64
|
+
)
|
|
65
|
+
maturity = months_diff / 3
|
|
66
|
+
|
|
67
|
+
elif product == "year":
|
|
68
|
+
maturity = delivery_start_date.year - trading_date.year
|
|
69
|
+
|
|
70
|
+
else:
|
|
71
|
+
raise ValueError("Invalid input product name.")
|
|
72
|
+
|
|
73
|
+
return maturity
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def convert_maturity_to_delivery_start_date(
|
|
77
|
+
trading_date: datetime,
|
|
78
|
+
maturity: int,
|
|
79
|
+
product: Literal["month", "quarter", "year"],
|
|
80
|
+
) -> datetime:
|
|
81
|
+
"""
|
|
82
|
+
Calculates the delivery start date of the input product, based on the input trading date
|
|
83
|
+
and input maturity.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
trading_date: Trading date
|
|
87
|
+
maturity: Product maturity
|
|
88
|
+
product: Product type (e.g. "month", "quarter", "year")
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
Delivery start date
|
|
92
|
+
|
|
93
|
+
Raises:
|
|
94
|
+
ValueError: Raises an error when the input product type is not recognized
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
# Make input product string lower case only
|
|
98
|
+
product = product.lower()
|
|
99
|
+
|
|
100
|
+
if product == "month":
|
|
101
|
+
month_start_date = datetime(trading_date.year, trading_date.month, 1)
|
|
102
|
+
delivery_start_date = month_start_date + relativedelta(months=maturity)
|
|
103
|
+
|
|
104
|
+
elif product == "quarter":
|
|
105
|
+
quarter = pd.Timestamp(trading_date).quarter
|
|
106
|
+
year_start_date = datetime(trading_date.year, 1, 1)
|
|
107
|
+
quarter_start_date = year_start_date + relativedelta(months=((quarter - 1) * 3))
|
|
108
|
+
delivery_start_date = quarter_start_date + relativedelta(months=(maturity * 3))
|
|
109
|
+
|
|
110
|
+
elif product == "year":
|
|
111
|
+
year_start_date = datetime(trading_date.year, 1, 1)
|
|
112
|
+
delivery_start_date = year_start_date + relativedelta(years=maturity)
|
|
113
|
+
|
|
114
|
+
else:
|
|
115
|
+
raise ValueError("Invalid input product name.")
|
|
116
|
+
|
|
117
|
+
return delivery_start_date
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def add_log(message: str):
|
|
5
|
+
"""
|
|
6
|
+
Short helper function to print log messages, including time stamps.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
message: Message to be printed
|
|
10
|
+
"""
|
|
11
|
+
print(f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] {message}")
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: detquantlib
|
|
3
|
+
Version: 2.0.4
|
|
4
|
+
Summary: An internal library containing functions and classes that can be used across Quant models.
|
|
5
|
+
Author: DET
|
|
6
|
+
Requires-Python: >=3.10,<4.0
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Requires-Dist: numpy (>=2.2.4,<3.0.0)
|
|
13
|
+
Requires-Dist: pandas (>=2.2.3,<3.0.0)
|
|
14
|
+
Requires-Dist: paramiko (>=3.5.1,<4.0.0)
|
|
15
|
+
Requires-Dist: plotly (>=6.0.1,<7.0.0)
|
|
16
|
+
Requires-Dist: pyodbc (>=5.2.0,<6.0.0)
|
|
17
|
+
Project-URL: Repository, https://github.com/Dynamic-Energy-Trading/detquantlib
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# DET Quant Library
|
|
21
|
+
|
|
22
|
+
The DET Quant Library is an internal library containing functions and classes that can be used
|
|
23
|
+
across Quant models.
|
|
24
|
+
|
|
25
|
+
## Instructions
|
|
26
|
+
|
|
27
|
+
#### Version control
|
|
28
|
+
|
|
29
|
+
- This repository contains a version control workflow.
|
|
30
|
+
- The version number is specified via the `version` field in the pyproject.toml file.
|
|
31
|
+
- The version number needs to be updated with every new master commit. If the version is not
|
|
32
|
+
updated, the GitHub workflow will fail.
|
|
33
|
+
- Version numbers should follow semantic versioning (i.e. `X.Y.Z`). That is:
|
|
34
|
+
- `X` increments represent major, non-backward compatible updates.
|
|
35
|
+
- `Y` increments represent minor, backward compatible functionality updates.
|
|
36
|
+
- `Z` increments represent patch/bugfix, backward compatible updates.
|
|
37
|
+
|
|
38
|
+
#### Release notes
|
|
39
|
+
|
|
40
|
+
- When deemed necessary (especially in case of major updates), developers can document code
|
|
41
|
+
changes in dedicated GitHub release notes.
|
|
42
|
+
- Release notes can be created via
|
|
43
|
+
<https://github.com/Dynamic-Energy-Trading/detquantlib/releases.>
|
|
44
|
+
- In any case, all codes changes should always be properly described/documented in GitHub
|
|
45
|
+
issues and/or pull requests.
|
|
46
|
+
|
|
47
|
+
#### Installing the `detquantlib` package in other Python projects
|
|
48
|
+
|
|
49
|
+
To install the library in another project, use the following poetry command:
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
poetry add git+https://github.com/Dynamic-Energy-Trading/detquantlib.git@vX.Y.Z
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
where `vX.Y.Z` should be replaced with the relevant version (e.g. `v1.2.3`).
|
|
56
|
+
|
|
57
|
+
## Development settings
|
|
58
|
+
|
|
59
|
+
### Dependency management
|
|
60
|
+
|
|
61
|
+
Project dependencies are managed by [Poetry](https://python-poetry.org/).
|
|
62
|
+
|
|
63
|
+
The project follows the standard Poetry structure:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
poetrytemplate
|
|
67
|
+
├── pyproject.toml
|
|
68
|
+
├── README.md
|
|
69
|
+
├── src
|
|
70
|
+
│ └── __init__.py
|
|
71
|
+
└── tests
|
|
72
|
+
└── __init__.py
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Dependency updates
|
|
76
|
+
|
|
77
|
+
This project is executing automated dependency updates using
|
|
78
|
+
[Dependabot with GitHub actions](https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions).
|
|
79
|
+
|
|
80
|
+
### Invoke development tasks
|
|
81
|
+
|
|
82
|
+
Development tasks are defined with the [Invoke](https://www.pyinvoke.org/) package.
|
|
83
|
+
|
|
84
|
+
#### What is Invoke?
|
|
85
|
+
|
|
86
|
+
Invoke provides a clean, high level API for running shell commands and defining/organizing task
|
|
87
|
+
functions from a tasks.py file.
|
|
88
|
+
|
|
89
|
+
#### How to run development tasks?
|
|
90
|
+
|
|
91
|
+
Development tasks can be executed directly from the terminal, using the `inv` (or `invoke`)
|
|
92
|
+
command line tool.
|
|
93
|
+
|
|
94
|
+
For guidance on the available Invoke development tasks, execute the following command in the
|
|
95
|
+
terminal:
|
|
96
|
+
|
|
97
|
+
```cmd
|
|
98
|
+
inv --list
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Use the `-h` (or `--help`) argument for help about a particular development task. For example:
|
|
102
|
+
|
|
103
|
+
```cmd
|
|
104
|
+
inv lint -h
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### CI/CD process
|
|
108
|
+
|
|
109
|
+
This project is executing CI checks using [GitHub actions](https://docs.github.com/en/actions)
|
|
110
|
+
workflows.
|
|
111
|
+
|
|
112
|
+
The GitHub workflow defined in this project was inspired by the following preconfigured templates:
|
|
113
|
+
|
|
114
|
+
- [Python package](https://github.com/actions/starter-workflows/blob/main/ci/python-package.yml):
|
|
115
|
+
A general workflow template for Python packages.
|
|
116
|
+
- [Poetry action](https://github.com/marketplace/actions/install-poetry-action): A GitHub action
|
|
117
|
+
for installing and configuring Poetry.
|
|
118
|
+
|
|
119
|
+
#### CI check: Testing
|
|
120
|
+
|
|
121
|
+
Code changes are tested with the [Pytest](https://github.com/pytest-dev/pytest) package.
|
|
122
|
+
|
|
123
|
+
The CI check is executed with the following the development task:
|
|
124
|
+
|
|
125
|
+
```cmd
|
|
126
|
+
inv test -c
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
#### CI check: Code formatting
|
|
130
|
+
|
|
131
|
+
Linters are used to check that the code is properly formatted:
|
|
132
|
+
|
|
133
|
+
- [Isort](https://github.com/timothycrosley/isort) for the imports section
|
|
134
|
+
- [Darglint](https://github.com/terrencepreilly/darglint) for the docstrings description
|
|
135
|
+
- [Black](https://github.com/psf/black) for the main code
|
|
136
|
+
- [Pymarkdown](https://github.com/jackdewinter/pymarkdown) for the markdown file README.md
|
|
137
|
+
|
|
138
|
+
The CI check is executed with the following development task:
|
|
139
|
+
|
|
140
|
+
```cmd
|
|
141
|
+
inv lint -c
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
If the CI check fails, execute the following command in the terminal:
|
|
145
|
+
|
|
146
|
+
```cmd
|
|
147
|
+
inv lint
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
This command fixes the parts of the code that should be reformatted. Adding the `-c` (or
|
|
151
|
+
`--check`) optional argument instructs the command to only _check_ if parts of the code should be
|
|
152
|
+
reformatted, without applying any actual changes.
|
|
153
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
detquantlib/__init__.py,sha256=dH46j7JDxM1CmQCEBY5Ghggv-vir43Cx9iiTf0ETx4I,48
|
|
2
|
+
detquantlib/data/databases/detdatabase.py,sha256=SmfFe7UjY0O_tv_rWJR99CyxGmJjgsmwL1ipu9ulVeQ,20322
|
|
3
|
+
detquantlib/data/entsoe/entsoe.py,sha256=NCoXcWSJe_IFovbtHFWtX8KSQHerzP5OQ1bq36TjIiA,6445
|
|
4
|
+
detquantlib/data/sftp/sftp.py,sha256=SZbW0GY3JQF1iW-brDWdt7j263YdSWFHdw8PENaWF-g,3100
|
|
5
|
+
detquantlib/dates/dates.py,sha256=1mfwVVlIJizRXUeKmFqXdufqnq-ypUJxDwIcsb0Dbd0,6394
|
|
6
|
+
detquantlib/figures/plotly_figures.py,sha256=UaZa_OjijHa2zrZ9Nh8q55dxWzbbYUSZPug5TH1CECs,2295
|
|
7
|
+
detquantlib/stats/data_analysis.py,sha256=bax_HDoKUQs5oESdYfmhJq1PlaZ_mrXtp1KB4zTS9o0,5465
|
|
8
|
+
detquantlib/tradable_products/tradable_products.py,sha256=BIqKdl0HKm4g2ztcUJXwm80wWkpPlGnrB_MIS_ONEng,3738
|
|
9
|
+
detquantlib/utils/utils.py,sha256=1Bok0osgKIzOU2J4T8VQ5mg9-COg9oBj0mLUEMmuM7U,270
|
|
10
|
+
detquantlib-2.0.4.dist-info/LICENSE.txt,sha256=uiy4xTg4EJIOVOoGJbh8FakJJjqxRlTuctKpPz9WP2g,246
|
|
11
|
+
detquantlib-2.0.4.dist-info/METADATA,sha256=pRzZbPabQvBV5gu7rGFRvwsCePFWCVyJ7weg_JbKycs,4988
|
|
12
|
+
detquantlib-2.0.4.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
13
|
+
detquantlib-2.0.4.dist-info/RECORD,,
|