openseries 1.5.4__py3-none-any.whl → 1.5.6__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.
@@ -38,6 +38,7 @@ from openseries.types import (
38
38
  CountriesType,
39
39
  DaysInYearType,
40
40
  LiteralBarPlotMode,
41
+ LiteralJsonOutput,
41
42
  LiteralLinePlotMode,
42
43
  LiteralNanMethod,
43
44
  LiteralPlotlyJSlib,
@@ -651,16 +652,18 @@ class _CommonModel(BaseModel):
651
652
 
652
653
  def to_json(
653
654
  self: Self,
655
+ what_output: LiteralJsonOutput,
654
656
  filename: str,
655
657
  directory: Optional[DirectoryPath] = None,
656
658
  ) -> list[dict[str, Union[str, bool, ValueType, list[str], list[float]]]]:
657
659
  """
658
660
  Dump timeseries data into a json file.
659
661
 
660
- The label and tsdf parameters are deleted before the json file is saved
661
-
662
662
  Parameters
663
663
  ----------
664
+ what_output: LiteralJsonOutput
665
+ Choice on whether the raw values or the tsdf Dataframe values are
666
+ returned as json and exported as json file.
664
667
  filename: str
665
668
  Filename including filetype
666
669
  directory: DirectoryPath, optional
@@ -669,7 +672,7 @@ class _CommonModel(BaseModel):
669
672
  Returns
670
673
  -------
671
674
  list[Dict[str, Union[str, bool, ValueType, list[str], list[float]]]]
672
- A list of dictionaries with the raw original data of the series
675
+ A list of dictionaries with the data of the series
673
676
 
674
677
  """
675
678
  if directory:
@@ -683,21 +686,31 @@ class _CommonModel(BaseModel):
683
686
  data = dict(self.__dict__)
684
687
  output = []
685
688
  if "label" in data:
689
+ if what_output == "tsdf":
690
+ values = self.tsdf.iloc[:, 0].tolist()
691
+ else:
692
+ values = list(cast(list[float], data.get("values")))
686
693
  for item in cleaner_list:
687
694
  data.pop(item)
695
+ valuetype = cast(ValueType, data.get("valuetype")).value
696
+ data.update({"valuetype": valuetype})
697
+ data.update({"values": values})
688
698
  output.append(dict(data))
689
699
  else:
690
700
  for serie in cast(list[Any], data.get("constituents")):
701
+ if what_output == "tsdf":
702
+ values = serie.tsdf.iloc[:, 0].tolist()
703
+ else:
704
+ values = list(serie.values)
691
705
  itemdata = dict(serie.__dict__)
692
706
  for item in cleaner_list:
693
707
  itemdata.pop(item)
708
+ valuetype = cast(ValueType, itemdata["valuetype"]).value
709
+ itemdata.update({"valuetype": valuetype})
710
+ itemdata.update({"values": values})
694
711
  output.append(dict(itemdata))
695
712
 
696
- with Path.open(
697
- dirpath.joinpath(filename),
698
- "w",
699
- encoding="utf-8",
700
- ) as jsonfile:
713
+ with dirpath.joinpath(filename).open(mode="w", encoding="utf-8") as jsonfile:
701
714
  dump(output, jsonfile, indent=2, sort_keys=False)
702
715
 
703
716
  return output
openseries/datefixer.py CHANGED
@@ -62,7 +62,7 @@ def holiday_calendar(
62
62
  endyear += 1
63
63
  if startyear == endyear:
64
64
  endyear += 1
65
- years = list(range(startyear, endyear))
65
+ years = list(range(int(startyear), int(endyear)))
66
66
 
67
67
  if isinstance(countries, str) and countries in list_supported_countries():
68
68
  staging = country_holidays(country=countries, years=years)
@@ -412,9 +412,11 @@ def do_resample_to_business_period_ends(
412
412
  data.index = Index(d.date() for d in DatetimeIndex(data.index))
413
413
 
414
414
  if newhead.index[0] not in data.index:
415
+ # noinspection PyUnreachableCode
415
416
  data = concat([data, newhead])
416
417
 
417
418
  if newtail.index[0] not in data.index:
419
+ # noinspection PyUnreachableCode
418
420
  data = concat([data, newtail])
419
421
 
420
422
  data = data.sort_index()
openseries/types.py CHANGED
@@ -113,6 +113,7 @@ PlotlyLayoutType = dict[
113
113
 
114
114
  CaptorLogoType = dict[str, Union[str, float]]
115
115
 
116
+ LiteralJsonOutput = Literal["values", "tsdf"]
116
117
  LiteralTrunc = Literal["before", "after", "both"]
117
118
  LiteralLinePlotMode = Literal[
118
119
  "lines",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openseries
3
- Version: 1.5.4
3
+ Version: 1.5.6
4
4
  Summary: Tools for analyzing financial timeseries.
5
5
  Home-page: https://github.com/CaptorAB/openseries
6
6
  License: BSD-3-Clause
@@ -20,7 +20,7 @@ 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: holidays (>=0.30,<1.0)
23
+ Requires-Dist: holidays (>=0.30,<0.50)
24
24
  Requires-Dist: numpy (>=1.23.2,<=2.0.0)
25
25
  Requires-Dist: openpyxl (>=3.1.2,<4.0.0)
26
26
  Requires-Dist: pandas (>=2.1.2,<3.0.0)
@@ -302,7 +302,7 @@ make lint
302
302
  | `value_nan_handle` | `OpenTimeSeries`, `OpenFrame` | Fills `Nan` in a value series with the preceding non-Nan value. |
303
303
  | `return_nan_handle` | `OpenTimeSeries`, `OpenFrame` | Replaces `Nan` in a return series with a 0.0 `float`. |
304
304
  | `to_cumret` | `OpenTimeSeries`, `OpenFrame` | Converts a return series into a value series and/or resets a value series to be rebased from 1.0. |
305
- | `to_json` | `OpenTimeSeries`, `OpenFrame` | Method to export the raw unaltered data to a json file. |
305
+ | `to_json` | `OpenTimeSeries`, `OpenFrame` | Method to export object data to a json file. |
306
306
  | `to_xlsx` | `OpenTimeSeries`, `OpenFrame` | Method to save the data in the .tsdf DataFrame to an Excel file. |
307
307
  | `value_to_ret` | `OpenTimeSeries`, `OpenFrame` | Converts a value series into a percentage return series. |
308
308
  | `value_to_diff` | `OpenTimeSeries`, `OpenFrame` | Converts a value series into a series of differences. |
@@ -1,15 +1,15 @@
1
1
  openseries/__init__.py,sha256=W429Ojwa-wPgHV5PDAOQOBOAzPOR4wrVHRwdZQjRKcQ,41
2
- openseries/_common_model.py,sha256=ETr8vueNHrMC5dZGHP2V3DowIg-jzgmhdOwCI_4258M,74705
2
+ openseries/_common_model.py,sha256=gHJfvxsOjrjGnuoTm62LRYho_VeEhRKmbY9xM6tiRUk,75497
3
3
  openseries/_risk.py,sha256=4ckiA-0-uuoUOsuc_uElUA_2rLS_U3xJyiva2BX4W1s,3300
4
- openseries/datefixer.py,sha256=ZOSPp4kLkMEsZv50GQaSo2vAEDVaXEr9iX3wTO7ZdB4,12378
4
+ openseries/datefixer.py,sha256=DtluyFPfrnXTqRnSfYyNfAE4KzAOiFwgDW8bJM3NjBA,12470
5
5
  openseries/frame.py,sha256=SH1sPUFoJS71o2uVJBLoDl3rSC8AP7wQZw3baMD9T4U,74019
6
6
  openseries/load_plotly.py,sha256=L4A3Fa5Jk47FY7pcg0NPZ0gm0JD_uCXjVlGC7FWVSJg,1856
7
7
  openseries/plotly_captor_logo.json,sha256=F5nhMzEyxKywtjvQqMTKgKRCJQYMDIiBgDSxdte8Clo,178
8
8
  openseries/plotly_layouts.json,sha256=ahx8-dL4_RPzvHtBOX0SiL0AH7xQJzNRSDhGrSmU-Og,1429
9
9
  openseries/series.py,sha256=pIpiD3v8z7SyIppBatbsPuqOWCf3qI_us2145JnPUkQ,28313
10
10
  openseries/simulation.py,sha256=VYxc-e5VSyC55DdfACpQen-necYbhso-6RMyOhYX-5k,13905
11
- openseries/types.py,sha256=fSSg9hzQd9cTY8Q3MVdCOtoSu4zFxX4GSk6778LdCNo,7643
12
- openseries-1.5.4.dist-info/LICENSE.md,sha256=cPUabMxJ6-ziqzqS6aLGkR-ilIOKe_s3Qtyp0ioTmo0,1521
13
- openseries-1.5.4.dist-info/METADATA,sha256=JhTQclCLTBKzyUE3uD_P-Oa6Ayfu2pAgljK-yODn_YU,44222
14
- openseries-1.5.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
15
- openseries-1.5.4.dist-info/RECORD,,
11
+ openseries/types.py,sha256=yJmGZcBFwvMQQEaRVb0vhVMP463xu7MSydjWr12X38M,7689
12
+ openseries-1.5.6.dist-info/LICENSE.md,sha256=cPUabMxJ6-ziqzqS6aLGkR-ilIOKe_s3Qtyp0ioTmo0,1521
13
+ openseries-1.5.6.dist-info/METADATA,sha256=aE0BWMcUlTQgJxWNK52MCYkO9dFFccqzn4BpR6_R9bA,44223
14
+ openseries-1.5.6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
15
+ openseries-1.5.6.dist-info/RECORD,,