cryptodatapy 0.2.26__py3-none-any.whl → 0.2.27__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.
@@ -1,5 +1,55 @@
1
1
  import pandas as pd
2
2
 
3
+ from tests.test_impute import filtered_data
4
+
5
+
6
+ def compute_reference_price(List: pd.DataFrame,
7
+ method: str = 'median',
8
+ trim_pct: float = 0.25,
9
+ ) -> pd.DataFrame:
10
+ """
11
+ Computes the consensus price from a list of dataframes.
12
+
13
+ Parameters
14
+ ----------
15
+ List: pd.DataFrame
16
+ List of dataframes containing price data.
17
+ method: str, optional
18
+ Method to compute the consensus price. Options are 'median' or 'trimmed_mean'.
19
+ Default is 'median'.
20
+ trim_pct: float, optional
21
+ Percentage of data to trim from both ends for 'trimmed_mean' method.
22
+ Default is 0.25 (25%).
23
+ Returns
24
+ -------
25
+ pd.DataFrame
26
+ Dataframe with the consensus price.
27
+ """
28
+ if not List:
29
+ raise ValueError("The input list is empty.")
30
+
31
+ # Concatenate all dataframes in the list
32
+ stacked_df = pd.concat(List)
33
+
34
+ # Compute consensus price based on the specified method
35
+ if method == 'median':
36
+ consensus_price = stacked_df.groupby(['date', 'ticker']).median()
37
+
38
+ elif method == 'trimmed_mean':
39
+ # Calculate trimmed mean with specified bounds
40
+ lower_bound = stacked_df.groupby(level=[0, 1]).quantile(trim_pct)
41
+ upper_bound = stacked_df.groupby(level=[0, 1]).quantile(1 - trim_pct)
42
+
43
+ # Filter out values outside the bounds
44
+ filtered_df = stacked_df[(stacked_df >= lower_bound.reindex(stacked_df.index)) &
45
+ (stacked_df <= upper_bound.reindex(stacked_df.index))]
46
+
47
+ consensus_price = filtered_df.groupby(level=[0, 1]).mean()
48
+ else:
49
+ raise ValueError("Method must be either 'median' or 'trimmed_mean'.")
50
+
51
+ return consensus_price.sort_index()
52
+
3
53
 
4
54
  def stitch_dataframes(df1: pd.DataFrame, df2: pd.DataFrame) -> pd.DataFrame:
5
55
  """
@@ -53,7 +103,6 @@ def rebase_fx_to_foreign_vs_usd(df) -> pd.DataFrame:
53
103
  raise ValueError(f"Unexpected ticker format: {ticker}")
54
104
 
55
105
  if isinstance(df.index, pd.MultiIndex):
56
- # MultiIndex: (date, ticker)
57
106
  tickers = df.index.get_level_values(1)
58
107
  inverted = tickers.str.startswith("USD")
59
108
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: cryptodatapy
3
- Version: 0.2.26
3
+ Version: 0.2.27
4
4
  Summary: Cryptoasset data library
5
5
  License: Apache-2.0
6
6
  Author: Systamental
@@ -57,8 +57,8 @@ cryptodatapy/transform/wrangle.py,sha256=cQOkPoiOmQtC7d2G15jMbMJSbinMmLYxM6Or7Ff
57
57
  cryptodatapy/util/__init__.py,sha256=zSQ2HU2QIXzCuptJjknmrClwtQKCvIj4aNysZljIgrU,116
58
58
  cryptodatapy/util/datacatalog.py,sha256=qCCX6srXvaAbVAKuA0M2y5IK_2OEx5xA3yRahDZlC-g,13157
59
59
  cryptodatapy/util/datacredentials.py,sha256=BnoQlUchbP0vfXqXRuhCOOsHyUTMuH5T4RAKBbHzMyo,3140
60
- cryptodatapy/util/utils.py,sha256=e71wm9F-6lXwODcdcHlxwR6t3RS582ibLM047rvcTO8,2434
61
- cryptodatapy-0.2.26.dist-info/LICENSE,sha256=sw4oVq8bDjT3uMtaFebQ-xeIVP4H-bXldTs9q-Jjeks,11344
62
- cryptodatapy-0.2.26.dist-info/METADATA,sha256=hhVFvFVTNwP3PTKIV4fUKFB_Od2imABceznnVDiSRMw,6473
63
- cryptodatapy-0.2.26.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
64
- cryptodatapy-0.2.26.dist-info/RECORD,,
60
+ cryptodatapy/util/utils.py,sha256=CqxFkaNNuOwA8RLz-G11bZ0jn3rcZfwEvKBkU0GDUDA,4164
61
+ cryptodatapy-0.2.27.dist-info/LICENSE,sha256=sw4oVq8bDjT3uMtaFebQ-xeIVP4H-bXldTs9q-Jjeks,11344
62
+ cryptodatapy-0.2.27.dist-info/METADATA,sha256=MVJocFDsV4nFpRTr7Tr_Pg7ydNIiFT6D_Anu6oZmfZ4,6473
63
+ cryptodatapy-0.2.27.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
64
+ cryptodatapy-0.2.27.dist-info/RECORD,,