pwb-toolbox 0.1.2__py3-none-any.whl → 0.1.4__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.
@@ -861,36 +861,82 @@ def __extend_etfs(df_etfs):
861
861
  return df
862
862
 
863
863
 
864
+ ALLOWED_FIELDS = {"open", "high", "low", "close"}
865
+
866
+
864
867
  def get_pricing(
865
868
  symbol_list,
866
- fields=["close"],
869
+ fields=None, # ← default set below
867
870
  start_date="1980-01-01",
868
871
  end_date=date.today().isoformat(),
872
+ extend=False,
873
+ keep_single_level=True, # backward-compat flag
869
874
  ):
870
875
  """
871
- Get pricing data for a list of symbols
876
+ Fetch OHLC pricing for the requested symbols.
877
+
878
+ Parameters
879
+ ----------
880
+ symbol_list : str | list[str]
881
+ One ticker or a list of tickers.
882
+ fields : list[str] | None
883
+ Any subset of ["open", "high", "low", "close"].
884
+ Defaults to ["close"] for backward compatibility.
885
+ start_date, end_date : str (YYYY-MM-DD)
886
+ Slice the date index (inclusive).
887
+ extend : bool
888
+ Pass-through to `load_dataset(..., extend=extend)`.
889
+ keep_single_level : bool
890
+ If `True` and only one field is requested, flatten the columns so the
891
+ output matches the old behaviour (columns = symbols). If `False`
892
+ you always get a two-level MultiIndex `(symbol, field)`.
893
+
894
+ Returns
895
+ -------
896
+ pd.DataFrame
897
+ * MultiIndex columns (symbol, field) when `len(fields) > 1`
898
+ * Single-level columns (symbol) when one field & keep_single_level=True
872
899
  """
900
+ # ------------------------------------------------------------------ sanity
901
+ if fields is None:
902
+ fields = ["close"]
873
903
  if isinstance(symbol_list, str):
874
904
  symbol_list = [symbol_list]
875
- if len(fields) != 1:
876
- raise ValueError("Only one field is allowed")
877
- if fields[0] not in ["open", "high", "low", "close"]:
878
- raise ValueError("Invalid field")
905
+
906
+ fields = [f.lower() for f in fields]
907
+ bad = [f for f in fields if f not in ALLOWED_FIELDS]
908
+ if bad:
909
+ raise ValueError(f"Invalid field(s): {bad}. Allowed: {sorted(ALLOWED_FIELDS)}")
910
+
911
+ # --------------------------------------------------------------- download
879
912
  df = pd.concat(
880
913
  [
881
- load_dataset("Stocks-Daily-Price", symbol_list),
882
- load_dataset("ETFs-Daily-Price", symbol_list),
883
- load_dataset("Cryptocurrencies-Daily-Price", symbol_list),
884
- load_dataset("Bonds-Daily-Price", symbol_list),
885
- load_dataset("Commodities-Daily-Price", symbol_list),
886
- ]
914
+ load_dataset("Stocks-Daily-Price", symbol_list, extend=extend),
915
+ load_dataset("ETFs-Daily-Price", symbol_list, extend=extend),
916
+ load_dataset("Cryptocurrencies-Daily-Price", symbol_list, extend=extend),
917
+ load_dataset("Bonds-Daily-Price", symbol_list, extend=extend),
918
+ load_dataset("Commodities-Daily-Price", symbol_list, extend=extend),
919
+ ],
920
+ ignore_index=True,
887
921
  )
922
+
888
923
  df["date"] = pd.to_datetime(df["date"])
889
924
  df.set_index("date", inplace=True)
890
925
  df.sort_index(inplace=True)
891
- df_filtered = df.loc[start_date:end_date]
892
- prices_df = df_filtered.pivot_table(
893
- values="close", index=df_filtered.index, columns="symbol"
894
- )
895
- prices_df.columns = list(prices_df.columns)
896
- return prices_df
926
+ df = df.loc[start_date:end_date]
927
+
928
+ # ------------------------------------------------------------- reshape
929
+ # Pivot can accept a list of values: returns columns = (field, symbol)
930
+ prices = df.pivot_table(values=fields, index=df.index, columns="symbol")
931
+
932
+ # Make outer level = symbol, inner = field → pivot_df[sym] gives OHLC block
933
+ prices = prices.swaplevel(axis=1).sort_index(axis=1)
934
+
935
+ # Optional: flatten back to the legacy layout if only one field requested
936
+ if keep_single_level and len(fields) == 1:
937
+ field = fields[0]
938
+ prices.columns = prices.columns.droplevel(1) # keep only the symbol names
939
+ # optional: rename index level for clarity
940
+ prices.name = field
941
+
942
+ return prices
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: pwb-toolbox
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: A toolbox library for quant traders
5
5
  Home-page: https://github.com/paperswithbacktest/pwb-toolbox
6
6
  Author: Your Name
@@ -14,6 +14,7 @@ Description-Content-Type: text/markdown
14
14
  License-File: LICENSE.txt
15
15
  Requires-Dist: datasets
16
16
  Requires-Dist: pandas
17
+ Dynamic: license-file
17
18
 
18
19
  <div align="center">
19
20
  <img src="static/images/systematic-trading.jpeg" height=200 alt=""/>
@@ -0,0 +1,7 @@
1
+ pwb_toolbox/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ pwb_toolbox/datasets/__init__.py,sha256=drj-jY3HSxYp8o1X8-hYbDvaHzuVR4JRumrXq-_CQFk,21668
3
+ pwb_toolbox-0.1.4.dist-info/licenses/LICENSE.txt,sha256=_Wjz7o7St3iVSPBRzE0keS8XSqSJ03A3NZ6cMlTaSK8,1079
4
+ pwb_toolbox-0.1.4.dist-info/METADATA,sha256=ai7OJKVjtSVmZbjZFH_dbqSD5pebe57j_xCw1yhAt20,4617
5
+ pwb_toolbox-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ pwb_toolbox-0.1.4.dist-info/top_level.txt,sha256=TZcXcF2AMkKkibZOuq6AYsHjajPgddHAGjQUT64OYGY,12
7
+ pwb_toolbox-0.1.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,7 +0,0 @@
1
- pwb_toolbox/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- pwb_toolbox/datasets/__init__.py,sha256=mR_gTpvdz_EmsEUtV4EOE-xxkwLMb54lgZXTgGw7_NQ,19813
3
- pwb_toolbox-0.1.2.dist-info/LICENSE.txt,sha256=_Wjz7o7St3iVSPBRzE0keS8XSqSJ03A3NZ6cMlTaSK8,1079
4
- pwb_toolbox-0.1.2.dist-info/METADATA,sha256=HXAh6eJ_W2-jdGicQY6r2R_xa9tdtC1EQARZ_QV8624,4595
5
- pwb_toolbox-0.1.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
6
- pwb_toolbox-0.1.2.dist-info/top_level.txt,sha256=TZcXcF2AMkKkibZOuq6AYsHjajPgddHAGjQUT64OYGY,12
7
- pwb_toolbox-0.1.2.dist-info/RECORD,,