pwb-toolbox 0.1.10__tar.gz → 0.1.11__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.
Files changed (29) hide show
  1. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/PKG-INFO +1 -1
  2. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox/backtest/engine.py +11 -1
  3. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox/datasets/__init__.py +26 -16
  4. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox.egg-info/PKG-INFO +1 -1
  5. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/setup.cfg +1 -1
  6. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/LICENSE.txt +0 -0
  7. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/README.md +0 -0
  8. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox/__init__.py +0 -0
  9. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox/backtest/__init__.py +0 -0
  10. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox/backtest/base_strategy.py +0 -0
  11. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox/backtest/ib_connector.py +0 -0
  12. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox/backtest/portfolio.py +0 -0
  13. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox/backtest/universe.py +0 -0
  14. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox/performance/__init__.py +0 -0
  15. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox/performance/metrics.py +0 -0
  16. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox/performance/plots.py +0 -0
  17. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox/performance/trade_stats.py +0 -0
  18. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox.egg-info/SOURCES.txt +0 -0
  19. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox.egg-info/dependency_links.txt +0 -0
  20. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox.egg-info/requires.txt +0 -0
  21. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pwb_toolbox.egg-info/top_level.txt +0 -0
  22. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/pyproject.toml +0 -0
  23. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/tests/test_backtest.py +0 -0
  24. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/tests/test_execution_models.py +0 -0
  25. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/tests/test_hf_token.py +0 -0
  26. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/tests/test_ib_connector.py +0 -0
  27. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/tests/test_portfolio_models.py +0 -0
  28. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/tests/test_risk_models.py +0 -0
  29. {pwb_toolbox-0.1.10 → pwb_toolbox-0.1.11}/tests/test_universe_models.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pwb-toolbox
3
- Version: 0.1.10
3
+ Version: 0.1.11
4
4
  Summary: A toolbox library for quant traders
5
5
  Home-page: https://github.com/paperswithbacktest/pwb-toolbox
6
6
  Author: Your Name
@@ -3,7 +3,16 @@ import pandas as pd
3
3
  import pwb_toolbox.datasets as pwb_ds
4
4
 
5
5
 
6
- def run_strategy(signal, signal_kwargs, portfolio, symbols, start_date, leverage, cash):
6
+ def run_strategy(
7
+ signal,
8
+ signal_kwargs,
9
+ portfolio,
10
+ portfolio_kwargs,
11
+ symbols,
12
+ start_date,
13
+ leverage,
14
+ cash,
15
+ ):
7
16
  """Run a tactical asset allocation strategy with Backtrader."""
8
17
  # Load the data from https://paperswithbacktest.com/datasets
9
18
  pivot_df = pwb_ds.get_pricing(
@@ -27,6 +36,7 @@ def run_strategy(signal, signal_kwargs, portfolio, symbols, start_date, leverage
27
36
  leverage=0.9,
28
37
  signal_cls=signal,
29
38
  signal_kwargs=signal_kwargs,
39
+ **portfolio_kwargs,
30
40
  )
31
41
  cerebro.broker.set_cash(cash)
32
42
  strategy = cerebro.run()[0]
@@ -921,6 +921,9 @@ def get_pricing(
921
921
  fields = ["close"]
922
922
  if isinstance(symbol_list, str):
923
923
  symbol_list = [symbol_list]
924
+ if isinstance(symbol_list, list) and "sp500" in symbol_list:
925
+ symbol_list.remove("sp500")
926
+ symbol_list += SP500_SYMBOLS
924
927
 
925
928
  fields = [f.lower() for f in fields]
926
929
  bad = [f for f in fields if f not in ALLOWED_FIELDS]
@@ -928,25 +931,32 @@ def get_pricing(
928
931
  raise ValueError(f"Invalid field(s): {bad}. Allowed: {sorted(ALLOWED_FIELDS)}")
929
932
 
930
933
  # --------------------------------------------------------------- download
931
- DATASETS = [
932
- ("Stocks-Daily-Price", extend),
933
- ("ETFs-Daily-Price", extend),
934
- ("Cryptocurrencies-Daily-Price", extend),
935
- ("Bonds-Daily-Price", extend),
936
- ("Commodities-Daily-Price", extend),
937
- ("Forex-Daily-Price", extend),
938
- ("Indices-Daily-Price", False), # indices generally have no proxy data
939
- ]
940
- remaining = set(symbol_list) # symbols still to fetch
934
+ universe = ds.load_dataset(
935
+ "paperswithbacktest/Universe-Daily-Price",
936
+ token=_get_hf_token(),
937
+ )
938
+ mapping = universe["train"].to_pandas()
939
+ mapping = mapping.set_index("symbol")["repo_id"].to_dict()
940
+
941
+ grouped = defaultdict(list)
942
+ remaining = []
943
+ for sym in symbol_list:
944
+ repo_id = mapping.get(sym)
945
+ repo_id = repo_id.split("/")[1] if isinstance(repo_id, str) else None
946
+ if repo_id:
947
+ grouped[repo_id].append(sym)
948
+ else:
949
+ print(f"Warning: No dataset found for symbol '{sym}'")
950
+ remaining.append(sym)
951
+
941
952
  frames = []
942
- for dataset_name, ext_flag in DATASETS:
943
- if not remaining: # all symbols resolved stop early
944
- break
945
- df_part = load_dataset(dataset_name, list(remaining), extend=ext_flag)
953
+ for repo_id, syms in grouped.items():
954
+ ext_flag = extend if repo_id != "Indices-Daily-Price" else False
955
+ df_part = load_dataset(repo_id, syms, extend=ext_flag)
946
956
  if not df_part.empty:
947
957
  frames.append(df_part)
948
- remaining -= set(df_part["symbol"].unique())
949
- df = pd.concat(frames, ignore_index=True)
958
+
959
+ df = pd.concat(frames, ignore_index=True) if frames else pd.DataFrame()
950
960
 
951
961
  df["date"] = pd.to_datetime(df["date"])
952
962
  df.set_index("date", inplace=True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pwb-toolbox
3
- Version: 0.1.10
3
+ Version: 0.1.11
4
4
  Summary: A toolbox library for quant traders
5
5
  Home-page: https://github.com/paperswithbacktest/pwb-toolbox
6
6
  Author: Your Name
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = pwb-toolbox
3
- version = 0.1.10
3
+ version = 0.1.11
4
4
  author = Your Name
5
5
  author_email = hello@paperswithbacktest.com
6
6
  description = A toolbox library for quant traders
File without changes
File without changes