openseries 1.5.0__tar.gz → 1.5.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.
- {openseries-1.5.0 → openseries-1.5.1}/PKG-INFO +21 -21
- {openseries-1.5.0 → openseries-1.5.1}/README.md +18 -18
- {openseries-1.5.0 → openseries-1.5.1}/openseries/_risk.py +0 -3
- {openseries-1.5.0 → openseries-1.5.1}/openseries/frame.py +21 -69
- {openseries-1.5.0 → openseries-1.5.1}/openseries/series.py +1 -0
- {openseries-1.5.0 → openseries-1.5.1}/openseries/types.py +0 -2
- {openseries-1.5.0 → openseries-1.5.1}/pyproject.toml +8 -10
- {openseries-1.5.0 → openseries-1.5.1}/LICENSE.md +0 -0
- {openseries-1.5.0 → openseries-1.5.1}/openseries/__init__.py +0 -0
- {openseries-1.5.0 → openseries-1.5.1}/openseries/_common_model.py +0 -0
- {openseries-1.5.0 → openseries-1.5.1}/openseries/datefixer.py +0 -0
- {openseries-1.5.0 → openseries-1.5.1}/openseries/load_plotly.py +0 -0
- {openseries-1.5.0 → openseries-1.5.1}/openseries/plotly_captor_logo.json +0 -0
- {openseries-1.5.0 → openseries-1.5.1}/openseries/plotly_layouts.json +0 -0
- {openseries-1.5.0 → openseries-1.5.1}/openseries/simulation.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: openseries
|
3
|
-
Version: 1.5.
|
3
|
+
Version: 1.5.1
|
4
4
|
Summary: Package for analyzing financial timeseries.
|
5
5
|
Home-page: https://github.com/CaptorAB/OpenSeries
|
6
6
|
License: BSD-3-Clause
|
@@ -20,15 +20,15 @@ Classifier: Programming Language :: Python :: 3.10
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.11
|
21
21
|
Classifier: Programming Language :: Python :: 3.12
|
22
22
|
Classifier: Topic :: Office/Business :: Financial :: Investment
|
23
|
-
Requires-Dist: ffn (>=1.0.0,<2.0.0)
|
24
23
|
Requires-Dist: holidays (>=0.30,<1.0)
|
25
24
|
Requires-Dist: numpy (>=1.23.2,<=2.0.0)
|
26
25
|
Requires-Dist: openpyxl (>=3.1.2,<4.0.0)
|
27
26
|
Requires-Dist: pandas (>=2.1.2,<3.0.0)
|
28
27
|
Requires-Dist: plotly (>=5.18.0,<6.0.0)
|
29
|
-
Requires-Dist: pyarrow (>=14.0.2,<
|
28
|
+
Requires-Dist: pyarrow (>=14.0.2,<16.0.0)
|
30
29
|
Requires-Dist: pydantic (>=2.5.2,<3.0.0)
|
31
30
|
Requires-Dist: python-dateutil (>=2.8.2,<3.0.0)
|
31
|
+
Requires-Dist: requests (>=2.20.0,<3.0.0)
|
32
32
|
Requires-Dist: scipy (>=1.11.4,<2.0.0)
|
33
33
|
Requires-Dist: statsmodels (>=0.14.0,<1.0.0)
|
34
34
|
Project-URL: Repository, https://github.com/CaptorAB/OpenSeries
|
@@ -272,24 +272,24 @@ make lint
|
|
272
272
|
|
273
273
|
### Methods that apply only to the [OpenFrame](https://github.com/CaptorAB/OpenSeries/blob/master/openseries/frame.py) class.
|
274
274
|
|
275
|
-
| Method | Applies to | Description
|
276
|
-
|
277
|
-
| `merge_series` | `OpenFrame` | Merges the Pandas Dataframes of the constituent OpenTimeSeries.
|
278
|
-
| `trunc_frame` | `OpenFrame` | Truncates the OpenFrame to a common period.
|
279
|
-
| `add_timeseries` | `OpenFrame` | Adds a given OpenTimeSeries to the OpenFrame.
|
280
|
-
| `delete_timeseries` | `OpenFrame` | Deletes an OpenTimeSeries from the OpenFrame.
|
281
|
-
| `relative` | `OpenFrame` | Calculates a new series that is the relative performance of two others.
|
282
|
-
| `make_portfolio` | `OpenFrame` | Calculates a portfolio timeseries based on the series and weights. Weights can be provided as a list, or a weight strategy can be
|
283
|
-
| `ord_least_squares_fit` | `OpenFrame` | Performs a regression and an [Ordinary Least Squares](https://www.statsmodels.org/stable/examples/notebooks/generated/ols.html) fit.
|
284
|
-
| `beta` | `OpenFrame` | Calculates [Beta](https://www.investopedia.com/terms/b/beta.asp) of an asset relative a market.
|
285
|
-
| `jensen_alpha` | `OpenFrame` | Calculates [Jensen's Alpha](https://www.investopedia.com/terms/j/jensensmeasure.asp) of an asset relative a market.
|
286
|
-
| `tracking_error_func` | `OpenFrame` | Calculates the [tracking errors](https://www.investopedia.com/terms/t/trackingerror.asp) relative to a selected series in the OpenFrame.
|
287
|
-
| `info_ratio_func` | `OpenFrame` | Calculates the [information ratios](https://www.investopedia.com/terms/i/informationratio.asp) relative to a selected series in the OpenFrame.
|
288
|
-
| `capture_ratio_func` | `OpenFrame` | Calculates up, down and up/down [capture ratios](https://www.investopedia.com/terms/d/down-market-capture-ratio.asp) relative to a selected series.
|
289
|
-
| `rolling_info_ratio` | `OpenFrame` | Returns a pandas.DataFrame with the rolling [information ratio](https://www.investopedia.com/terms/i/informationratio.asp) between two series.
|
290
|
-
| `rolling_beta` | `OpenFrame` | Returns a pandas.DataFrame with the rolling [Beta](https://www.investopedia.com/terms/b/beta.asp) of an asset relative a market.
|
291
|
-
| `rolling_corr` | `OpenFrame` | Calculates and adds a series of rolling [correlations](https://www.investopedia.com/terms/c/correlation.asp) between two other series.
|
292
|
-
| `ewma_risk` | `OpenFrame` | Returns a `pandas.DataFrame` with volatility and correlation based on [Exponentially Weighted Moving Average](https://www.investopedia.com/articles/07/ewma.asp).
|
275
|
+
| Method | Applies to | Description |
|
276
|
+
|:------------------------|:------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
277
|
+
| `merge_series` | `OpenFrame` | Merges the Pandas Dataframes of the constituent OpenTimeSeries. |
|
278
|
+
| `trunc_frame` | `OpenFrame` | Truncates the OpenFrame to a common period. |
|
279
|
+
| `add_timeseries` | `OpenFrame` | Adds a given OpenTimeSeries to the OpenFrame. |
|
280
|
+
| `delete_timeseries` | `OpenFrame` | Deletes an OpenTimeSeries from the OpenFrame. |
|
281
|
+
| `relative` | `OpenFrame` | Calculates a new series that is the relative performance of two others. |
|
282
|
+
| `make_portfolio` | `OpenFrame` | Calculates a portfolio timeseries based on the series and weights. Weights can be provided as a list, or a weight strategy can be set as *equal weights* or *inverted volatility*. |
|
283
|
+
| `ord_least_squares_fit` | `OpenFrame` | Performs a regression and an [Ordinary Least Squares](https://www.statsmodels.org/stable/examples/notebooks/generated/ols.html) fit. |
|
284
|
+
| `beta` | `OpenFrame` | Calculates [Beta](https://www.investopedia.com/terms/b/beta.asp) of an asset relative a market. |
|
285
|
+
| `jensen_alpha` | `OpenFrame` | Calculates [Jensen's Alpha](https://www.investopedia.com/terms/j/jensensmeasure.asp) of an asset relative a market. |
|
286
|
+
| `tracking_error_func` | `OpenFrame` | Calculates the [tracking errors](https://www.investopedia.com/terms/t/trackingerror.asp) relative to a selected series in the OpenFrame. |
|
287
|
+
| `info_ratio_func` | `OpenFrame` | Calculates the [information ratios](https://www.investopedia.com/terms/i/informationratio.asp) relative to a selected series in the OpenFrame. |
|
288
|
+
| `capture_ratio_func` | `OpenFrame` | Calculates up, down and up/down [capture ratios](https://www.investopedia.com/terms/d/down-market-capture-ratio.asp) relative to a selected series. |
|
289
|
+
| `rolling_info_ratio` | `OpenFrame` | Returns a pandas.DataFrame with the rolling [information ratio](https://www.investopedia.com/terms/i/informationratio.asp) between two series. |
|
290
|
+
| `rolling_beta` | `OpenFrame` | Returns a pandas.DataFrame with the rolling [Beta](https://www.investopedia.com/terms/b/beta.asp) of an asset relative a market. |
|
291
|
+
| `rolling_corr` | `OpenFrame` | Calculates and adds a series of rolling [correlations](https://www.investopedia.com/terms/c/correlation.asp) between two other series. |
|
292
|
+
| `ewma_risk` | `OpenFrame` | Returns a `pandas.DataFrame` with volatility and correlation based on [Exponentially Weighted Moving Average](https://www.investopedia.com/articles/07/ewma.asp). |
|
293
293
|
|
294
294
|
### Methods 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.
|
295
295
|
|
@@ -236,24 +236,24 @@ make lint
|
|
236
236
|
|
237
237
|
### Methods that apply only to the [OpenFrame](https://github.com/CaptorAB/OpenSeries/blob/master/openseries/frame.py) class.
|
238
238
|
|
239
|
-
| Method | Applies to | Description
|
240
|
-
|
241
|
-
| `merge_series` | `OpenFrame` | Merges the Pandas Dataframes of the constituent OpenTimeSeries.
|
242
|
-
| `trunc_frame` | `OpenFrame` | Truncates the OpenFrame to a common period.
|
243
|
-
| `add_timeseries` | `OpenFrame` | Adds a given OpenTimeSeries to the OpenFrame.
|
244
|
-
| `delete_timeseries` | `OpenFrame` | Deletes an OpenTimeSeries from the OpenFrame.
|
245
|
-
| `relative` | `OpenFrame` | Calculates a new series that is the relative performance of two others.
|
246
|
-
| `make_portfolio` | `OpenFrame` | Calculates a portfolio timeseries based on the series and weights. Weights can be provided as a list, or a weight strategy can be
|
247
|
-
| `ord_least_squares_fit` | `OpenFrame` | Performs a regression and an [Ordinary Least Squares](https://www.statsmodels.org/stable/examples/notebooks/generated/ols.html) fit.
|
248
|
-
| `beta` | `OpenFrame` | Calculates [Beta](https://www.investopedia.com/terms/b/beta.asp) of an asset relative a market.
|
249
|
-
| `jensen_alpha` | `OpenFrame` | Calculates [Jensen's Alpha](https://www.investopedia.com/terms/j/jensensmeasure.asp) of an asset relative a market.
|
250
|
-
| `tracking_error_func` | `OpenFrame` | Calculates the [tracking errors](https://www.investopedia.com/terms/t/trackingerror.asp) relative to a selected series in the OpenFrame.
|
251
|
-
| `info_ratio_func` | `OpenFrame` | Calculates the [information ratios](https://www.investopedia.com/terms/i/informationratio.asp) relative to a selected series in the OpenFrame.
|
252
|
-
| `capture_ratio_func` | `OpenFrame` | Calculates up, down and up/down [capture ratios](https://www.investopedia.com/terms/d/down-market-capture-ratio.asp) relative to a selected series.
|
253
|
-
| `rolling_info_ratio` | `OpenFrame` | Returns a pandas.DataFrame with the rolling [information ratio](https://www.investopedia.com/terms/i/informationratio.asp) between two series.
|
254
|
-
| `rolling_beta` | `OpenFrame` | Returns a pandas.DataFrame with the rolling [Beta](https://www.investopedia.com/terms/b/beta.asp) of an asset relative a market.
|
255
|
-
| `rolling_corr` | `OpenFrame` | Calculates and adds a series of rolling [correlations](https://www.investopedia.com/terms/c/correlation.asp) between two other series.
|
256
|
-
| `ewma_risk` | `OpenFrame` | Returns a `pandas.DataFrame` with volatility and correlation based on [Exponentially Weighted Moving Average](https://www.investopedia.com/articles/07/ewma.asp).
|
239
|
+
| Method | Applies to | Description |
|
240
|
+
|:------------------------|:------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
241
|
+
| `merge_series` | `OpenFrame` | Merges the Pandas Dataframes of the constituent OpenTimeSeries. |
|
242
|
+
| `trunc_frame` | `OpenFrame` | Truncates the OpenFrame to a common period. |
|
243
|
+
| `add_timeseries` | `OpenFrame` | Adds a given OpenTimeSeries to the OpenFrame. |
|
244
|
+
| `delete_timeseries` | `OpenFrame` | Deletes an OpenTimeSeries from the OpenFrame. |
|
245
|
+
| `relative` | `OpenFrame` | Calculates a new series that is the relative performance of two others. |
|
246
|
+
| `make_portfolio` | `OpenFrame` | Calculates a portfolio timeseries based on the series and weights. Weights can be provided as a list, or a weight strategy can be set as *equal weights* or *inverted volatility*. |
|
247
|
+
| `ord_least_squares_fit` | `OpenFrame` | Performs a regression and an [Ordinary Least Squares](https://www.statsmodels.org/stable/examples/notebooks/generated/ols.html) fit. |
|
248
|
+
| `beta` | `OpenFrame` | Calculates [Beta](https://www.investopedia.com/terms/b/beta.asp) of an asset relative a market. |
|
249
|
+
| `jensen_alpha` | `OpenFrame` | Calculates [Jensen's Alpha](https://www.investopedia.com/terms/j/jensensmeasure.asp) of an asset relative a market. |
|
250
|
+
| `tracking_error_func` | `OpenFrame` | Calculates the [tracking errors](https://www.investopedia.com/terms/t/trackingerror.asp) relative to a selected series in the OpenFrame. |
|
251
|
+
| `info_ratio_func` | `OpenFrame` | Calculates the [information ratios](https://www.investopedia.com/terms/i/informationratio.asp) relative to a selected series in the OpenFrame. |
|
252
|
+
| `capture_ratio_func` | `OpenFrame` | Calculates up, down and up/down [capture ratios](https://www.investopedia.com/terms/d/down-market-capture-ratio.asp) relative to a selected series. |
|
253
|
+
| `rolling_info_ratio` | `OpenFrame` | Returns a pandas.DataFrame with the rolling [information ratio](https://www.investopedia.com/terms/i/informationratio.asp) between two series. |
|
254
|
+
| `rolling_beta` | `OpenFrame` | Returns a pandas.DataFrame with the rolling [Beta](https://www.investopedia.com/terms/b/beta.asp) of an asset relative a market. |
|
255
|
+
| `rolling_corr` | `OpenFrame` | Calculates and adds a series of rolling [correlations](https://www.investopedia.com/terms/c/correlation.asp) between two other series. |
|
256
|
+
| `ewma_risk` | `OpenFrame` | Returns a `pandas.DataFrame` with volatility and correlation based on [Exponentially Weighted Moving Average](https://www.investopedia.com/articles/07/ewma.asp). |
|
257
257
|
|
258
258
|
### Methods 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.
|
259
259
|
|
@@ -124,9 +124,6 @@ def _calc_inv_vol_weights(returns: DataFrame) -> NDArray[float64]:
|
|
124
124
|
"""
|
125
125
|
Calculate weights proportional to inverse volatility.
|
126
126
|
|
127
|
-
Source: https://github.com/pmorissette/ffn.
|
128
|
-
Function copied here because of FutureWarning from pandas ^2.1.0
|
129
|
-
|
130
127
|
Parameters
|
131
128
|
----------
|
132
129
|
returns: pandas.DataFrame
|
@@ -12,10 +12,6 @@ from pathlib import Path
|
|
12
12
|
from typing import Callable, Optional, Union, cast
|
13
13
|
|
14
14
|
import statsmodels.api as sm # type: ignore[import-untyped,unused-ignore]
|
15
|
-
from ffn.core import ( # type: ignore[import-untyped,unused-ignore]
|
16
|
-
calc_erc_weights,
|
17
|
-
calc_mean_var_weights,
|
18
|
-
)
|
19
15
|
from numpy import (
|
20
16
|
append,
|
21
17
|
array,
|
@@ -70,7 +66,6 @@ from openseries.types import (
|
|
70
66
|
DaysInYearType,
|
71
67
|
LiteralBizDayFreq,
|
72
68
|
LiteralCaptureRatio,
|
73
|
-
LiteralCovMethod,
|
74
69
|
LiteralFrameProps,
|
75
70
|
LiteralHowMerge,
|
76
71
|
LiteralLinePlotMode,
|
@@ -80,13 +75,13 @@ from openseries.types import (
|
|
80
75
|
LiteralPlotlyJSlib,
|
81
76
|
LiteralPlotlyOutput,
|
82
77
|
LiteralPortfolioWeightings,
|
83
|
-
LiteralRiskParityMethod,
|
84
78
|
LiteralTrunc,
|
85
79
|
OpenFramePropertiesList,
|
86
80
|
ValueType,
|
87
81
|
)
|
88
82
|
|
89
83
|
|
84
|
+
# noinspection PyUnresolvedReferences
|
90
85
|
class OpenFrame(_CommonModel):
|
91
86
|
|
92
87
|
"""
|
@@ -249,7 +244,7 @@ class OpenFrame(_CommonModel):
|
|
249
244
|
prop_list = [
|
250
245
|
getattr(self, x) for x in OpenFramePropertiesList.allowed_strings
|
251
246
|
]
|
252
|
-
return concat(prop_list, axis="columns").T
|
247
|
+
return cast(DataFrame, concat(prop_list, axis="columns").T)
|
253
248
|
|
254
249
|
@property
|
255
250
|
def lengths_of_items(self: Self) -> Series[int]:
|
@@ -666,6 +661,7 @@ class OpenFrame(_CommonModel):
|
|
666
661
|
|
667
662
|
"""
|
668
663
|
self.constituents += [new_series]
|
664
|
+
# noinspection PyUnreachableCode
|
669
665
|
self.tsdf = concat([self.tsdf, new_series.tsdf], axis="columns", sort=True)
|
670
666
|
return self
|
671
667
|
|
@@ -1476,15 +1472,6 @@ class OpenFrame(_CommonModel):
|
|
1476
1472
|
self: Self,
|
1477
1473
|
name: str,
|
1478
1474
|
weight_strat: Optional[LiteralPortfolioWeightings] = None,
|
1479
|
-
initial_weights: Optional[list[float]] = None,
|
1480
|
-
risk_weights: Optional[list[float]] = None,
|
1481
|
-
risk_parity_method: LiteralRiskParityMethod = "ccd",
|
1482
|
-
maximum_iterations: int = 100,
|
1483
|
-
tolerance: float = 1e-8,
|
1484
|
-
weight_bounds: tuple[float, float] = (0.0, 1.0),
|
1485
|
-
riskfree: float = 0.0,
|
1486
|
-
covar_method: LiteralCovMethod = "ledoit-wolf",
|
1487
|
-
options: Optional[dict[str, int]] = None,
|
1488
1475
|
) -> DataFrame:
|
1489
1476
|
"""
|
1490
1477
|
Calculate a basket timeseries based on the supplied weights.
|
@@ -1494,25 +1481,7 @@ class OpenFrame(_CommonModel):
|
|
1494
1481
|
name: str
|
1495
1482
|
Name of the basket timeseries
|
1496
1483
|
weight_strat: LiteralPortfolioWeightings, optional
|
1497
|
-
weight calculation
|
1498
|
-
initial_weights: list[float], optional
|
1499
|
-
Starting asset weights, default inverse volatility
|
1500
|
-
risk_weights: list[float], optional
|
1501
|
-
Risk target weights, default equal weight
|
1502
|
-
risk_parity_method: LiteralRiskParityMethod, default: ccd
|
1503
|
-
Risk parity estimation method
|
1504
|
-
maximum_iterations: int, default: 100
|
1505
|
-
Maximum iterations in iterative solutions
|
1506
|
-
tolerance: float, default: 1e-8
|
1507
|
-
Tolerance level in iterative solutions
|
1508
|
-
weight_bounds: tuple[float, float], default: (0.0, 1.0)
|
1509
|
-
Weigh limits for optimization
|
1510
|
-
riskfree: float, default: 0.0
|
1511
|
-
Risk-free rate used in utility calculation
|
1512
|
-
covar_method: LiteralCovMethod, default: ledoit-wolf
|
1513
|
-
Covariance matrix estimation method
|
1514
|
-
options: dict, optional
|
1515
|
-
options for minimizing, e.g. {'maxiter': 10000 }
|
1484
|
+
weight calculation strategies
|
1516
1485
|
|
1517
1486
|
Returns
|
1518
1487
|
-------
|
@@ -1538,32 +1507,9 @@ class OpenFrame(_CommonModel):
|
|
1538
1507
|
if weight_strat:
|
1539
1508
|
if weight_strat == "eq_weights":
|
1540
1509
|
self.weights = [1.0 / self.item_count] * self.item_count
|
1541
|
-
elif weight_strat == "eq_risk":
|
1542
|
-
weight_calc = list(
|
1543
|
-
calc_erc_weights(
|
1544
|
-
returns=dframe,
|
1545
|
-
initial_weights=initial_weights,
|
1546
|
-
risk_weights=risk_weights,
|
1547
|
-
risk_parity_method=risk_parity_method,
|
1548
|
-
maximum_iterations=maximum_iterations,
|
1549
|
-
tolerance=tolerance,
|
1550
|
-
),
|
1551
|
-
)
|
1552
|
-
self.weights = weight_calc
|
1553
1510
|
elif weight_strat == "inv_vol":
|
1554
1511
|
weight_calc = list(_calc_inv_vol_weights(returns=dframe))
|
1555
1512
|
self.weights = weight_calc
|
1556
|
-
elif weight_strat == "mean_var":
|
1557
|
-
weight_calc = list(
|
1558
|
-
calc_mean_var_weights(
|
1559
|
-
returns=dframe,
|
1560
|
-
weight_bounds=weight_bounds,
|
1561
|
-
rf=riskfree,
|
1562
|
-
covar_method=covar_method,
|
1563
|
-
options=options,
|
1564
|
-
),
|
1565
|
-
)
|
1566
|
-
self.weights = weight_calc
|
1567
1513
|
else:
|
1568
1514
|
msg = "Weight strategy not implemented"
|
1569
1515
|
raise NotImplementedError(msg)
|
@@ -1809,9 +1755,12 @@ def simulate_portfolios(
|
|
1809
1755
|
|
1810
1756
|
sharpe_arr[x] = ret_arr[x] / vol_arr[x]
|
1811
1757
|
|
1812
|
-
|
1758
|
+
# noinspection PyUnreachableCode
|
1813
1759
|
simdf = concat(
|
1814
|
-
[
|
1760
|
+
[
|
1761
|
+
DataFrame({"stdev": vol_arr, "ret": ret_arr, "sharpe": sharpe_arr}),
|
1762
|
+
DataFrame(all_weights, columns=simframe.columns_lvl_zero),
|
1763
|
+
],
|
1815
1764
|
axis="columns",
|
1816
1765
|
)
|
1817
1766
|
simdf = simdf.replace([inf, -inf], nan)
|
@@ -1878,9 +1827,9 @@ def efficient_frontier( # noqa: C901
|
|
1878
1827
|
return cast(float64, npsum(weights) - 1)
|
1879
1828
|
|
1880
1829
|
def _get_ret_vol_sr(
|
1881
|
-
|
1882
|
-
|
1883
|
-
|
1830
|
+
lg_ret: DataFrame,
|
1831
|
+
weights: NDArray[float64],
|
1832
|
+
per_in_yr: float,
|
1884
1833
|
) -> NDArray[float64]:
|
1885
1834
|
ret = npsum(lg_ret.mean() * weights) * per_in_yr
|
1886
1835
|
volatility = sqrt(dot(weights.T, dot(lg_ret.cov() * per_in_yr, weights)))
|
@@ -1888,10 +1837,10 @@ def efficient_frontier( # noqa: C901
|
|
1888
1837
|
return cast(NDArray[float64], array([ret, volatility, sr]))
|
1889
1838
|
|
1890
1839
|
def _diff_return(
|
1891
|
-
|
1892
|
-
|
1893
|
-
|
1894
|
-
|
1840
|
+
lg_ret: DataFrame,
|
1841
|
+
weights: NDArray[float64],
|
1842
|
+
per_in_yr: float,
|
1843
|
+
poss_return: float,
|
1895
1844
|
) -> float64:
|
1896
1845
|
return cast(
|
1897
1846
|
float64,
|
@@ -1972,9 +1921,12 @@ def efficient_frontier( # noqa: C901
|
|
1972
1921
|
frontier_x.append(result["fun"])
|
1973
1922
|
frontier_weights.append(result["x"])
|
1974
1923
|
|
1975
|
-
|
1924
|
+
# noinspection PyUnreachableCode
|
1976
1925
|
line_df = concat(
|
1977
|
-
[
|
1926
|
+
[
|
1927
|
+
DataFrame(data=frontier_weights, columns=eframe.columns_lvl_zero),
|
1928
|
+
DataFrame({"stdev": frontier_x, "ret": frontier_y}),
|
1929
|
+
],
|
1978
1930
|
axis="columns",
|
1979
1931
|
)
|
1980
1932
|
line_df["sharpe"] = line_df.ret / line_df.stdev
|
@@ -138,8 +138,6 @@ LiteralPlotlyOutput = Literal["file", "div"]
|
|
138
138
|
LiteralPlotlyJSlib = Literal[True, False, "cdn"]
|
139
139
|
LiteralOlsFitMethod = Literal["pinv", "qr"]
|
140
140
|
LiteralPortfolioWeightings = Literal["eq_weights", "eq_risk", "inv_vol", "mean_var"]
|
141
|
-
LiteralCovMethod = Literal["ledoit-wolf", "standard"]
|
142
|
-
LiteralRiskParityMethod = Literal["ccd", "slsqp"]
|
143
141
|
LiteralOlsFitCovType = Literal[
|
144
142
|
"nonrobust",
|
145
143
|
"fixed scale",
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[tool.poetry]
|
2
2
|
name = "openseries"
|
3
|
-
version = "1.5.
|
3
|
+
version = "1.5.1"
|
4
4
|
description = "Package for analyzing financial timeseries."
|
5
5
|
authors = ["Martin Karrin <martin.karrin@captor.se>"]
|
6
6
|
repository = "https://github.com/CaptorAB/OpenSeries"
|
@@ -34,28 +34,28 @@ keywords = [
|
|
34
34
|
|
35
35
|
[tool.poetry.dependencies]
|
36
36
|
python = ">=3.9,<3.13"
|
37
|
-
ffn = ">=1.0.0,<2.0.0"
|
38
37
|
holidays = ">=0.30,<1.0"
|
39
38
|
numpy = ">=1.23.2,<=2.0.0"
|
40
39
|
openpyxl = ">=3.1.2,<4.0.0"
|
41
40
|
pandas = ">=2.1.2,<3.0.0"
|
42
41
|
plotly = ">=5.18.0,<6.0.0"
|
43
|
-
pyarrow = ">=14.0.2,<
|
42
|
+
pyarrow = ">=14.0.2,<16.0.0"
|
44
43
|
pydantic = ">=2.5.2,<3.0.0"
|
45
44
|
python-dateutil = ">=2.8.2,<3.0.0"
|
45
|
+
requests = ">=2.20.0,<3.0.0"
|
46
46
|
scipy = ">=1.11.4,<2.0.0"
|
47
47
|
statsmodels = ">=0.14.0,<1.0.0"
|
48
48
|
|
49
49
|
[tool.poetry.group.dev.dependencies]
|
50
|
-
coverage = "^7.4.
|
50
|
+
coverage = "^7.4.4"
|
51
51
|
coverage-badge = "^1.1.0"
|
52
52
|
mypy = "^1.9.0"
|
53
|
-
pandas-stubs = "^2.2.
|
54
|
-
pre-commit = "^3.
|
53
|
+
pandas-stubs = "^2.2.1.240316"
|
54
|
+
pre-commit = "^3.7.0"
|
55
55
|
pytest = "^8.1.1"
|
56
|
-
ruff = "^0.3.
|
56
|
+
ruff = "^0.3.4"
|
57
57
|
types-openpyxl = "^3.1.0.20240311"
|
58
|
-
types-python-dateutil = "^2.
|
58
|
+
types-python-dateutil = "^2.9.0.20240316"
|
59
59
|
types-requests = "^2.31.0.20240311"
|
60
60
|
|
61
61
|
[build-system]
|
@@ -71,8 +71,6 @@ path = "venv"
|
|
71
71
|
|
72
72
|
[tool.pytest.ini_options]
|
73
73
|
filterwarnings = [
|
74
|
-
# https://github.com/pydata/pandas-datareader/issues/960
|
75
|
-
"ignore::DeprecationWarning:pandas_datareader.*:",
|
76
74
|
"ignore::RuntimeWarning:pandas.*:"
|
77
75
|
]
|
78
76
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|