pwb-toolbox 0.1.5__py3-none-any.whl → 0.1.6__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.
- pwb_toolbox/datasets/__init__.py +51 -44
- {pwb_toolbox-0.1.5.dist-info → pwb_toolbox-0.1.6.dist-info}/METADATA +1 -1
- pwb_toolbox-0.1.6.dist-info/RECORD +7 -0
- pwb_toolbox-0.1.5.dist-info/RECORD +0 -7
- {pwb_toolbox-0.1.5.dist-info → pwb_toolbox-0.1.6.dist-info}/WHEEL +0 -0
- {pwb_toolbox-0.1.5.dist-info → pwb_toolbox-0.1.6.dist-info}/licenses/LICENSE.txt +0 -0
- {pwb_toolbox-0.1.5.dist-info → pwb_toolbox-0.1.6.dist-info}/top_level.txt +0 -0
pwb_toolbox/datasets/__init__.py
CHANGED
@@ -813,62 +813,68 @@ def __extend_etfs(df_etfs):
|
|
813
813
|
symbols = df_etfs.symbol.unique()
|
814
814
|
mapping = {k: v for k, v in mapping.items() if k in symbols}
|
815
815
|
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
816
|
+
# Nothing to extend → just return the input
|
817
|
+
if not mapping:
|
818
|
+
return df_etfs.copy()
|
819
|
+
|
820
|
+
# ------------------------------------------------------------------ step 2
|
821
|
+
grouped = defaultdict(list) # {path: [proxy1, proxy2, ...]}
|
822
|
+
for _, (path, proxy) in mapping.items():
|
823
|
+
grouped[path].append(proxy)
|
824
|
+
|
825
|
+
# Load each dataset only if there's at least one proxy symbol
|
826
|
+
other_frames = []
|
827
|
+
for path, proxies in grouped.items():
|
828
|
+
if proxies: # skip empty lists
|
829
|
+
other_frames.append(load_dataset(path, proxies, to_usd=True))
|
826
830
|
|
831
|
+
# If no proxy data could be loaded, fall back to raw ETF data
|
832
|
+
if not other_frames:
|
833
|
+
return df_etfs.copy()
|
834
|
+
|
835
|
+
df_others = pd.concat(other_frames, ignore_index=True)
|
836
|
+
|
837
|
+
# ------------------------------------------------------------------ step 3
|
827
838
|
frames = []
|
828
|
-
for etf,
|
829
|
-
other_symbol = other[1]
|
830
|
-
# Get the ETF & Index data
|
839
|
+
for etf, (__, proxy) in mapping.items():
|
831
840
|
etf_data = df_etfs[df_etfs["symbol"] == etf]
|
832
|
-
|
833
|
-
continue
|
834
|
-
other_data = df_others[df_others["symbol"] == other_symbol]
|
835
|
-
if other_data.empty:
|
836
|
-
continue
|
837
|
-
|
838
|
-
# Find the first overlapping date
|
839
|
-
common_dates = etf_data["date"].isin(other_data["date"])
|
840
|
-
first_common_date = etf_data.loc[common_dates, "date"].min()
|
841
|
+
proxy_data = df_others[df_others["symbol"] == proxy]
|
841
842
|
|
842
|
-
if
|
843
|
-
|
843
|
+
if etf_data.empty or proxy_data.empty:
|
844
|
+
frames.append(etf_data) # keep raw ETF if proxy missing
|
844
845
|
continue
|
845
846
|
|
846
|
-
|
847
|
-
|
847
|
+
# Find first overlapping date
|
848
|
+
first_common = etf_data.loc[
|
849
|
+
etf_data["date"].isin(proxy_data["date"]), "date"
|
850
|
+
].min()
|
851
|
+
if pd.isna(first_common):
|
852
|
+
frames.append(etf_data) # no overlap → keep raw ETF
|
853
|
+
continue
|
848
854
|
|
849
|
-
# Compute
|
850
|
-
|
851
|
-
|
855
|
+
# Compute adjustment factor on that date
|
856
|
+
k = (
|
857
|
+
etf_data.loc[etf_data["date"] == first_common, "close"].iloc[0]
|
858
|
+
/ proxy_data.loc[proxy_data["date"] == first_common, "close"].iloc[0]
|
852
859
|
)
|
853
860
|
|
854
|
-
#
|
855
|
-
|
856
|
-
|
857
|
-
]
|
858
|
-
for column in ["open", "high", "low", "close"]:
|
859
|
-
index_data_before_common.loc[:, column] *= adjustment_factor
|
860
|
-
index_data_before_common.loc[:, "symbol"] = etf
|
861
|
+
# Scale proxy history before the overlap
|
862
|
+
hist = proxy_data[proxy_data["date"] < first_common].copy()
|
863
|
+
hist[["open", "high", "low", "close"]] *= k
|
864
|
+
hist["symbol"] = etf
|
861
865
|
|
862
|
-
# Combine
|
863
|
-
|
864
|
-
frames.append(combined_data)
|
866
|
+
# Combine proxy history + actual ETF data
|
867
|
+
frames.append(pd.concat([hist, etf_data]))
|
865
868
|
|
866
|
-
|
867
|
-
|
869
|
+
# Add ETFs that were never in the mapping
|
870
|
+
untouched = set(symbols) - set(mapping)
|
871
|
+
frames.append(df_etfs[df_etfs["symbol"].isin(untouched)])
|
868
872
|
|
869
|
-
|
870
|
-
|
871
|
-
|
873
|
+
return (
|
874
|
+
pd.concat(frames, ignore_index=True)
|
875
|
+
.sort_values(["date", "symbol"])
|
876
|
+
.reset_index(drop=True)
|
877
|
+
)
|
872
878
|
|
873
879
|
|
874
880
|
ALLOWED_FIELDS = {"open", "high", "low", "close"}
|
@@ -925,6 +931,7 @@ def get_pricing(
|
|
925
931
|
("Cryptocurrencies-Daily-Price", extend),
|
926
932
|
("Bonds-Daily-Price", extend),
|
927
933
|
("Commodities-Daily-Price", extend),
|
934
|
+
("Forex-Daily-Price", extend),
|
928
935
|
("Indices-Daily-Price", False), # indices generally have no proxy data
|
929
936
|
]
|
930
937
|
remaining = set(symbol_list) # symbols still to fetch
|
@@ -0,0 +1,7 @@
|
|
1
|
+
pwb_toolbox/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
pwb_toolbox/datasets/__init__.py,sha256=8ruFquxyz5_6D9zImecPmTXruHClkoV0vNX5H0eR4Fw,22249
|
3
|
+
pwb_toolbox-0.1.6.dist-info/licenses/LICENSE.txt,sha256=_Wjz7o7St3iVSPBRzE0keS8XSqSJ03A3NZ6cMlTaSK8,1079
|
4
|
+
pwb_toolbox-0.1.6.dist-info/METADATA,sha256=nao3Zw_tNUmsNxm9tql9HfYc3NAOWc_wyJIaYcuuHBA,4617
|
5
|
+
pwb_toolbox-0.1.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
+
pwb_toolbox-0.1.6.dist-info/top_level.txt,sha256=TZcXcF2AMkKkibZOuq6AYsHjajPgddHAGjQUT64OYGY,12
|
7
|
+
pwb_toolbox-0.1.6.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
pwb_toolbox/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
pwb_toolbox/datasets/__init__.py,sha256=quP-eG9-ExUUwYFxvSwoFWmhzXH_2bfZLwTfdTHdds8,22155
|
3
|
-
pwb_toolbox-0.1.5.dist-info/licenses/LICENSE.txt,sha256=_Wjz7o7St3iVSPBRzE0keS8XSqSJ03A3NZ6cMlTaSK8,1079
|
4
|
-
pwb_toolbox-0.1.5.dist-info/METADATA,sha256=aoumC8jamm2AG8LDdqrCN13xuvS-UoDbzIMPLl0Uv9Q,4617
|
5
|
-
pwb_toolbox-0.1.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
-
pwb_toolbox-0.1.5.dist-info/top_level.txt,sha256=TZcXcF2AMkKkibZOuq6AYsHjajPgddHAGjQUT64OYGY,12
|
7
|
-
pwb_toolbox-0.1.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|