pwb-toolbox 0.1.2__tar.gz → 0.1.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.
- {pwb_toolbox-0.1.2 → pwb_toolbox-0.1.4}/PKG-INFO +3 -2
- {pwb_toolbox-0.1.2 → pwb_toolbox-0.1.4}/pwb_toolbox/datasets/__init__.py +64 -18
- {pwb_toolbox-0.1.2 → pwb_toolbox-0.1.4}/pwb_toolbox.egg-info/PKG-INFO +3 -2
- {pwb_toolbox-0.1.2 → pwb_toolbox-0.1.4}/setup.cfg +1 -1
- {pwb_toolbox-0.1.2 → pwb_toolbox-0.1.4}/LICENSE.txt +0 -0
- {pwb_toolbox-0.1.2 → pwb_toolbox-0.1.4}/README.md +0 -0
- {pwb_toolbox-0.1.2 → pwb_toolbox-0.1.4}/pwb_toolbox/__init__.py +0 -0
- {pwb_toolbox-0.1.2 → pwb_toolbox-0.1.4}/pwb_toolbox.egg-info/SOURCES.txt +0 -0
- {pwb_toolbox-0.1.2 → pwb_toolbox-0.1.4}/pwb_toolbox.egg-info/dependency_links.txt +0 -0
- {pwb_toolbox-0.1.2 → pwb_toolbox-0.1.4}/pwb_toolbox.egg-info/requires.txt +0 -0
- {pwb_toolbox-0.1.2 → pwb_toolbox-0.1.4}/pwb_toolbox.egg-info/top_level.txt +0 -0
- {pwb_toolbox-0.1.2 → pwb_toolbox-0.1.4}/pyproject.toml +0 -0
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: pwb-toolbox
|
3
|
-
Version: 0.1.
|
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=""/>
|
@@ -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=
|
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
|
-
|
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
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
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
|
-
|
892
|
-
|
893
|
-
|
894
|
-
)
|
895
|
-
|
896
|
-
|
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.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: pwb-toolbox
|
3
|
-
Version: 0.1.
|
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=""/>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|