In [1]:
import warnings
import yfinance as yf
import pandas as pd
# Suppress annoying FutureWarnings
warnings.simplefilter(action='ignore', category=FutureWarning)
# 1. Define Tickers (Ordered alphabetically for easy renaming)
tickers = ["BTC-USD", "DX-Y.NYB", "USDC-USD", "XRP-USD"]
# 2. Download Data
data = yf.download(tickers, start="2019-01-01", end="2024-05-01", progress=False)
# 3. Clean and Extract 'Close' prices
# auto_adjust=True (default) makes 'Close' the final adjusted price
prices = data['Close'].dropna()
# 4. Normalize to 100
normalized = (prices / prices.iloc[0]) * 100
# 5. Rename Columns accurately (matching alphabetical order)
normalized.columns = ['Bitcoin (BTC)', 'US Dollar Index', 'USD Coin (USDC)', 'XRP Performance']
print("Success! Multi-Asset Performance normalized to 100:")
display(normalized.head())
Success! Multi-Asset Performance normalized to 100:
| Bitcoin (BTC) | US Dollar Index | USD Coin (USDC) | XRP Performance | |
|---|---|---|---|---|
| Date | ||||
| 2019-01-02 | 100.000000 | 100.000000 | 100.000000 | 100.000000 |
| 2019-01-03 | 97.295026 | 99.473247 | 99.548604 | 95.997527 |
| 2019-01-04 | 97.826959 | 99.349311 | 99.016573 | 95.070926 |
| 2019-01-07 | 102.075333 | 98.853542 | 98.741373 | 97.096282 |
| 2019-01-08 | 102.217332 | 99.049785 | 98.992806 | 97.354243 |
In [2]:
import plotly.express as px
import plotly.io as pio
# Use 'html' to ensure the code is embedded directly into the notebook cells
pio.renderers.default = "notebook_connected"
# 1. CREATE THE INTERACTIVE PLOT
# Use px.line with your normalized dataframe
# x=normalized.index uses your Date column
fig = px.line(
normalized,
x=normalized.index,
y=normalized.columns,
title='Asset Performance Comparison (Baseline: Jan 2019 = 100)',
labels={'value': 'Normalized Price (100 = Start)', 'variable': 'Asset'},
template='plotly_dark' # Matches your site's "Matrix" dark theme
)
# 2. CUSTOMIZE THE STYLE
fig.update_layout(
font_family="IBM Plex Sans",
hovermode="x unified", # Shows all asset values in one tooltip when hovering
legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1),
yaxis_title="Normalized Value (%)",
xaxis_title="Timeline"
)
# 3. EMPHASIZE KEY LINES (Optional)
# Make crypto lines thicker and the Dollar/USDC thinner for contrast
fig.update_traces(line=dict(width=1.5), selector=dict(name='US Dollar Index'))
fig.update_traces(line=dict(width=1.5), selector=dict(name='USD Coin (USDC)'))
fig.update_traces(line=dict(width=3), selector=dict(name='XRP Performance'))
fig.show()
In [3]:
import plotly.graph_objects as go
from plotly.subplots import make_subplots
# --- A. CALCULATE ROLLING CORRELATION (90-Day) ---
# This shows how XRP's relationship with BTC "tightens" or "decouples"
correlation_series = prices['XRP-USD'].rolling(window=90).corr(prices['BTC-USD'])
# --- B. CALCULATE VOLATILITY (30-Day Rolling Standard Deviation) ---
volatility = prices.pct_change().rolling(window=30).std() * (252**0.5) * 100
# --- C. PLOT: CORRELATION & VOLATILITY DASHBOARD ---
fig_metrics = make_subplots(rows=2, cols=1, shared_xaxes=True,
vertical_spacing=0.1,
subplot_titles=("90-Day Price Correlation: XRP vs. BTC",
"30-Day Annualized Volatility (%)"))
# Add Correlation Trace
fig_metrics.add_trace(go.Scatter(x=correlation_series.index, y=correlation_series,
name="XRP/BTC Correlation", line=dict(color='#3fb950')), row=1, col=1)
# Add Volatility Traces
fig_metrics.add_trace(go.Scatter(x=volatility.index, y=volatility['XRP-USD'],
name="XRP Volatility", line=dict(color='#FFD700')), row=2, col=1)
fig_metrics.add_trace(go.Scatter(x=volatility.index, y=volatility['BTC-USD'],
name="BTC Volatility", line=dict(color='#f0b429', dash='dot')), row=2, col=1)
fig_metrics.update_layout(height=700, template='plotly_dark', showlegend=True,
title_text="Advanced Market Dynamics: XRP Intelligence")
fig_metrics.show(renderer='notebook_connected')
In [4]:
from IPython.display import HTML
# --- DYNAMIC CALCULATIONS ---
# We use .iloc[-1] to get the most recent data point vs the start (100)
total_xrp_gain = round(normalized['XRP Performance'].iloc[-1] - 100, 1)
total_btc_gain = round(normalized['Bitcoin (BTC)'].iloc[-1] - 100, 1)
dxy_change = round(normalized['US Dollar Index'].iloc[-1] - 100, 1)
avg_corr = round(correlation_series.mean(), 2)
# --- THE EXECUTIVE HTML/CSS ---
exec_summary_html = f"""
<style>
.crypto-exec {{ background:#0d1117; color:#c9d1d9; font-family:sans-serif; padding:35px; border-radius:15px; border:1px solid #3fb950; max-width:950px; margin:20px auto; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }}
.crypto-exec h1 {{ color:#fff; font-size:24px; border-bottom: 2px solid #3fb950; padding-bottom:10px; margin-top:0; }}
.kpi-row {{ display:flex; justify-content:space-between; margin:25px 0; gap:15px; }}
.kpi-card {{ background:#161b22; padding:20px; border-radius:10px; flex:1; text-align:center; border:1px solid #21262d; }}
.kpi-card .label {{ font-size:11px; text-transform:uppercase; color:#8b949e; letter-spacing:1px; }}
.kpi-card .value {{ font-size:22px; font-weight:700; margin-top:8px; color:#3fb950; }}
.kpi-card.alt .value {{ color:#FFD700; }}
.insight-box {{ background:rgba(63, 185, 80, 0.1); border-left:4px solid #3fb950; padding:15px; margin-top:15px; border-radius: 0 8px 8px 0; font-size:14px; line-height:1.6; }}
.highlight {{ color:#FFD700; font-weight:600; }}
</style>
<div class='crypto-exec'>
<h1>XRP Performance Intelligence Briefing</h1>
<p>Comparative analysis of <b>XRP</b>, <b>Bitcoin</b>, and the <b>US Dollar Index (DXY)</b> from 2019 to Present.</p>
<div class='kpi-row'>
<div class='kpi-card'><div class='label'>XRP Total Return</div><div class='value'>{total_xrp_gain:+,}%</div></div>
<div class='kpi-card alt'><div class='label'>BTC Total Return</div><div class='value'>{total_btc_gain:+,}%</div></div>
<div class='kpi-card'><div class='label'>USD Index Delta</div><div class='value'>{dxy_change:+,}%</div></div>
<div class='kpi-card alt'><div class='label'>Avg BTC Correlation</div><div class='value'>{avg_corr}</div></div>
</div>
<div class='insight-box'>
<b>Market Coupling:</b> XRP maintains an average 90-day correlation of <span class='highlight'>{avg_corr}</span> with Bitcoin. While it largely follows the broader crypto market, significant "decoupling" events align with specific legal and regulatory milestones.
</div>
<div class='insight-box' style='border-left-color:#FFD700;'>
<b>Macro Divergence:</b> Since 2019, XRP's performance of <span class='highlight'>{total_xrp_gain}%</span> stands in stark contrast to the US Dollar Index move of <span class='highlight'>{dxy_change}%</span>, illustrating its role as a high-volatility "Risk-On" asset.
</div>
</div>
"""
display(HTML(exec_summary_html))
XRP Performance Intelligence Briefing
Comparative analysis of XRP, Bitcoin, and the US Dollar Index (DXY) from 2019 to Present.
XRP Total Return
+33.3%
BTC Total Return
+1,437.7%
USD Index Delta
+9.7%
Avg BTC Correlation
0.58
Market Coupling: XRP maintains an average 90-day correlation of 0.58 with Bitcoin. While it largely follows the broader crypto market, significant "decoupling" events align with specific legal and regulatory milestones.
Macro Divergence: Since 2019, XRP's performance of 33.3% stands in stark contrast to the US Dollar Index move of 9.7%, illustrating its role as a high-volatility "Risk-On" asset.
In [5]:
from IPython.display import HTML
# --- DATA FOR THE MODELER ---
circ_supply = 60_900_000_000
scenarios = [
{"name": "Stalled Legislation (Status Quo)", "price": 1.41, "class": "warn"},
{"name": "Clarity Act: Conservative Passage", "price": 3.50, "class": "good"},
{"name": "Clarity Act: Moderate Adoption", "price": 5.00, "class": "good"},
{"name": "Clarity Act: Full Institutional Inflow", "price": 8.00, "class": "ultra"}
]
# Build the scenario rows
rows_html = ""
for s in scenarios:
m_cap = (s['price'] * circ_supply) / 1e9
rows_html += f"""
<div class='scenario-row {s['class']}'>
<div class='scen-name'>{s['name']}</div>
<div class='scen-price'>${s['price']:.2f}</div>
<div class='scen-cap'>${m_cap:.1f}B Market Cap</div>
</div>
"""
# --- THE STYLED CARD ---
modeller_html = f"""
<style>
.modeller-card {{ background:#0d1117; color:#c9d1d9; font-family:sans-serif; padding:30px; border-radius:15px; border:1px solid #FFD700; max-width:950px; margin:30px auto; }}
.modeller-card h2 {{ color:#FFD700; margin-top:0; font-size:20px; text-transform:uppercase; letter-spacing:1px; }}
.modeller-sub {{ font-size:13px; color:#8b949e; margin-bottom:20px; border-left: 2px solid #FFD700; padding-left:10px; }}
.scenario-grid {{ display:flex; flex-direction:column; gap:10px; }}
.scenario-row {{ display:flex; justify-content:space-between; align-items:center; background:#161b22; padding:15px 25px; border-radius:8px; border:1px solid #21262d; transition: 0.3s; }}
.scenario-row:hover {{ border-color:#FFD700; transform: scale(1.01); background:#1c2128; }}
.scen-name {{ flex:2; font-weight:600; font-size:15px; }}
.scen-price {{ flex:1; text-align:center; font-family:monospace; font-size:18px; color:#FFD700; }}
.scen-cap {{ flex:1.5; text-align:right; font-size:12px; color:#8b949e; text-transform:uppercase; }}
.scenario-row.good {{ border-left: 4px solid #3fb950; }}
.scenario-row.warn {{ border-left: 4px solid #f0b429; }}
.scenario-row.ultra {{ border-left: 4px solid #3fb950; box-shadow: inset 0 0 10px rgba(63,185,80,0.1); }}
.scenario-row.ultra .scen-price {{ color:#3fb950; text-shadow: 0 0 5px rgba(63,185,80,0.5); }}
.bonus-note {{ margin-top:20px; padding:15px; background:rgba(255, 215, 0, 0.05); border-radius:8px; font-size:13px; line-height:1.5; }}
</style>
<div class='modeller-card'>
<h2>Predictive Valuation: The Clarity Act (May 2026)</h2>
<p class='modeller-sub'>Projected valuation based on legislative outcomes for the Senate Banking Committee markup.</p>
<div class='scenario-grid'>
{rows_html}
</div>
<div class='bonus-note'>
<b>Analyst Sweetener:</b> While current price action reflects legislative stalling, <b>Standard Chartered</b> maintains a price target of <span style='color:#3fb950;'>$8.00</span> contingent on a clean bill passage. A "Full Adoption" scenario places XRP in a market-cap tier comparable to Ethereum ($490B+), assuming codified institutional on-ramps.
</div>
</div>
"""
display(HTML(modeller_html))
Predictive Valuation: The Clarity Act (May 2026)
Projected valuation based on legislative outcomes for the Senate Banking Committee markup.
Stalled Legislation (Status Quo)
$1.41
$85.9B Market Cap
Clarity Act: Conservative Passage
$3.50
$213.2B Market Cap
Clarity Act: Moderate Adoption
$5.00
$304.5B Market Cap
Clarity Act: Full Institutional Inflow
$8.00
$487.2B Market Cap
Analyst Sweetener: While current price action reflects legislative stalling, Standard Chartered maintains a price target of $8.00 contingent on a clean bill passage. A "Full Adoption" scenario places XRP in a market-cap tier comparable to Ethereum ($490B+), assuming codified institutional on-ramps.