openseries 1.8.3__tar.gz → 1.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.
- {openseries-1.8.3 → openseries-1.9.0}/PKG-INFO +46 -73
- {openseries-1.8.3 → openseries-1.9.0}/README.md +43 -70
- {openseries-1.8.3 → openseries-1.9.0}/openseries/__init__.py +10 -1
- {openseries-1.8.3 → openseries-1.9.0}/openseries/_common_model.py +55 -5
- {openseries-1.8.3 → openseries-1.9.0}/openseries/_risk.py +8 -1
- {openseries-1.8.3 → openseries-1.9.0}/openseries/datefixer.py +127 -33
- {openseries-1.8.3 → openseries-1.9.0}/openseries/frame.py +10 -7
- {openseries-1.8.3 → openseries-1.9.0}/openseries/load_plotly.py +8 -1
- {openseries-1.8.3 → openseries-1.9.0}/openseries/owntypes.py +12 -11
- {openseries-1.8.3 → openseries-1.9.0}/openseries/portfoliotools.py +8 -1
- openseries-1.9.0/openseries/report.py +479 -0
- {openseries-1.8.3 → openseries-1.9.0}/openseries/series.py +32 -1
- {openseries-1.8.3 → openseries-1.9.0}/openseries/simulation.py +12 -1
- {openseries-1.8.3 → openseries-1.9.0}/pyproject.toml +8 -12
- {openseries-1.8.3 → openseries-1.9.0}/LICENSE.md +0 -0
- {openseries-1.8.3 → openseries-1.9.0}/openseries/plotly_captor_logo.json +0 -0
- {openseries-1.8.3 → openseries-1.9.0}/openseries/plotly_layouts.json +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: openseries
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.9.0
|
4
4
|
Summary: Tools for analyzing financial timeseries.
|
5
5
|
License: # BSD 3-Clause License
|
6
6
|
|
@@ -46,12 +46,12 @@ Classifier: Natural Language :: English
|
|
46
46
|
Classifier: Development Status :: 5 - Production/Stable
|
47
47
|
Classifier: Operating System :: OS Independent
|
48
48
|
Classifier: Framework :: Pydantic
|
49
|
+
Requires-Dist: exchange-calendars (>=4.10.1,<6.0)
|
49
50
|
Requires-Dist: holidays (>=0.30,<1.0)
|
50
|
-
Requires-Dist: numpy (>=1.23.2,<3.0.0)
|
51
|
+
Requires-Dist: numpy (>=1.23.2,!=2.3.0,<3.0.0)
|
51
52
|
Requires-Dist: openpyxl (>=3.1.2,<5.0.0)
|
52
53
|
Requires-Dist: pandas (>=2.1.2,<3.0.0)
|
53
54
|
Requires-Dist: plotly (>=5.18.0,<7.0.0)
|
54
|
-
Requires-Dist: pyarrow (>=14.0.2,<21.0.0)
|
55
55
|
Requires-Dist: pydantic (>=2.5.2,<3.0.0)
|
56
56
|
Requires-Dist: python-dateutil (>=2.8.2,<4.0.0)
|
57
57
|
Requires-Dist: requests (>=2.20.0,<3.0.0)
|
@@ -74,7 +74,7 @@ Description-Content-Type: text/markdown
|
|
74
74
|

|
75
75
|
[](https://www.python.org/)
|
76
76
|
[](https://github.com/CaptorAB/openseries/actions/workflows/test.yml)
|
77
|
-
[](https://codecov.io/gh/CaptorAB/openseries)
|
78
78
|
[](https://python-poetry.org/)
|
79
79
|
[](https://beta.ruff.rs/docs/)
|
80
80
|
[](https://github.com/CaptorAB/openseries/blob/master/LICENSE.md)
|
@@ -83,7 +83,6 @@ Description-Content-Type: text/markdown
|
|
83
83
|
This is a project with tools to analyze financial timeseries of a single
|
84
84
|
asset or a group of assets. It is solely made for daily or less frequent data.
|
85
85
|
|
86
|
-
|
87
86
|
## Basic Usage
|
88
87
|
|
89
88
|
To install:
|
@@ -118,34 +117,9 @@ _,_=series.plot_series()
|
|
118
117
|
|
119
118
|
```
|
120
119
|
|
121
|
-
### Sample output using the
|
122
|
-
|
123
|
-
|
124
|
-
ValueType.PRICE ValueType.PRICE
|
125
|
-
Total return 3.641282 1.946319
|
126
|
-
Arithmetic return 0.096271 0.069636
|
127
|
-
Geometric return 0.093057 0.06464
|
128
|
-
Volatility 0.120279 0.117866
|
129
|
-
Return vol ratio 0.800396 0.59081
|
130
|
-
Downside deviation 0.085956 0.086723
|
131
|
-
Sortino ratio 1.119993 0.802975
|
132
|
-
Positive share 0.541783 0.551996
|
133
|
-
Worst -0.071616 -0.089415
|
134
|
-
Worst month -0.122503 -0.154485
|
135
|
-
Max drawdown -0.309849 -0.435444
|
136
|
-
Max drawdown in cal yr -0.309849 -0.348681
|
137
|
-
Max drawdown dates 2020-03-23 2009-03-09
|
138
|
-
CVaR 95.0% -0.01793 -0.018429
|
139
|
-
VaR 95.0% -0.011365 -0.010807
|
140
|
-
Imp vol from VaR 95% 0.109204 0.103834
|
141
|
-
Z-score 0.587905 0.103241
|
142
|
-
Skew -0.650782 -0.888109
|
143
|
-
Kurtosis 8.511166 17.527367
|
144
|
-
observations 4309 4309
|
145
|
-
span of days 6301 6301
|
146
|
-
first indices 2006-01-03 2006-01-03
|
147
|
-
last indices 2023-04-05 2023-04-05
|
148
|
-
```
|
120
|
+
### Sample output using the report_html() function:
|
121
|
+
|
122
|
+
<img src="./captor_plot_image.png" alt="Two Assets Compared" width="1000" />
|
149
123
|
|
150
124
|
## Development Instructions
|
151
125
|
|
@@ -156,7 +130,6 @@ The OpenTimeSeries and OpenFrame classes are both subclasses of
|
|
156
130
|
the [Pydantic BaseModel](https://docs.pydantic.dev/usage/models/). Please refer to its documentation for information
|
157
131
|
on any attributes or methods inherited from this model.
|
158
132
|
|
159
|
-
|
160
133
|
### Windows Powershell
|
161
134
|
|
162
135
|
```powershell
|
@@ -171,9 +144,8 @@ cd openseries
|
|
171
144
|
```bash
|
172
145
|
git clone https://github.com/CaptorAB/openseries.git
|
173
146
|
cd openseries
|
174
|
-
make
|
175
|
-
source source_me
|
176
147
|
make install
|
148
|
+
source source_me
|
177
149
|
|
178
150
|
```
|
179
151
|
|
@@ -202,7 +174,6 @@ make lint
|
|
202
174
|
|
203
175
|
```
|
204
176
|
|
205
|
-
|
206
177
|
## Table of Contents
|
207
178
|
|
208
179
|
- [Basic Usage](#basic-usage)
|
@@ -221,12 +192,13 @@ make lint
|
|
221
192
|
|
222
193
|
### On some files in the project
|
223
194
|
|
224
|
-
| File | Description
|
225
|
-
|
226
|
-
| [series.py](https://github.com/CaptorAB/openseries/blob/master/openseries/series.py) | Defines the class _OpenTimeSeries_ for managing and analyzing a single timeseries. The module also defines a function `timeseries_chain` that can be used to chain two timeseries objects together.
|
227
|
-
| [frame.py](https://github.com/CaptorAB/openseries/blob/master/openseries/frame.py) | Defines the class _OpenFrame_ for managing a group of timeseries, and e.g. calculate a portfolio timeseries from a rebalancing strategy between timeseries.
|
228
|
-
| [portfoliotools.py](https://github.com/CaptorAB/openseries/blob/master/openseries/portfoliotools.py) | Defines functions to simulate, optimize, and plot portfolios.
|
229
|
-
| [
|
195
|
+
| File | Description |
|
196
|
+
|:-----------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
197
|
+
| [series.py](https://github.com/CaptorAB/openseries/blob/master/openseries/series.py) | Defines the class _OpenTimeSeries_ for managing and analyzing a single timeseries. The module also defines a function `timeseries_chain` that can be used to chain two timeseries objects together. |
|
198
|
+
| [frame.py](https://github.com/CaptorAB/openseries/blob/master/openseries/frame.py) | Defines the class _OpenFrame_ for managing a group of timeseries, and e.g. calculate a portfolio timeseries from a rebalancing strategy between timeseries. |
|
199
|
+
| [portfoliotools.py](https://github.com/CaptorAB/openseries/blob/master/openseries/portfoliotools.py) | Defines functions to simulate, optimize, and plot portfolios. |
|
200
|
+
| [report.py](https://github.com/CaptorAB/openseries/blob/master/openseries/report.py) | Defines the _report_html_ function that is used to create a landscape orientation report on at least two assets. All preceding assets will be measured against the last asset in the input OpenFrame. |
|
201
|
+
| [simulation.py](https://github.com/CaptorAB/openseries/blob/master/openseries/simulation.py) | Defines the class _ReturnSimulation_ to create simulated financial timeseries. Used in the project's test suite |
|
230
202
|
|
231
203
|
### Class methods used to construct objects.
|
232
204
|
|
@@ -239,34 +211,35 @@ make lint
|
|
239
211
|
|
240
212
|
### Non-numerical or "helper" properties that apply only to the [OpenTimeSeries](https://github.com/CaptorAB/openseries/blob/master/openseries/series.py) class.
|
241
213
|
|
242
|
-
| Property | type
|
243
|
-
|
244
|
-
| `timeseries_id` | `str`
|
245
|
-
| `instrument_id` | `str`
|
246
|
-
| `dates` | `list[str]`
|
247
|
-
| `values` | `list[float]`
|
248
|
-
| `currency` | `str`
|
249
|
-
| `domestic` | `str`
|
250
|
-
| `local_ccy` | `bool`
|
251
|
-
| `name` | `str`
|
252
|
-
| `isin` | `str`
|
253
|
-
| `label` | `str`
|
254
|
-
| `countries` | `list` or `str` | `OpenTimeSeries` | (List of) country code(s) according to ISO 3166-1 alpha-2 used to generate business days.
|
255
|
-
| `
|
214
|
+
| Property | type | Applies to | Description |
|
215
|
+
|:----------------|:---------------------|:-----------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
216
|
+
| `timeseries_id` | `str` | `OpenTimeSeries` | Placeholder for database identifier for the timeseries. Can be left as empty string. |
|
217
|
+
| `instrument_id` | `str` | `OpenTimeSeries` | Placeholder for database identifier for the instrument associated with the timeseries. Can be left as empty string. |
|
218
|
+
| `dates` | `list[str]` | `OpenTimeSeries` | Dates of the timeseries. Not edited by any method to allow reversion to original. |
|
219
|
+
| `values` | `list[float]` | `OpenTimeSeries` | Values of the timeseries. Not edited by any method to allow reversion to original. |
|
220
|
+
| `currency` | `str` | `OpenTimeSeries` | Currency of the timeseries. Only used if conversion/hedging methods are added. |
|
221
|
+
| `domestic` | `str` | `OpenTimeSeries` | Domestic currency of the user / investor. Only used if conversion/hedging methods are added. |
|
222
|
+
| `local_ccy` | `bool` | `OpenTimeSeries` | Indicates if series should be in its local currency or the domestic currency of the user. Only used if conversion/hedging methods are added. |
|
223
|
+
| `name` | `str` | `OpenTimeSeries` | An identifier field. |
|
224
|
+
| `isin` | `str` | `OpenTimeSeries` | ISIN code of the associated instrument. If any. |
|
225
|
+
| `label` | `str` | `OpenTimeSeries` | Field used in outputs. Derived from name as default. |
|
226
|
+
| `countries` | `list[str]` or `str` | `OpenTimeSeries` | (List of) country code(s) according to ISO 3166-1 alpha-2 used in the [holidays](https://github.com/vacanza/holidays/) package to generate business days. |
|
227
|
+
| `markets` | `list[str]` or `str` | `OpenTimeSeries` | (List of) markets code(s) according to market code(s) input for the [pandas-market-calendars](https://pandas-market-calendars.readthedocs.io/en/latest/) package. |
|
228
|
+
| `valuetype` | `ValueType` | `OpenTimeSeries` | Field identifies the type of values in the series. ValueType is an Enum. |
|
256
229
|
|
257
230
|
### Non-numerical or "helper" properties that apply only to the [OpenFrame](https://github.com/CaptorAB/openseries/blob/master/openseries/frame.py) class.
|
258
231
|
|
259
|
-
| Property | type
|
260
|
-
|
261
|
-
| `constituents` | `list[OpenTimeSeries]`
|
262
|
-
| `columns_lvl_zero` | `list`
|
263
|
-
| `columns_lvl_one` | `list`
|
264
|
-
| `item_count` | `int`
|
265
|
-
| `weights` | `list[float]`
|
266
|
-
| `first_indices` | `pandas.Series`
|
267
|
-
| `last_indices` | `pandas.Series`
|
268
|
-
| `lengths_of_items` | `pandas.Series`
|
269
|
-
| `span_of_days_all` | `pandas.Series`
|
232
|
+
| Property | type | Applies to | Description |
|
233
|
+
|:-------------------|:---------------------------------|:------------|:-------------------------------------------------------------------------|
|
234
|
+
| `constituents` | `list[OpenTimeSeries]` | `OpenFrame` | A list of the OpenTimeSeries that make up an OpenFrame. |
|
235
|
+
| `columns_lvl_zero` | `list[str]` | `OpenFrame` | A list of the level zero column names in the OpenFrame pandas.DataFrame. |
|
236
|
+
| `columns_lvl_one` | `list[ValueType]` or `list[str]` | `OpenFrame` | A list of the level one column names in the OpenFrame pandas.DataFrame. |
|
237
|
+
| `item_count` | `int` | `OpenFrame` | Number of columns in the OpenFrame pandas.DataFrame. |
|
238
|
+
| `weights` | `list[float]` | `OpenFrame` | Weights used in the method `make_portfolio`. |
|
239
|
+
| `first_indices` | `pandas.Series[dt.date]` | `OpenFrame` | First dates of all the series in the OpenFrame. |
|
240
|
+
| `last_indices` | `pandas.Series[dt.date]` | `OpenFrame` | Last dates of all the series in the OpenFrame. |
|
241
|
+
| `lengths_of_items` | `pandas.Series[int]` | `OpenFrame` | Number of items in each of the series in the OpenFrame. |
|
242
|
+
| `span_of_days_all` | `pandas.Series[int]` | `OpenFrame` | Number of days from the first to the last in each of the series. |
|
270
243
|
|
271
244
|
### Non-numerical or "helper" properties that apply to both the [OpenTimeSeries](https://github.com/CaptorAB/openseries/blob/master/openseries/series.py) and the [OpenFrame](https://github.com/CaptorAB/openseries/blob/master/openseries/frame.py) class.
|
272
245
|
|
@@ -290,7 +263,7 @@ make lint
|
|
290
263
|
| `running_adjustment` | `OpenTimeSeries` | Adjusts the series performance with a `float` factor. |
|
291
264
|
| `ewma_vol_func` | `OpenTimeSeries` | Returns a `pandas.Series` with volatility based on [Exponentially Weighted Moving Average](https://www.investopedia.com/articles/07/ewma.asp). |
|
292
265
|
| `from_1d_rate_to_cumret` | `OpenTimeSeries` | Converts a series of 1-day rates into a cumulative valueseries. |
|
293
|
-
|
266
|
+
|
|
294
267
|
|
295
268
|
### Methods that apply only to the [OpenFrame](https://github.com/CaptorAB/openseries/blob/master/openseries/frame.py) class.
|
296
269
|
|
@@ -328,11 +301,11 @@ make lint
|
|
328
301
|
| `to_xlsx` | `OpenTimeSeries`, `OpenFrame` | Method to save the data in the .tsdf DataFrame to an Excel file. |
|
329
302
|
| `value_to_ret` | `OpenTimeSeries`, `OpenFrame` | Converts a value series into a percentage return series. |
|
330
303
|
| `value_to_diff` | `OpenTimeSeries`, `OpenFrame` | Converts a value series into a series of differences. |
|
331
|
-
| `value_to_log` | `OpenTimeSeries`, `OpenFrame` | Converts a value series into a
|
304
|
+
| `value_to_log` | `OpenTimeSeries`, `OpenFrame` | Converts a value series into a cumulative log return series, useful for plotting growth relative to the starting point. |
|
332
305
|
| `value_ret_calendar_period` | `OpenTimeSeries`, `OpenFrame` | Returns the series simple return for a specific calendar period. |
|
333
|
-
| `plot_series` | `OpenTimeSeries`, `OpenFrame` | Opens a HTML [Plotly Scatter](https://plotly.com/python/line-and-scatter/) plot of the serie(s) in a browser window.
|
334
|
-
| `plot_bars` | `OpenTimeSeries`, `OpenFrame` | Opens a HTML [Plotly Bar](https://plotly.com/python/bar-charts/) plot of the serie(s) in a browser window.
|
335
|
-
| `plot_histogram` | `OpenTimeSeries`, `OpenFrame` | Opens a HTML [Plotly Histogram](https://plotly.com/python/histograms/) plot of the serie(s) in a browser window.
|
306
|
+
| `plot_series` | `OpenTimeSeries`, `OpenFrame` | Opens a HTML [Plotly Scatter](https://plotly.com/python/line-and-scatter/) plot of the serie(s) in a browser window. |
|
307
|
+
| `plot_bars` | `OpenTimeSeries`, `OpenFrame` | Opens a HTML [Plotly Bar](https://plotly.com/python/bar-charts/) plot of the serie(s) in a browser window. |
|
308
|
+
| `plot_histogram` | `OpenTimeSeries`, `OpenFrame` | Opens a HTML [Plotly Histogram](https://plotly.com/python/histograms/) plot of the serie(s) in a browser window. |
|
336
309
|
| `to_drawdown_series` | `OpenTimeSeries`, `OpenFrame` | Converts the series into drawdown series. |
|
337
310
|
| `rolling_return` | `OpenTimeSeries`, `OpenFrame` | Returns a pandas.DataFrame with rolling returns. |
|
338
311
|
| `rolling_vol` | `OpenTimeSeries`, `OpenFrame` | Returns a pandas.DataFrame with rolling volatilities. |
|
@@ -9,7 +9,7 @@
|
|
9
9
|

|
10
10
|
[](https://www.python.org/)
|
11
11
|
[](https://github.com/CaptorAB/openseries/actions/workflows/test.yml)
|
12
|
-
[](https://codecov.io/gh/CaptorAB/openseries)
|
13
13
|
[](https://python-poetry.org/)
|
14
14
|
[](https://beta.ruff.rs/docs/)
|
15
15
|
[](https://github.com/CaptorAB/openseries/blob/master/LICENSE.md)
|
@@ -18,7 +18,6 @@
|
|
18
18
|
This is a project with tools to analyze financial timeseries of a single
|
19
19
|
asset or a group of assets. It is solely made for daily or less frequent data.
|
20
20
|
|
21
|
-
|
22
21
|
## Basic Usage
|
23
22
|
|
24
23
|
To install:
|
@@ -53,34 +52,9 @@ _,_=series.plot_series()
|
|
53
52
|
|
54
53
|
```
|
55
54
|
|
56
|
-
### Sample output using the
|
57
|
-
|
58
|
-
|
59
|
-
ValueType.PRICE ValueType.PRICE
|
60
|
-
Total return 3.641282 1.946319
|
61
|
-
Arithmetic return 0.096271 0.069636
|
62
|
-
Geometric return 0.093057 0.06464
|
63
|
-
Volatility 0.120279 0.117866
|
64
|
-
Return vol ratio 0.800396 0.59081
|
65
|
-
Downside deviation 0.085956 0.086723
|
66
|
-
Sortino ratio 1.119993 0.802975
|
67
|
-
Positive share 0.541783 0.551996
|
68
|
-
Worst -0.071616 -0.089415
|
69
|
-
Worst month -0.122503 -0.154485
|
70
|
-
Max drawdown -0.309849 -0.435444
|
71
|
-
Max drawdown in cal yr -0.309849 -0.348681
|
72
|
-
Max drawdown dates 2020-03-23 2009-03-09
|
73
|
-
CVaR 95.0% -0.01793 -0.018429
|
74
|
-
VaR 95.0% -0.011365 -0.010807
|
75
|
-
Imp vol from VaR 95% 0.109204 0.103834
|
76
|
-
Z-score 0.587905 0.103241
|
77
|
-
Skew -0.650782 -0.888109
|
78
|
-
Kurtosis 8.511166 17.527367
|
79
|
-
observations 4309 4309
|
80
|
-
span of days 6301 6301
|
81
|
-
first indices 2006-01-03 2006-01-03
|
82
|
-
last indices 2023-04-05 2023-04-05
|
83
|
-
```
|
55
|
+
### Sample output using the report_html() function:
|
56
|
+
|
57
|
+
<img src="./captor_plot_image.png" alt="Two Assets Compared" width="1000" />
|
84
58
|
|
85
59
|
## Development Instructions
|
86
60
|
|
@@ -91,7 +65,6 @@ The OpenTimeSeries and OpenFrame classes are both subclasses of
|
|
91
65
|
the [Pydantic BaseModel](https://docs.pydantic.dev/usage/models/). Please refer to its documentation for information
|
92
66
|
on any attributes or methods inherited from this model.
|
93
67
|
|
94
|
-
|
95
68
|
### Windows Powershell
|
96
69
|
|
97
70
|
```powershell
|
@@ -106,9 +79,8 @@ cd openseries
|
|
106
79
|
```bash
|
107
80
|
git clone https://github.com/CaptorAB/openseries.git
|
108
81
|
cd openseries
|
109
|
-
make
|
110
|
-
source source_me
|
111
82
|
make install
|
83
|
+
source source_me
|
112
84
|
|
113
85
|
```
|
114
86
|
|
@@ -137,7 +109,6 @@ make lint
|
|
137
109
|
|
138
110
|
```
|
139
111
|
|
140
|
-
|
141
112
|
## Table of Contents
|
142
113
|
|
143
114
|
- [Basic Usage](#basic-usage)
|
@@ -156,12 +127,13 @@ make lint
|
|
156
127
|
|
157
128
|
### On some files in the project
|
158
129
|
|
159
|
-
| File | Description
|
160
|
-
|
161
|
-
| [series.py](https://github.com/CaptorAB/openseries/blob/master/openseries/series.py) | Defines the class _OpenTimeSeries_ for managing and analyzing a single timeseries. The module also defines a function `timeseries_chain` that can be used to chain two timeseries objects together.
|
162
|
-
| [frame.py](https://github.com/CaptorAB/openseries/blob/master/openseries/frame.py) | Defines the class _OpenFrame_ for managing a group of timeseries, and e.g. calculate a portfolio timeseries from a rebalancing strategy between timeseries.
|
163
|
-
| [portfoliotools.py](https://github.com/CaptorAB/openseries/blob/master/openseries/portfoliotools.py) | Defines functions to simulate, optimize, and plot portfolios.
|
164
|
-
| [
|
130
|
+
| File | Description |
|
131
|
+
|:-----------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
132
|
+
| [series.py](https://github.com/CaptorAB/openseries/blob/master/openseries/series.py) | Defines the class _OpenTimeSeries_ for managing and analyzing a single timeseries. The module also defines a function `timeseries_chain` that can be used to chain two timeseries objects together. |
|
133
|
+
| [frame.py](https://github.com/CaptorAB/openseries/blob/master/openseries/frame.py) | Defines the class _OpenFrame_ for managing a group of timeseries, and e.g. calculate a portfolio timeseries from a rebalancing strategy between timeseries. |
|
134
|
+
| [portfoliotools.py](https://github.com/CaptorAB/openseries/blob/master/openseries/portfoliotools.py) | Defines functions to simulate, optimize, and plot portfolios. |
|
135
|
+
| [report.py](https://github.com/CaptorAB/openseries/blob/master/openseries/report.py) | Defines the _report_html_ function that is used to create a landscape orientation report on at least two assets. All preceding assets will be measured against the last asset in the input OpenFrame. |
|
136
|
+
| [simulation.py](https://github.com/CaptorAB/openseries/blob/master/openseries/simulation.py) | Defines the class _ReturnSimulation_ to create simulated financial timeseries. Used in the project's test suite |
|
165
137
|
|
166
138
|
### Class methods used to construct objects.
|
167
139
|
|
@@ -174,34 +146,35 @@ make lint
|
|
174
146
|
|
175
147
|
### Non-numerical or "helper" properties that apply only to the [OpenTimeSeries](https://github.com/CaptorAB/openseries/blob/master/openseries/series.py) class.
|
176
148
|
|
177
|
-
| Property | type
|
178
|
-
|
179
|
-
| `timeseries_id` | `str`
|
180
|
-
| `instrument_id` | `str`
|
181
|
-
| `dates` | `list[str]`
|
182
|
-
| `values` | `list[float]`
|
183
|
-
| `currency` | `str`
|
184
|
-
| `domestic` | `str`
|
185
|
-
| `local_ccy` | `bool`
|
186
|
-
| `name` | `str`
|
187
|
-
| `isin` | `str`
|
188
|
-
| `label` | `str`
|
189
|
-
| `countries` | `list` or `str` | `OpenTimeSeries` | (List of) country code(s) according to ISO 3166-1 alpha-2 used to generate business days.
|
190
|
-
| `
|
149
|
+
| Property | type | Applies to | Description |
|
150
|
+
|:----------------|:---------------------|:-----------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
151
|
+
| `timeseries_id` | `str` | `OpenTimeSeries` | Placeholder for database identifier for the timeseries. Can be left as empty string. |
|
152
|
+
| `instrument_id` | `str` | `OpenTimeSeries` | Placeholder for database identifier for the instrument associated with the timeseries. Can be left as empty string. |
|
153
|
+
| `dates` | `list[str]` | `OpenTimeSeries` | Dates of the timeseries. Not edited by any method to allow reversion to original. |
|
154
|
+
| `values` | `list[float]` | `OpenTimeSeries` | Values of the timeseries. Not edited by any method to allow reversion to original. |
|
155
|
+
| `currency` | `str` | `OpenTimeSeries` | Currency of the timeseries. Only used if conversion/hedging methods are added. |
|
156
|
+
| `domestic` | `str` | `OpenTimeSeries` | Domestic currency of the user / investor. Only used if conversion/hedging methods are added. |
|
157
|
+
| `local_ccy` | `bool` | `OpenTimeSeries` | Indicates if series should be in its local currency or the domestic currency of the user. Only used if conversion/hedging methods are added. |
|
158
|
+
| `name` | `str` | `OpenTimeSeries` | An identifier field. |
|
159
|
+
| `isin` | `str` | `OpenTimeSeries` | ISIN code of the associated instrument. If any. |
|
160
|
+
| `label` | `str` | `OpenTimeSeries` | Field used in outputs. Derived from name as default. |
|
161
|
+
| `countries` | `list[str]` or `str` | `OpenTimeSeries` | (List of) country code(s) according to ISO 3166-1 alpha-2 used in the [holidays](https://github.com/vacanza/holidays/) package to generate business days. |
|
162
|
+
| `markets` | `list[str]` or `str` | `OpenTimeSeries` | (List of) markets code(s) according to market code(s) input for the [pandas-market-calendars](https://pandas-market-calendars.readthedocs.io/en/latest/) package. |
|
163
|
+
| `valuetype` | `ValueType` | `OpenTimeSeries` | Field identifies the type of values in the series. ValueType is an Enum. |
|
191
164
|
|
192
165
|
### Non-numerical or "helper" properties that apply only to the [OpenFrame](https://github.com/CaptorAB/openseries/blob/master/openseries/frame.py) class.
|
193
166
|
|
194
|
-
| Property | type
|
195
|
-
|
196
|
-
| `constituents` | `list[OpenTimeSeries]`
|
197
|
-
| `columns_lvl_zero` | `list`
|
198
|
-
| `columns_lvl_one` | `list`
|
199
|
-
| `item_count` | `int`
|
200
|
-
| `weights` | `list[float]`
|
201
|
-
| `first_indices` | `pandas.Series`
|
202
|
-
| `last_indices` | `pandas.Series`
|
203
|
-
| `lengths_of_items` | `pandas.Series`
|
204
|
-
| `span_of_days_all` | `pandas.Series`
|
167
|
+
| Property | type | Applies to | Description |
|
168
|
+
|:-------------------|:---------------------------------|:------------|:-------------------------------------------------------------------------|
|
169
|
+
| `constituents` | `list[OpenTimeSeries]` | `OpenFrame` | A list of the OpenTimeSeries that make up an OpenFrame. |
|
170
|
+
| `columns_lvl_zero` | `list[str]` | `OpenFrame` | A list of the level zero column names in the OpenFrame pandas.DataFrame. |
|
171
|
+
| `columns_lvl_one` | `list[ValueType]` or `list[str]` | `OpenFrame` | A list of the level one column names in the OpenFrame pandas.DataFrame. |
|
172
|
+
| `item_count` | `int` | `OpenFrame` | Number of columns in the OpenFrame pandas.DataFrame. |
|
173
|
+
| `weights` | `list[float]` | `OpenFrame` | Weights used in the method `make_portfolio`. |
|
174
|
+
| `first_indices` | `pandas.Series[dt.date]` | `OpenFrame` | First dates of all the series in the OpenFrame. |
|
175
|
+
| `last_indices` | `pandas.Series[dt.date]` | `OpenFrame` | Last dates of all the series in the OpenFrame. |
|
176
|
+
| `lengths_of_items` | `pandas.Series[int]` | `OpenFrame` | Number of items in each of the series in the OpenFrame. |
|
177
|
+
| `span_of_days_all` | `pandas.Series[int]` | `OpenFrame` | Number of days from the first to the last in each of the series. |
|
205
178
|
|
206
179
|
### Non-numerical or "helper" properties that apply to both the [OpenTimeSeries](https://github.com/CaptorAB/openseries/blob/master/openseries/series.py) and the [OpenFrame](https://github.com/CaptorAB/openseries/blob/master/openseries/frame.py) class.
|
207
180
|
|
@@ -225,7 +198,7 @@ make lint
|
|
225
198
|
| `running_adjustment` | `OpenTimeSeries` | Adjusts the series performance with a `float` factor. |
|
226
199
|
| `ewma_vol_func` | `OpenTimeSeries` | Returns a `pandas.Series` with volatility based on [Exponentially Weighted Moving Average](https://www.investopedia.com/articles/07/ewma.asp). |
|
227
200
|
| `from_1d_rate_to_cumret` | `OpenTimeSeries` | Converts a series of 1-day rates into a cumulative valueseries. |
|
228
|
-
|
201
|
+
|
|
229
202
|
|
230
203
|
### Methods that apply only to the [OpenFrame](https://github.com/CaptorAB/openseries/blob/master/openseries/frame.py) class.
|
231
204
|
|
@@ -263,11 +236,11 @@ make lint
|
|
263
236
|
| `to_xlsx` | `OpenTimeSeries`, `OpenFrame` | Method to save the data in the .tsdf DataFrame to an Excel file. |
|
264
237
|
| `value_to_ret` | `OpenTimeSeries`, `OpenFrame` | Converts a value series into a percentage return series. |
|
265
238
|
| `value_to_diff` | `OpenTimeSeries`, `OpenFrame` | Converts a value series into a series of differences. |
|
266
|
-
| `value_to_log` | `OpenTimeSeries`, `OpenFrame` | Converts a value series into a
|
239
|
+
| `value_to_log` | `OpenTimeSeries`, `OpenFrame` | Converts a value series into a cumulative log return series, useful for plotting growth relative to the starting point. |
|
267
240
|
| `value_ret_calendar_period` | `OpenTimeSeries`, `OpenFrame` | Returns the series simple return for a specific calendar period. |
|
268
|
-
| `plot_series` | `OpenTimeSeries`, `OpenFrame` | Opens a HTML [Plotly Scatter](https://plotly.com/python/line-and-scatter/) plot of the serie(s) in a browser window.
|
269
|
-
| `plot_bars` | `OpenTimeSeries`, `OpenFrame` | Opens a HTML [Plotly Bar](https://plotly.com/python/bar-charts/) plot of the serie(s) in a browser window.
|
270
|
-
| `plot_histogram` | `OpenTimeSeries`, `OpenFrame` | Opens a HTML [Plotly Histogram](https://plotly.com/python/histograms/) plot of the serie(s) in a browser window.
|
241
|
+
| `plot_series` | `OpenTimeSeries`, `OpenFrame` | Opens a HTML [Plotly Scatter](https://plotly.com/python/line-and-scatter/) plot of the serie(s) in a browser window. |
|
242
|
+
| `plot_bars` | `OpenTimeSeries`, `OpenFrame` | Opens a HTML [Plotly Bar](https://plotly.com/python/bar-charts/) plot of the serie(s) in a browser window. |
|
243
|
+
| `plot_histogram` | `OpenTimeSeries`, `OpenFrame` | Opens a HTML [Plotly Histogram](https://plotly.com/python/histograms/) plot of the serie(s) in a browser window. |
|
271
244
|
| `to_drawdown_series` | `OpenTimeSeries`, `OpenFrame` | Converts the series into drawdown series. |
|
272
245
|
| `rolling_return` | `OpenTimeSeries`, `OpenFrame` | Returns a pandas.DataFrame with rolling returns. |
|
273
246
|
| `rolling_vol` | `OpenTimeSeries`, `OpenFrame` | Returns a pandas.DataFrame with rolling volatilities. |
|
@@ -1,4 +1,11 @@
|
|
1
|
-
"""openseries.openseries.__init__.py.
|
1
|
+
"""openseries.openseries.__init__.py.
|
2
|
+
|
3
|
+
Copyright (c) Captor Fund Management AB. This file is part of the openseries project.
|
4
|
+
|
5
|
+
Licensed under the BSD 3-Clause License. You may obtain a copy of the License at:
|
6
|
+
https://github.com/CaptorAB/openseries/blob/master/LICENSE.md
|
7
|
+
SPDX-License-Identifier: BSD-3-Clause
|
8
|
+
"""
|
2
9
|
|
3
10
|
from .datefixer import (
|
4
11
|
date_fix,
|
@@ -18,6 +25,7 @@ from .portfoliotools import (
|
|
18
25
|
sharpeplot,
|
19
26
|
simulate_portfolios,
|
20
27
|
)
|
28
|
+
from .report import report_html
|
21
29
|
from .series import OpenTimeSeries, timeseries_chain
|
22
30
|
from .simulation import ReturnSimulation
|
23
31
|
|
@@ -37,6 +45,7 @@ __all__ = [
|
|
37
45
|
"load_plotly_dict",
|
38
46
|
"offset_business_days",
|
39
47
|
"prepare_plot_data",
|
48
|
+
"report_html",
|
40
49
|
"sharpeplot",
|
41
50
|
"simulate_portfolios",
|
42
51
|
"timeseries_chain",
|
@@ -1,4 +1,11 @@
|
|
1
|
-
"""Defining the _CommonModel class.
|
1
|
+
"""Defining the _CommonModel class.
|
2
|
+
|
3
|
+
Copyright (c) Captor Fund Management AB. This file is part of the openseries project.
|
4
|
+
|
5
|
+
Licensed under the BSD 3-Clause License. You may obtain a copy of the License at:
|
6
|
+
https://github.com/CaptorAB/openseries/blob/master/LICENSE.md
|
7
|
+
SPDX-License-Identifier: BSD-3-Clause
|
8
|
+
"""
|
2
9
|
|
3
10
|
# mypy: disable-error-code="no-any-return"
|
4
11
|
from __future__ import annotations
|
@@ -58,7 +65,7 @@ from plotly.figure_factory import create_distplot # type: ignore[import-untyped
|
|
58
65
|
from plotly.graph_objs import Figure # type: ignore[import-untyped]
|
59
66
|
from plotly.io import to_html # type: ignore[import-untyped]
|
60
67
|
from plotly.offline import plot # type: ignore[import-untyped]
|
61
|
-
from pydantic import BaseModel, ConfigDict, DirectoryPath
|
68
|
+
from pydantic import BaseModel, ConfigDict, DirectoryPath, ValidationError
|
62
69
|
from scipy.stats import ( # type: ignore[import-untyped]
|
63
70
|
kurtosis,
|
64
71
|
norm,
|
@@ -377,13 +384,23 @@ class _CommonModel(BaseModel): # type: ignore[misc]
|
|
377
384
|
|
378
385
|
"""
|
379
386
|
method: LiteralPandasReindexMethod = "nearest"
|
380
|
-
|
387
|
+
|
388
|
+
try:
|
389
|
+
countries = self.countries
|
390
|
+
markets = self.markets
|
391
|
+
except AttributeError:
|
392
|
+
countries = self.constituents[0].countries
|
393
|
+
markets = self.constituents[0].markets
|
394
|
+
|
381
395
|
wmdf = self.tsdf.copy()
|
396
|
+
|
382
397
|
dates = _do_resample_to_business_period_ends(
|
383
398
|
data=wmdf,
|
384
399
|
freq="BME",
|
385
400
|
countries=countries,
|
401
|
+
markets=markets,
|
386
402
|
)
|
403
|
+
|
387
404
|
wmdf = wmdf.reindex(index=[deyt.date() for deyt in dates], method=method)
|
388
405
|
wmdf.index = DatetimeIndex(wmdf.index)
|
389
406
|
result = wmdf.ffill().pct_change().min()
|
@@ -539,14 +556,20 @@ class _CommonModel(BaseModel): # type: ignore[misc]
|
|
539
556
|
|
540
557
|
def align_index_to_local_cdays(
|
541
558
|
self: Self,
|
542
|
-
countries: CountriesType =
|
559
|
+
countries: CountriesType | None = None,
|
560
|
+
markets: list[str] | str | None = None,
|
561
|
+
custom_holidays: list[str] | str | None = None,
|
543
562
|
) -> Self:
|
544
563
|
"""Align the index of .tsdf with local calendar business days.
|
545
564
|
|
546
565
|
Parameters
|
547
566
|
----------
|
548
|
-
countries: CountriesType,
|
567
|
+
countries: CountriesType, optional
|
549
568
|
(List of) country code(s) according to ISO 3166-1 alpha-2
|
569
|
+
markets: list[str] | str, optional
|
570
|
+
(List of) markets code(s) according to pandas-market-calendars
|
571
|
+
custom_holidays: list[str] | str, optional
|
572
|
+
Argument where missing holidays can be added
|
550
573
|
|
551
574
|
Returns:
|
552
575
|
-------
|
@@ -556,10 +579,37 @@ class _CommonModel(BaseModel): # type: ignore[misc]
|
|
556
579
|
"""
|
557
580
|
startyear = cast("int", to_datetime(self.tsdf.index[0]).year)
|
558
581
|
endyear = cast("int", to_datetime(self.tsdf.index[-1]).year)
|
582
|
+
|
583
|
+
if countries:
|
584
|
+
try:
|
585
|
+
self.countries = countries
|
586
|
+
except ValidationError:
|
587
|
+
for serie in self.constituents:
|
588
|
+
serie.countries = countries
|
589
|
+
else:
|
590
|
+
try:
|
591
|
+
countries = self.countries
|
592
|
+
except AttributeError:
|
593
|
+
countries = self.constituents[0].countries
|
594
|
+
|
595
|
+
if markets:
|
596
|
+
try:
|
597
|
+
self.markets = markets
|
598
|
+
except ValidationError:
|
599
|
+
for serie in self.constituents:
|
600
|
+
serie.markets = markets
|
601
|
+
else:
|
602
|
+
try:
|
603
|
+
markets = self.markets
|
604
|
+
except AttributeError:
|
605
|
+
markets = self.constituents[0].markets
|
606
|
+
|
559
607
|
calendar = holiday_calendar(
|
560
608
|
startyear=startyear,
|
561
609
|
endyear=endyear,
|
562
610
|
countries=countries,
|
611
|
+
markets=markets,
|
612
|
+
custom_holidays=custom_holidays,
|
563
613
|
)
|
564
614
|
|
565
615
|
d_range = [
|
@@ -1,4 +1,11 @@
|
|
1
|
-
"""Various risk related functions.
|
1
|
+
"""Various risk related functions.
|
2
|
+
|
3
|
+
Copyright (c) Captor Fund Management AB. This file is part of the openseries project.
|
4
|
+
|
5
|
+
Licensed under the BSD 3-Clause License. You may obtain a copy of the License at:
|
6
|
+
https://github.com/CaptorAB/openseries/blob/master/LICENSE.md
|
7
|
+
SPDX-License-Identifier: BSD-3-Clause
|
8
|
+
"""
|
2
9
|
|
3
10
|
from __future__ import annotations
|
4
11
|
|