pwb-toolbox 0.1.1__py3-none-any.whl → 0.1.2__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,4 +1,5 @@
1
1
  from collections import defaultdict
2
+ from datetime import date
2
3
  import os
3
4
  import re
4
5
 
@@ -852,6 +853,44 @@ def __extend_etfs(df_etfs):
852
853
  combined_data = pd.concat([index_data_before_common, etf_data])
853
854
  frames.append(combined_data)
854
855
 
856
+ symbols_not_in_mapping = set(symbols) - set(mapping.keys())
857
+ frames.append(df_etfs[df_etfs["symbol"].isin(symbols_not_in_mapping)])
858
+
855
859
  # Concatenate all frames to form the final dataframe
856
860
  df = pd.concat(frames).sort_values(by=["date", "symbol"]).reset_index(drop=True)
857
861
  return df
862
+
863
+
864
+ def get_pricing(
865
+ symbol_list,
866
+ fields=["close"],
867
+ start_date="1980-01-01",
868
+ end_date=date.today().isoformat(),
869
+ ):
870
+ """
871
+ Get pricing data for a list of symbols
872
+ """
873
+ if isinstance(symbol_list, str):
874
+ 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")
879
+ df = pd.concat(
880
+ [
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
+ ]
887
+ )
888
+ df["date"] = pd.to_datetime(df["date"])
889
+ df.set_index("date", inplace=True)
890
+ 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
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: pwb-toolbox
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: A toolbox library for quant traders
5
5
  Home-page: https://github.com/paperswithbacktest/pwb-toolbox
6
6
  Author: Your Name
@@ -46,13 +46,15 @@ The `pwb-toolbox` package offers a range of functionalities for systematic tradi
46
46
  ```python
47
47
  import pwb_toolbox.datasets as pwb_ds
48
48
 
49
- df = ds.load_dataset("Bonds-Daily-Price")
50
- df = ds.load_dataset("Commodities-Daily-Price")
51
- df = ds.load_dataset("Cryptocurrencies-Daily-Price")
52
- df = ds.load_dataset("ETFs-Daily-Price")
53
- df = ds.load_dataset("Forex-Daily-Price")
54
- df = ds.load_dataset("Indices-Daily-Price")
55
- df = ds.load_dataset("Stocks-Daily-Price")
49
+ df = pwb_ds.get_pricing(["AAPL", "MSFT", "GOOGL"])
50
+ df = pwb_ds.load_dataset("Bonds-Daily-Price")
51
+ df = pwb_ds.load_dataset("Commodities-Daily-Price")
52
+ df = pwb_ds.load_dataset("Cryptocurrencies-Daily-Price")
53
+ df = pwb_ds.load_dataset("ETFs-Daily-Price")
54
+ df = pwb_ds.load_dataset("Forex-Daily-Price")
55
+ df = pwb_ds.load_dataset("Indices-Daily-Price")
56
+ df = pwb_ds.load_dataset("Stocks-Daily-Price")
57
+
56
58
  ```
57
59
 
58
60
  - Load daily stock price data for specific symbols using the load_dataset function. The first call retrieves data for Apple and Microsoft. The second call retrieves the same stocks but without price adjustments (`adjust=False`). The third call loads daily price data for the S&P 500 index:
@@ -130,6 +132,7 @@ To build the package, run:
130
132
 
131
133
  ```bash
132
134
  python -m pip install --upgrade build
135
+ rm -r dist
133
136
  python -m build
134
137
  ```
135
138
 
@@ -0,0 +1,7 @@
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,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.1.0)
2
+ Generator: setuptools (75.8.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=YGupxmXGcM_Q6QjFEvaQO_RwLSFrN46WhBfVDa-uF7c,18501
3
- pwb_toolbox-0.1.1.dist-info/LICENSE.txt,sha256=_Wjz7o7St3iVSPBRzE0keS8XSqSJ03A3NZ6cMlTaSK8,1079
4
- pwb_toolbox-0.1.1.dist-info/METADATA,sha256=Jl53c7wl36Cog8UQANNBHJsrAMemcyJjVwauIbU5D3w,4504
5
- pwb_toolbox-0.1.1.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
6
- pwb_toolbox-0.1.1.dist-info/top_level.txt,sha256=TZcXcF2AMkKkibZOuq6AYsHjajPgddHAGjQUT64OYGY,12
7
- pwb_toolbox-0.1.1.dist-info/RECORD,,