openseries 1.5.3__tar.gz → 1.5.4__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.1
2
2
  Name: openseries
3
- Version: 1.5.3
3
+ Version: 1.5.4
4
4
  Summary: Tools for analyzing financial timeseries.
5
5
  Home-page: https://github.com/CaptorAB/openseries
6
6
  License: BSD-3-Clause
@@ -53,7 +53,7 @@ width="81" height="100" align="left" float="right"/><br/>
53
53
  [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://beta.ruff.rs/docs/)
54
54
  [![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
55
55
 
56
- `openseries` is a project with tools to analyse financial timeseries of a single
56
+ This is a project with tools to analyze financial timeseries of a single
57
57
  asset or a group of assets. It is solely made for daily or less frequent data.
58
58
 
59
59
  <span style="font-size:2em;">[CHANGELOG](https://github.com/CaptorAB/openseries/blob/master/CHANGELOG.md)</span>
@@ -329,6 +329,7 @@ make lint
329
329
  | `downside_deviation` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | [Downside deviation](https://www.investopedia.com/terms/d/downside-deviation.asp) is the volatility of all negative return observations. Minimum Accepted Return (MAR) set to zero. |
330
330
  | `ret_vol_ratio` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | Ratio of arithmetic mean return and annualized volatility. It is the [Sharpe Ratio](https://www.investopedia.com/terms/s/sharperatio.asp) with the riskfree rate set to zero. |
331
331
  | `sortino_ratio` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | The [Sortino Ratio](https://www.investopedia.com/terms/s/sortinoratio.asp) is the arithmetic mean return divided by the downside deviation. This attribute assumes that the riskfree rate and the MAR are both zero. |
332
+ | `omega_ratio` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | The [Omega Ratio](https://en.wikipedia.org/wiki/Omega_ratio) compares returns above a certain target level (MAR) to the total downside risk below MAR. |
332
333
  | `var_down` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | Downside 95% [Value At Risk](https://www.investopedia.com/terms/v/var.asp), "VaR". The equivalent of percentile.inc([...], 1-level) over returns in MS Excel. For other confidence levels use the corresponding method. |
333
334
  | `cvar_down` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | Downside 95% [Conditional Value At Risk](https://www.investopedia.com/terms/c/conditional_value_at_risk.asp), "CVaR". For other confidence levels use the corresponding method. |
334
335
  | `worst` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | Most negative percentage change of a single observation. |
@@ -355,6 +356,7 @@ properties for subset periods._
355
356
  | `downside_deviation_func` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | [Downside deviation](https://www.investopedia.com/terms/d/downside-deviation.asp) is the volatility of all negative return observations. MAR and riskfree rate can be set. |
356
357
  | `ret_vol_ratio_func` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | Ratio of arithmetic mean return and annualized volatility. It is the [Sharpe Ratio](https://www.investopedia.com/terms/s/sharperatio.asp) with the riskfree rate set to zero. A riskfree rate can be set as a float or a series chosen for the frame function. |
357
358
  | `sortino_ratio_func` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | The [Sortino Ratio](https://www.investopedia.com/terms/s/sortinoratio.asp) is the arithmetic mean return divided by the downside deviation. A riskfree rate can be set as a float or a series chosen for the frame function. MAR is set to zero. |
359
+ | `omega_ratio_func` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | The [Omega Ratio](https://en.wikipedia.org/wiki/Omega_ratio) compares returns above a certain target level (MAR) to the total downside risk below MAR. |
358
360
  | `var_down_func` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | Downside 95% [Value At Risk](https://www.investopedia.com/terms/v/var.asp), "VaR". The equivalent of percentile.inc([...], 1-level) over returns in MS Excel. Default is 95% confidence level. |
359
361
  | `cvar_down_func` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | Downside 95% [Conditional Value At Risk](https://www.investopedia.com/terms/c/conditional_value_at_risk.asp), "CVaR". Default is 95% confidence level. |
360
362
  | `worst_func` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | Most negative percentage change for a given number of observations (default=1). |
@@ -17,7 +17,7 @@ width="81" height="100" align="left" float="right"/><br/>
17
17
  [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://beta.ruff.rs/docs/)
18
18
  [![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
19
19
 
20
- `openseries` is a project with tools to analyse financial timeseries of a single
20
+ This is a project with tools to analyze financial timeseries of a single
21
21
  asset or a group of assets. It is solely made for daily or less frequent data.
22
22
 
23
23
  <span style="font-size:2em;">[CHANGELOG](https://github.com/CaptorAB/openseries/blob/master/CHANGELOG.md)</span>
@@ -293,6 +293,7 @@ make lint
293
293
  | `downside_deviation` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | [Downside deviation](https://www.investopedia.com/terms/d/downside-deviation.asp) is the volatility of all negative return observations. Minimum Accepted Return (MAR) set to zero. |
294
294
  | `ret_vol_ratio` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | Ratio of arithmetic mean return and annualized volatility. It is the [Sharpe Ratio](https://www.investopedia.com/terms/s/sharperatio.asp) with the riskfree rate set to zero. |
295
295
  | `sortino_ratio` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | The [Sortino Ratio](https://www.investopedia.com/terms/s/sortinoratio.asp) is the arithmetic mean return divided by the downside deviation. This attribute assumes that the riskfree rate and the MAR are both zero. |
296
+ | `omega_ratio` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | The [Omega Ratio](https://en.wikipedia.org/wiki/Omega_ratio) compares returns above a certain target level (MAR) to the total downside risk below MAR. |
296
297
  | `var_down` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | Downside 95% [Value At Risk](https://www.investopedia.com/terms/v/var.asp), "VaR". The equivalent of percentile.inc([...], 1-level) over returns in MS Excel. For other confidence levels use the corresponding method. |
297
298
  | `cvar_down` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | Downside 95% [Conditional Value At Risk](https://www.investopedia.com/terms/c/conditional_value_at_risk.asp), "CVaR". For other confidence levels use the corresponding method. |
298
299
  | `worst` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | Most negative percentage change of a single observation. |
@@ -319,6 +320,7 @@ properties for subset periods._
319
320
  | `downside_deviation_func` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | [Downside deviation](https://www.investopedia.com/terms/d/downside-deviation.asp) is the volatility of all negative return observations. MAR and riskfree rate can be set. |
320
321
  | `ret_vol_ratio_func` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | Ratio of arithmetic mean return and annualized volatility. It is the [Sharpe Ratio](https://www.investopedia.com/terms/s/sharperatio.asp) with the riskfree rate set to zero. A riskfree rate can be set as a float or a series chosen for the frame function. |
321
322
  | `sortino_ratio_func` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | The [Sortino Ratio](https://www.investopedia.com/terms/s/sortinoratio.asp) is the arithmetic mean return divided by the downside deviation. A riskfree rate can be set as a float or a series chosen for the frame function. MAR is set to zero. |
323
+ | `omega_ratio_func` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | The [Omega Ratio](https://en.wikipedia.org/wiki/Omega_ratio) compares returns above a certain target level (MAR) to the total downside risk below MAR. |
322
324
  | `var_down_func` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | Downside 95% [Value At Risk](https://www.investopedia.com/terms/v/var.asp), "VaR". The equivalent of percentile.inc([...], 1-level) over returns in MS Excel. Default is 95% confidence level. |
323
325
  | `cvar_down_func` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | Downside 95% [Conditional Value At Risk](https://www.investopedia.com/terms/c/conditional_value_at_risk.asp), "CVaR". Default is 95% confidence level. |
324
326
  | `worst_func` | `float`, `pandas.Series` | `OpenTimeSeries`, `OpenFrame` | Most negative percentage change for a given number of observations (default=1). |
@@ -163,7 +163,7 @@ class _CommonModel(BaseModel):
163
163
  return Series(
164
164
  data=mddc,
165
165
  index=self.tsdf.columns,
166
- name="Max Drawdown in cal yr",
166
+ name="Max drawdown in cal yr",
167
167
  dtype="float64",
168
168
  )
169
169
 
@@ -275,6 +275,20 @@ class _CommonModel(BaseModel):
275
275
  min_accepted_return=minimum_accepted_return,
276
276
  )
277
277
 
278
+ @property
279
+ def omega_ratio(self: Self) -> Union[float, Series[float]]:
280
+ """
281
+ https://en.wikipedia.org/wiki/Omega_ratio.
282
+
283
+ Returns
284
+ -------
285
+ Union[float, Pandas.Series[float]]
286
+ Omega ratio calculation
287
+
288
+ """
289
+ minimum_accepted_return: float = 0.0
290
+ return self.omega_ratio_func(min_accepted_return=minimum_accepted_return)
291
+
278
292
  @property
279
293
  def z_score(self: Self) -> Union[float, Series[float]]:
280
294
  """
@@ -1679,7 +1693,7 @@ class _CommonModel(BaseModel):
1679
1693
  return Series(
1680
1694
  data=result,
1681
1695
  index=self.tsdf.columns,
1682
- name="Max Drawdown",
1696
+ name="Max drawdown",
1683
1697
  dtype="float64",
1684
1698
  )
1685
1699
 
@@ -1735,7 +1749,7 @@ class _CommonModel(BaseModel):
1735
1749
  return Series(
1736
1750
  data=share,
1737
1751
  index=self.tsdf.columns,
1738
- name="Positive Share",
1752
+ name="Positive share",
1739
1753
  dtype="float64",
1740
1754
  )
1741
1755
 
@@ -1869,6 +1883,60 @@ class _CommonModel(BaseModel):
1869
1883
  dtype="float64",
1870
1884
  )
1871
1885
 
1886
+ def omega_ratio_func(
1887
+ self: Self,
1888
+ min_accepted_return: float = 0.0,
1889
+ months_from_last: Optional[int] = None,
1890
+ from_date: Optional[dt.date] = None,
1891
+ to_date: Optional[dt.date] = None,
1892
+ ) -> Union[float, Series[float]]:
1893
+ """
1894
+ Omega Ratio.
1895
+
1896
+ The Omega Ratio compares returns above a certain target level
1897
+ (often referred to as the “minimum acceptable return” or “MAR”)
1898
+ to the total downside risk below that same threshold.
1899
+ https://en.wikipedia.org/wiki/Omega_ratio.
1900
+
1901
+ Parameters
1902
+ ----------
1903
+ min_accepted_return : float, optional
1904
+ The annualized Minimum Accepted Return (MAR)
1905
+ months_from_last : int, optional
1906
+ number of months offset as positive integer. Overrides use of from_date
1907
+ and to_date
1908
+ from_date : datetime.date, optional
1909
+ Specific from date
1910
+ to_date : datetime.date, optional
1911
+ Specific to date
1912
+
1913
+ Returns
1914
+ -------
1915
+ Union[float, Pandas.Series[float]]
1916
+ Omega ratio calculation
1917
+
1918
+ """
1919
+ earlier, later = self.calc_range(
1920
+ months_offset=months_from_last,
1921
+ from_dt=from_date,
1922
+ to_dt=to_date,
1923
+ )
1924
+ retdf = self.tsdf.loc[cast(int, earlier) : cast(int, later)].pct_change(
1925
+ fill_method=cast(str, None),
1926
+ )
1927
+ pos = retdf[retdf > min_accepted_return].sub(min_accepted_return).sum()
1928
+ neg = retdf[retdf < min_accepted_return].sub(min_accepted_return).sum()
1929
+ ratio = pos / -neg
1930
+
1931
+ if self.tsdf.shape[1] == 1:
1932
+ return float(cast(float64, ratio.iloc[0]))
1933
+ return Series(
1934
+ data=ratio,
1935
+ index=self.tsdf.columns,
1936
+ name="Omega ratio",
1937
+ dtype="float64",
1938
+ )
1939
+
1872
1940
  def value_ret_func(
1873
1941
  self: Self,
1874
1942
  months_from_last: Optional[int] = None,
@@ -7,6 +7,7 @@ from logging import warning
7
7
  from pathlib import Path
8
8
 
9
9
  import requests
10
+ from requests.exceptions import ConnectionError
10
11
 
11
12
  from openseries.types import CaptorLogoType, PlotlyLayoutType
12
13
 
@@ -32,7 +33,7 @@ def _check_remote_file_existence(url: str) -> bool:
32
33
  response = requests.head(url, timeout=30)
33
34
  if response.status_code != ok_code:
34
35
  return False
35
- except requests.exceptions.ConnectionError:
36
+ except ConnectionError:
36
37
  return False
37
38
  return True
38
39
 
@@ -59,9 +60,9 @@ def load_plotly_dict(
59
60
  layoutfile = project_root.joinpath("openseries").joinpath("plotly_layouts.json")
60
61
  logofile = project_root.joinpath("openseries").joinpath("plotly_captor_logo.json")
61
62
 
62
- with Path.open(layoutfile, encoding="utf-8") as layout_file:
63
+ with Path.open(layoutfile, mode="r", encoding="utf-8") as layout_file:
63
64
  fig = load(layout_file)
64
- with Path.open(logofile, encoding="utf-8") as logo_file:
65
+ with Path.open(logofile, mode="r", encoding="utf-8") as logo_file:
65
66
  logo = load(logo_file)
66
67
 
67
68
  if _check_remote_file_existence(url=logo["source"]) is False:
@@ -220,6 +220,7 @@ class OpenTimeSeriesPropertiesList(list[str]):
220
220
  "downside_deviation",
221
221
  "ret_vol_ratio",
222
222
  "sortino_ratio",
223
+ "omega_ratio",
223
224
  "z_score",
224
225
  "skew",
225
226
  "kurtosis",
@@ -276,6 +277,7 @@ class OpenFramePropertiesList(list[str]):
276
277
  "downside_deviation",
277
278
  "ret_vol_ratio",
278
279
  "sortino_ratio",
280
+ "omega_ratio",
279
281
  "z_score",
280
282
  "skew",
281
283
  "kurtosis",
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "openseries"
3
- version = "1.5.3"
3
+ version = "1.5.4"
4
4
  description = "Tools for analyzing financial timeseries."
5
5
  authors = ["Martin Karrin <martin.karrin@captor.se>"]
6
6
  repository = "https://github.com/CaptorAB/openseries"
@@ -47,13 +47,13 @@ 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.5.0"
50
+ coverage = "^7.5.1"
51
51
  coverage-badge = "^1.1.1"
52
52
  mypy = "^1.10.0"
53
53
  pandas-stubs = "^2.2.1.240316"
54
54
  pre-commit = "^3.7.0"
55
55
  pytest = "^8.2.0"
56
- ruff = "^0.4.2"
56
+ ruff = "^0.4.3"
57
57
  types-openpyxl = "^3.1.0.20240428"
58
58
  types-python-dateutil = "^2.9.0.20240316"
59
59
  types-requests = "^2.31.0.20240406"
File without changes