kyoslib_py 4.0.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.
- kyoslib_py-4.0.1/LICENSE.txt +21 -0
- kyoslib_py-4.0.1/PKG-INFO +81 -0
- kyoslib_py-4.0.1/README.md +56 -0
- kyoslib_py-4.0.1/kyoslib_py/__init__.py +0 -0
- kyoslib_py-4.0.1/kyoslib_py/forward_curve.py +192 -0
- kyoslib_py-4.0.1/kyoslib_py/front_end.py +397 -0
- kyoslib_py-4.0.1/kyoslib_py/historical_price.py +535 -0
- kyoslib_py-4.0.1/kyoslib_py/kyos_api.py +95 -0
- kyoslib_py-4.0.1/kyoslib_py/kyos_utils.py +117 -0
- kyoslib_py-4.0.1/kyoslib_py/settings.py +1223 -0
- kyoslib_py-4.0.1/kyoslib_py/simulation.py +1890 -0
- kyoslib_py-4.0.1/kyoslib_py/tradable_product.py +471 -0
- kyoslib_py-4.0.1/kyoslib_py/valuation_interface.py +729 -0
- kyoslib_py-4.0.1/pyproject.toml +48 -0
- kyoslib_py-4.0.1/setup.py +39 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 KYOS Energy Analytics
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: kyoslib-py
|
|
3
|
+
Version: 4.0.1
|
|
4
|
+
Summary: KYOS shared lib code as python package
|
|
5
|
+
Home-page: http://github.com/kyosenergy/kyoslib_py
|
|
6
|
+
License: MIT
|
|
7
|
+
Author: KYOS
|
|
8
|
+
Author-email: support@kyos.com
|
|
9
|
+
Requires-Python: >=3.7,<3.10
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Requires-Dist: h5py (>=3.6.0,<4.0.0)
|
|
16
|
+
Requires-Dist: numba (==0.56.4)
|
|
17
|
+
Requires-Dist: numpy (<1.22.1)
|
|
18
|
+
Requires-Dist: pandas (<1.5.3)
|
|
19
|
+
Requires-Dist: plotly (>=5.7.0,<6.0.0)
|
|
20
|
+
Requires-Dist: requests (>=2.28.1,<3.0.0)
|
|
21
|
+
Project-URL: Documentation, https://kyosenergy.github.io/kyoslib_py/
|
|
22
|
+
Project-URL: Repository, http://github.com/kyosenergy/kyoslib_py
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# kyoslib_py
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
Example code:
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from kyoslib_py.simulation import Simulation
|
|
33
|
+
simulation_set = Simulation()
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```pip install kyoslib_py -extra-index-url https://pypi.fury.io/kyos/```
|
|
39
|
+
|
|
40
|
+
## Dependencies
|
|
41
|
+
|
|
42
|
+
Python 3.7+
|
|
43
|
+
|
|
44
|
+
## Development
|
|
45
|
+
|
|
46
|
+
This project is executing CI checks using **GitHub actions**.
|
|
47
|
+
|
|
48
|
+
It will run `pytest` and `black`.
|
|
49
|
+
|
|
50
|
+
### Invoking development tasks
|
|
51
|
+
|
|
52
|
+
[Invoke](https://www.pyinvoke.org/) is used for development tasks.
|
|
53
|
+
|
|
54
|
+
Tasks are stored in `tasks.py` and are executable using the `inv[oke]` command line tool.
|
|
55
|
+
|
|
56
|
+
To see the list of tasks, you can type:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
inv --list
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
For example, before your commits, you should run
|
|
63
|
+
```bash
|
|
64
|
+
inv format
|
|
65
|
+
```
|
|
66
|
+
to format your code.
|
|
67
|
+
|
|
68
|
+
## Documentation
|
|
69
|
+
|
|
70
|
+
The package documentation is generated by MkDocs. The correct version can be installed in the project's virtual environment by:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
poetry install
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Then the documentation can be built, and a server to view it started by:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
mkdocs serve
|
|
80
|
+
```
|
|
81
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# kyoslib_py
|
|
2
|
+
|
|
3
|
+
## Usage
|
|
4
|
+
|
|
5
|
+
Example code:
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from kyoslib_py.simulation import Simulation
|
|
9
|
+
simulation_set = Simulation()
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```pip install kyoslib_py -extra-index-url https://pypi.fury.io/kyos/```
|
|
15
|
+
|
|
16
|
+
## Dependencies
|
|
17
|
+
|
|
18
|
+
Python 3.7+
|
|
19
|
+
|
|
20
|
+
## Development
|
|
21
|
+
|
|
22
|
+
This project is executing CI checks using **GitHub actions**.
|
|
23
|
+
|
|
24
|
+
It will run `pytest` and `black`.
|
|
25
|
+
|
|
26
|
+
### Invoking development tasks
|
|
27
|
+
|
|
28
|
+
[Invoke](https://www.pyinvoke.org/) is used for development tasks.
|
|
29
|
+
|
|
30
|
+
Tasks are stored in `tasks.py` and are executable using the `inv[oke]` command line tool.
|
|
31
|
+
|
|
32
|
+
To see the list of tasks, you can type:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
inv --list
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For example, before your commits, you should run
|
|
39
|
+
```bash
|
|
40
|
+
inv format
|
|
41
|
+
```
|
|
42
|
+
to format your code.
|
|
43
|
+
|
|
44
|
+
## Documentation
|
|
45
|
+
|
|
46
|
+
The package documentation is generated by MkDocs. The correct version can be installed in the project's virtual environment by:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
poetry install
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Then the documentation can be built, and a server to view it started by:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
mkdocs serve
|
|
56
|
+
```
|
|
File without changes
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import pandas as pd
|
|
4
|
+
|
|
5
|
+
from kyoslib_py.kyos_api import call_kyos_api_v1
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def write_curve_to_csv(curves, delTypes, grID, fullFileName):
|
|
9
|
+
"""Stores the forward curves in generalized data format on the disk in ./ForwardCurves directory
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
curves (dict): HTTP response body which provided by kyos_api.call_kyos_api_v1
|
|
13
|
+
delTypes (list): baseload:1, peak:2, offpeak:3
|
|
14
|
+
grID (int): granularity id of the requested forward curve(e.g. half-hour:1, hour:2, day:3, month:5)
|
|
15
|
+
fullFileName (str): full path of the file(e.g. "./ForwardCurves/ForwardCurveDaily_2_20200101")
|
|
16
|
+
|
|
17
|
+
Note:
|
|
18
|
+
The current implementation allows to store only data based on monthly granularity.
|
|
19
|
+
|
|
20
|
+
Example:
|
|
21
|
+
>>> from kyoslib_py.forward_curve import write_curve_to_csv
|
|
22
|
+
>>> curves = {}
|
|
23
|
+
>>> data = {}
|
|
24
|
+
>>> month = {}
|
|
25
|
+
>>> baseload = [{'date':'2020-01-01', 'value':20.2}, {'date':'2020-02-01', 'value':30.3}]
|
|
26
|
+
>>> month['baseload'] = baseload
|
|
27
|
+
>>> data['month'] = month
|
|
28
|
+
>>> curves['data'] = data
|
|
29
|
+
>>> write_curve_to_csv(curves, [1, 2, 3], 5, "./ForwardCurves/ForwardCurveMonthlyDeliveryTypes_2_20200101")
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
if grID == 1: # half-hourly
|
|
33
|
+
return
|
|
34
|
+
elif grID == 2: # hourly
|
|
35
|
+
return
|
|
36
|
+
elif grID == 3: # daily
|
|
37
|
+
return
|
|
38
|
+
elif grID == 5: # monthly
|
|
39
|
+
curves_df = pd.DataFrame()
|
|
40
|
+
numDelType = len(delTypes)
|
|
41
|
+
# read dates from base load and store in the table, column name should be "0" for the date column
|
|
42
|
+
curves_df['0'] = [x['date'] for x in curves['data']['month']['baseload']]
|
|
43
|
+
|
|
44
|
+
for i in range(numDelType):
|
|
45
|
+
|
|
46
|
+
if delTypes[i] == 1:
|
|
47
|
+
curves_df[str(delTypes[i])] = [
|
|
48
|
+
x['value'] for x in curves['data']['month']['baseload']
|
|
49
|
+
]
|
|
50
|
+
elif delTypes[i] == 2:
|
|
51
|
+
curves_df[str(delTypes[i])] = [
|
|
52
|
+
x['value'] for x in curves['data']['month']['peakload']
|
|
53
|
+
]
|
|
54
|
+
elif delTypes[i] == 3:
|
|
55
|
+
curves_df[str(delTypes[i])] = [
|
|
56
|
+
x['value'] for x in curves['data']['month']['offpeak']
|
|
57
|
+
]
|
|
58
|
+
# write monthly curves to csv
|
|
59
|
+
curves_df.to_csv(fullFileName, index=False)
|
|
60
|
+
return
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def get_curve_api(fwdCurveID, granularityID, deliveryTypes, tradingDates, isCSVWrite):
|
|
64
|
+
"""Performs API requests to KYOS API and stores the curve inputs in a generalized format in CSV files or
|
|
65
|
+
returns a pandas.DataFrame
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
fwdCurveID (int): id of the curve profile
|
|
69
|
+
granularityID (int): half-hour:1, hour:2, day:3, month:5
|
|
70
|
+
deliveryTypes (list or int): list of delivery type ids(int array), base load:1, peak:2, off-peak:3
|
|
71
|
+
tradingDates (list): list of trading dates(string array) e.g. ['2019-01-01', '2019-01-02', '2019-01-03']
|
|
72
|
+
isCSVWrite (bool): indicator of creating csv files, 0 or 1, we will provide a DataFrame in case of zero.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
(pandas.DataFrame): Contains all requested curves. If isCSVWrite equals 1 then the dataframe will be empty and
|
|
76
|
+
the curves will be saved as CSV files on the disk in directory ./ForwardCurves.
|
|
77
|
+
|
|
78
|
+
Note:
|
|
79
|
+
The current implementation allows to read only data based on monthly granularity.
|
|
80
|
+
KYOS API provides the curves with the daylight saving switches for the half-hourly and hourly curves.
|
|
81
|
+
KYOS API supports base load, peak and off-peak delivery types.
|
|
82
|
+
|
|
83
|
+
Example:
|
|
84
|
+
>>> from kyoslib_py.forward_curve import get_curve_api
|
|
85
|
+
>>> arg = {'fwdCurveID': 4, 'granularityID': 5, 'deliveryTypes': [1, 2, 3],
|
|
86
|
+
>>> 'tradingDates': ['2019-01-01', '2019-01-02'], 'isCSVWrite': 1}
|
|
87
|
+
>>> curves_df = get_curve_api(**arg)
|
|
88
|
+
>>> arg = {'fwdCurveID': 4, 'granularityID': 5, 'deliveryTypes': 1 ,
|
|
89
|
+
>>> 'tradingDates': '2019-01-01', 'isCSVWrite': 1}
|
|
90
|
+
>>> curves_df2 = get_curve_api(**arg)
|
|
91
|
+
"""
|
|
92
|
+
# Initialize output directory
|
|
93
|
+
curDir = os.getcwd()
|
|
94
|
+
outputDir = os.path.join(curDir, 'ForwardCurves')
|
|
95
|
+
if isCSVWrite and (not os.path.exists(outputDir)):
|
|
96
|
+
os.mkdir(outputDir)
|
|
97
|
+
forward_curves_df = pd.DataFrame()
|
|
98
|
+
# ################################################# INPUT VALIDATION ###########################################
|
|
99
|
+
# Check the granularity input
|
|
100
|
+
if granularityID == 1:
|
|
101
|
+
fileName = f"ForwardCurveHalfHourlyDST_{fwdCurveID}_"
|
|
102
|
+
granularity = 'half_hour'
|
|
103
|
+
print('The function does not support reading of the ' + granularity + ' curves !!!')
|
|
104
|
+
return forward_curves_df
|
|
105
|
+
elif granularityID == 2:
|
|
106
|
+
fileName = f"ForwardCurveHourlyDST_{fwdCurveID}_"
|
|
107
|
+
granularity = 'hour'
|
|
108
|
+
print('The function does not support reading of the ' + granularity + ' curves !!!')
|
|
109
|
+
return forward_curves_df
|
|
110
|
+
elif granularityID == 3:
|
|
111
|
+
fileName = f"ForwardCurveDaily_{fwdCurveID}_"
|
|
112
|
+
granularity = 'day'
|
|
113
|
+
print('The function does not support reading of the ' + granularity + ' curves !!!')
|
|
114
|
+
return forward_curves_df
|
|
115
|
+
elif granularityID == 5:
|
|
116
|
+
fileName = f"ForwardCurveMonthlyDeliveryTypes_{fwdCurveID}_"
|
|
117
|
+
granularity = 'month'
|
|
118
|
+
else:
|
|
119
|
+
print('The granularity id:' + str(granularityID) + ' is not supported in KYOS API!!!')
|
|
120
|
+
return forward_curves_df
|
|
121
|
+
# in case of empty delivery type after the cleaning process, initialize base load in the list
|
|
122
|
+
if deliveryTypes is None:
|
|
123
|
+
deliveryTypes = [1]
|
|
124
|
+
|
|
125
|
+
# Check the delivery type input, deliveryTypes should be a list
|
|
126
|
+
if type(deliveryTypes) != list:
|
|
127
|
+
deliveryTypes = [deliveryTypes]
|
|
128
|
+
if len(deliveryTypes) == 0:
|
|
129
|
+
deliveryTypes.append(1) # in case of empty delivery type list, import the base load curve
|
|
130
|
+
else:
|
|
131
|
+
# remove the unsupported delivery types from the list
|
|
132
|
+
deliveryTypes = [
|
|
133
|
+
deliveryTypes for deliveryTypes in deliveryTypes if deliveryTypes in [1, 2, 3]
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
# Check tradingDates, it should be provided as a list
|
|
137
|
+
if type(tradingDates) != list:
|
|
138
|
+
tradingDates = [tradingDates]
|
|
139
|
+
|
|
140
|
+
# ########################################### IMPORT CURVES #######################################################
|
|
141
|
+
numTradDays = tradingDates.__len__()
|
|
142
|
+
for i in range(numTradDays):
|
|
143
|
+
tradingDate_i = tradingDates[i]
|
|
144
|
+
query = f"/curves/results/{fwdCurveID}/{tradingDate_i}?filter[granularity]={granularity}"
|
|
145
|
+
|
|
146
|
+
status, data = call_kyos_api_v1(query)
|
|
147
|
+
if 200 >= status < 300:
|
|
148
|
+
print(query + ' Imported!')
|
|
149
|
+
if isCSVWrite == 1: # in this case, we will store the curves on disk per trading dates
|
|
150
|
+
fullName = os.path.join(
|
|
151
|
+
outputDir, f"{fileName}{tradingDate_i.replace('-', '')}.csv"
|
|
152
|
+
)
|
|
153
|
+
write_curve_to_csv(data, deliveryTypes, granularityID, fullName)
|
|
154
|
+
else: # in this case, we will store the curves in a dataframe
|
|
155
|
+
if granularityID == 1: # half-hourly
|
|
156
|
+
return
|
|
157
|
+
elif granularityID == 2: # hourly
|
|
158
|
+
return
|
|
159
|
+
elif granularityID == 3: # daily
|
|
160
|
+
return
|
|
161
|
+
elif granularityID == 5: # monthly
|
|
162
|
+
curves_df_i = pd.DataFrame()
|
|
163
|
+
numDelType = len(deliveryTypes)
|
|
164
|
+
# update curve id and trading dates column
|
|
165
|
+
numMonths = data['data']['month']['baseload'].__len__()
|
|
166
|
+
curves_df_i['curve_id'] = [fwdCurveID for _ in range(numMonths)]
|
|
167
|
+
curves_df_i['trading_dates'] = [tradingDate_i for _ in range(numMonths)]
|
|
168
|
+
|
|
169
|
+
# read dates from base load and store in the table as delivery dates
|
|
170
|
+
curves_df_i['delivery_dates'] = [
|
|
171
|
+
x['date'] for x in data['data']['month']['baseload']
|
|
172
|
+
]
|
|
173
|
+
for i in range(numDelType):
|
|
174
|
+
|
|
175
|
+
if deliveryTypes[i] == 1:
|
|
176
|
+
curves_df_i['baseload'] = [
|
|
177
|
+
x['value'] for x in data['data']['month']['baseload']
|
|
178
|
+
]
|
|
179
|
+
elif deliveryTypes[i] == 2:
|
|
180
|
+
curves_df_i['peak'] = [
|
|
181
|
+
x['value'] for x in data['data']['month']['peakload']
|
|
182
|
+
]
|
|
183
|
+
elif deliveryTypes[i] == 3:
|
|
184
|
+
curves_df_i['offpeak'] = [
|
|
185
|
+
x['value'] for x in data['data']['month']['offpeak']
|
|
186
|
+
]
|
|
187
|
+
|
|
188
|
+
forward_curves_df = pd.concat([forward_curves_df, curves_df_i])
|
|
189
|
+
else:
|
|
190
|
+
print(query + ' could not be imported!')
|
|
191
|
+
|
|
192
|
+
return forward_curves_df
|