Merge pull request #34 from PR0M3TH3AN/codex/fix-keyerror-by-adjusting-m2-crop-date

Remove forced crop in bitcoin_m2_chart
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2025-06-01 10:37:10 -04:00
commit b2db3573b6
1 file changed
+10 -9
+10 -9
View File
@@ -3,8 +3,9 @@
---------------------- ----------------------
Plot Bitcoin price (log scale) versus global M2 money supply (rebased to 100), Plot Bitcoin price (log scale) versus global M2 money supply (rebased to 100),
with M2 shifted forward by 90 days so that both series share the same x-axis. with M2 shifted forward by 90 days so that both series share the same x-axis.
Show only data from July 1, 2024 onward. White background, two y-axes on the right, Use the full range provided by ``--start``/``--end``. White background, two y-axes
monthly x-ticks, and friendly error message if GLOBAL_M2 is missing. on the right, monthly x-ticks, and friendly error message if ``GLOBAL_M2`` is
missing.
""" """
from __future__ import annotations from __future__ import annotations
@@ -65,8 +66,9 @@ def plot_bitcoin_m2(
) -> plt.Figure: ) -> plt.Figure:
""" """
Plot Bitcoin (log scale) and Global M2 (rebased to 100) on a shared x-axis, Plot Bitcoin (log scale) and Global M2 (rebased to 100) on a shared x-axis,
with M2 shifted forward by `offset_days` (90 days). Show only data from with M2 shifted forward by ``offset_days`` (90 days). Data is shown for the
July 1, 2024 onward. White background, two y-axes on the right, monthly x-ticks. entire range provided by ``--start``/``--end``. White background, two
y-axes on the right, monthly x-ticks.
""" """
# ────────────────────────────────────────────────────────────────────────── # ──────────────────────────────────────────────────────────────────────────
@@ -82,11 +84,10 @@ def plot_bitcoin_m2(
m2_shifted.index = m2_shifted.index + pd.Timedelta(days=offset_days) m2_shifted.index = m2_shifted.index + pd.Timedelta(days=offset_days)
# ────────────────────────────────────────────────────────────────────────── # ──────────────────────────────────────────────────────────────────────────
# 3) CROP BOTH SERIES TO START ON JULY 1, 2024 (user request) # 3) USE FULL RANGE FROM --start (no hard-coded crop)
# ────────────────────────────────────────────────────────────────────────── # ──────────────────────────────────────────────────────────────────────────
crop_start = pd.to_datetime("2024-07-01") btc_cropped = btc_clean
btc_cropped = btc_clean.loc[btc_clean.index >= crop_start] m2_cropped = m2_shifted
m2_cropped = m2_shifted.loc[m2_shifted.index >= crop_start]
# ────────────────────────────────────────────────────────────────────────── # ──────────────────────────────────────────────────────────────────────────
# 4) FIND OVERLAP WINDOW: plot only dates where BOTH series exist # 4) FIND OVERLAP WINDOW: plot only dates where BOTH series exist
@@ -96,7 +97,7 @@ def plot_bitcoin_m2(
if overlap_start >= overlap_end: if overlap_start >= overlap_end:
raise ValueError( raise ValueError(
f"No overlapping range from {crop_start.date()} after shifting M2 by {offset_days} days." f"No overlapping range after shifting M2 by {offset_days} days."
) )
btc_overlap = btc_cropped.loc[overlap_start:overlap_end] btc_overlap = btc_cropped.loc[overlap_start:overlap_end]