pwb-toolbox 0.1.4__py3-none-any.whl → 0.1.5__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 +49 -31
- {pwb_toolbox-0.1.4.dist-info → pwb_toolbox-0.1.5.dist-info}/METADATA +1 -1
- pwb_toolbox-0.1.5.dist-info/RECORD +7 -0
- pwb_toolbox-0.1.4.dist-info/RECORD +0 -7
- {pwb_toolbox-0.1.4.dist-info → pwb_toolbox-0.1.5.dist-info}/WHEEL +0 -0
- {pwb_toolbox-0.1.4.dist-info → pwb_toolbox-0.1.5.dist-info}/licenses/LICENSE.txt +0 -0
- {pwb_toolbox-0.1.4.dist-info → pwb_toolbox-0.1.5.dist-info}/top_level.txt +0 -0
pwb_toolbox/datasets/__init__.py
CHANGED
@@ -627,7 +627,9 @@ def load_dataset(
|
|
627
627
|
return df
|
628
628
|
|
629
629
|
|
630
|
-
def __convert_indices_to_usd(
|
630
|
+
def __convert_indices_to_usd(
|
631
|
+
df_indices: pd.DataFrame, df_forex: pd.DataFrame
|
632
|
+
) -> pd.DataFrame:
|
631
633
|
mapping = {
|
632
634
|
"ADSMI": "AED", # United Arab Emirates
|
633
635
|
"AEX": "EUR", # Netherlands
|
@@ -727,32 +729,40 @@ def __convert_indices_to_usd(df_indices, df_forex):
|
|
727
729
|
"SX5E": "EUR", # Europe
|
728
730
|
"TA125": "ILS", # Israel
|
729
731
|
}
|
730
|
-
symbols = df_indices.symbol.unique()
|
731
|
-
mapping = {k: v for k, v in mapping.items() if k in symbols}
|
732
732
|
frames = []
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
733
|
+
|
734
|
+
# iterate over the symbols that actually exist in df_indices
|
735
|
+
for symbol in df_indices["symbol"].unique():
|
736
|
+
df_idx = df_indices[df_indices["symbol"] == symbol].copy()
|
737
|
+
|
738
|
+
# 1) Figure out what currency the index is quoted in.
|
739
|
+
ccy = mapping.get(symbol) # None if not mapped
|
740
|
+
if ccy is None or ccy == "USD":
|
741
|
+
# Unknown or already USD – just keep the original rows
|
742
|
+
frames.append(df_idx)
|
737
743
|
continue
|
738
|
-
|
739
|
-
|
744
|
+
|
745
|
+
# 2) Find the matching FX rate (home-ccy → USD)
|
746
|
+
pair = ccy + "USD"
|
747
|
+
df_fx = df_forex[df_forex["symbol"] == pair].copy()
|
748
|
+
|
749
|
+
if df_idx.empty or df_fx.empty:
|
750
|
+
# No FX data – keep raw index levels instead of dropping them
|
751
|
+
frames.append(df_idx)
|
740
752
|
continue
|
741
|
-
# Merge dataframes on the date column
|
742
|
-
merged_df = pd.merge(
|
743
|
-
df_index, df_forex_currency, on="date", suffixes=("", "_forex")
|
744
|
-
)
|
745
753
|
|
746
|
-
#
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
merged_df["close"] = merged_df["close"] * merged_df["close_forex"]
|
754
|
+
# 3) Merge on date and convert OHLC
|
755
|
+
merged = pd.merge(df_idx, df_fx, on="date", suffixes=("", "_fx"))
|
756
|
+
for col in ("open", "high", "low", "close"):
|
757
|
+
merged[col] = merged[col] * merged[f"{col}_fx"]
|
751
758
|
|
752
|
-
frames.append(
|
759
|
+
frames.append(merged[["symbol", "date", "open", "high", "low", "close"]])
|
753
760
|
|
754
|
-
|
755
|
-
|
761
|
+
if not frames:
|
762
|
+
return pd.DataFrame(columns=df_indices.columns)
|
763
|
+
|
764
|
+
# Combine everything back into one DataFrame
|
765
|
+
return pd.concat(frames, ignore_index=True)
|
756
766
|
|
757
767
|
|
758
768
|
def __extract_years_to_maturity(bond_symbol):
|
@@ -909,16 +919,24 @@ def get_pricing(
|
|
909
919
|
raise ValueError(f"Invalid field(s): {bad}. Allowed: {sorted(ALLOWED_FIELDS)}")
|
910
920
|
|
911
921
|
# --------------------------------------------------------------- download
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
+
DATASETS = [
|
923
|
+
("Stocks-Daily-Price", extend),
|
924
|
+
("ETFs-Daily-Price", extend),
|
925
|
+
("Cryptocurrencies-Daily-Price", extend),
|
926
|
+
("Bonds-Daily-Price", extend),
|
927
|
+
("Commodities-Daily-Price", extend),
|
928
|
+
("Indices-Daily-Price", False), # indices generally have no proxy data
|
929
|
+
]
|
930
|
+
remaining = set(symbol_list) # symbols still to fetch
|
931
|
+
frames = []
|
932
|
+
for dataset_name, ext_flag in DATASETS:
|
933
|
+
if not remaining: # all symbols resolved → stop early
|
934
|
+
break
|
935
|
+
df_part = load_dataset(dataset_name, list(remaining), extend=ext_flag)
|
936
|
+
if not df_part.empty:
|
937
|
+
frames.append(df_part)
|
938
|
+
remaining -= set(df_part["symbol"].unique())
|
939
|
+
df = pd.concat(frames, ignore_index=True)
|
922
940
|
|
923
941
|
df["date"] = pd.to_datetime(df["date"])
|
924
942
|
df.set_index("date", inplace=True)
|
@@ -0,0 +1,7 @@
|
|
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,,
|
@@ -1,7 +0,0 @@
|
|
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,,
|
File without changes
|
File without changes
|
File without changes
|