This repository demonstrates beta hedging using Oracle (ORCL) and the S&P 500 ETF (SPY). It includes explanations of factor models, beta calculation, risk exposure, and hedging implementation.
Beta hedging is a strategy to reduce the impact of market movements on a portfolio.
-
Beta (
$\beta$ ) measures an asset's sensitivity to a factor, usually the market. -
Alpha (
$\alpha$ ) represents returns independent of the market. - Hedging creates a market-neutral portfolio, where returns are mostly alpha and volatility is reduced.
A factor model explains the returns of an asset as a linear combination of factors:
Where:
-
$Y$ = asset returns (Oracle in this case) -
$X_i$ = factor returns (market index, sector ETF, etc.) -
$\alpha$ = return independent of factors -
$\beta_i$ = sensitivity to factor$X_i$ -
$\epsilon$ = noise
A single-factor model for Oracle vs the market:
- Measures how Oracle moves relative to the market
- High beta → more volatile, follows the market closely
- Low beta → less sensitive to market swings
- Beta = 0 → market-neutral
- High beta means larger gains in a rising market and larger losses in a falling market.
- Low or negligible beta indicates returns mostly independent of the market.
- Market-neutral portfolios focus on asset-specific performance, providing stable returns across market conditions.
- Obtain price data for ORCL and SPY.
- Calculate daily returns from price data.
- Estimate beta:
- Construct a hedged portfolio:
-
Evaluate hedged portfolio:
- Alpha: independent performance
- Beta: reduced market exposure
- Volatility: lower risk
- A portfolio with beta ≈ 0 is market-neutral
- Returns are driven primarily by asset-specific factors (alpha) rather than market movements
- Beta is estimated from historical data and may change over time.
- Hedging using historical beta may not fully remove market risk.
- Beta estimates have standard errors; frequent recalculation improves hedging accuracy.
-
Download Data: Daily prices for ORCL and SPY using
yfinance. -
Compute Returns: Calculate daily percent changes.
-
Estimate Beta: Linear regression of ORCL returns against SPY returns to find alpha and beta.
-
Construct Hedged Portfolio:
Hedged Portfolio = ORCL returns - (beta × SPY returns) -
Analyze Portfolio: Compare volatility, average return, and alpha before and after hedging.
-
Out-of-Sample Test: Apply the hedge to a future period to test stability.
- Reduced Volatility: The hedged portfolio is smoother than ORCL alone.
- Market Neutral: Beta ≈ 0 — the portfolio no longer follows SPY movements.
- Alpha Preserved: Small positive returns remain, independent of the market.
| Metric | ORCL | Hedged ORCL |
|---|---|---|
| Average Daily Return | -0.000038 | 0.000592 |
| Volatility (Std Dev) | 0.0193 | 0.0136 |
| Beta vs SPY | 1.0+ | ~0 |
This example demonstrates how beta hedging can isolate a stock’s intrinsic performance, reduce market-driven risk, and create a more stable, market-neutral portfolio.
yfinance– for historical stock pricesnumpy– numerical operationsmatplotlib– plottingstatsmodels– regression analysis