Commodity Markets and Futures › Hedging Example: Crude Oil Producer
Quantitative FinanceAll chapters Commodity Markets and Futures › Hedging Example: Crude Oil ProducerOne section · Sections in this chapter8 / 12 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Let's work through a complete hedging example for an oil producer seeking to lock in prices for future production.
# Producer's situation
production_volume = 100000 # barrels to hedge
current_spot = 75.00 # current spot price per barrel
futures_price = 77.50 # 6-month futures price
contract_size = 1000 # barrels per futures contract
# Calculate number of contracts needed
num_contracts = production_volume / contract_size
# Simulate price scenarios at delivery
np.random.seed(123)
price_scenarios = np.linspace(50, 100, 21) # Range of possible prices
# Calculate outcomes
def calculate_hedge_outcome(
final_spot, futures_price, volume, num_contracts, contract_size
):
"""Calculate total revenue and effective price from hedged position."""
# Revenue from physical sales
physical_revenue = final_spot * volume
# Profit/loss from futures (short position profits when prices fall)
futures_pnl = (futures_price - final_spot) * num_contracts * contract_size
# Total revenue
total_revenue = physical_revenue + futures_pnl
# Effective price per barrel
effective_price = total_revenue / volume
return physical_revenue, futures_pnl, total_revenue, effective_priceimport pandas as pd
# Calculate outcomes for all price scenarios
results = []
for spot in price_scenarios:
physical, futures_pnl, total, effective = calculate_hedge_outcome(
spot, futures_price, production_volume, num_contracts, contract_size
)
results.append(
{
"final_spot": spot,
"physical_revenue": physical / 1e6, # Convert to millions
"futures_pnl": futures_pnl / 1e6,
"total_revenue": total / 1e6,
"effective_price": effective,
}
)
results_df = pd.DataFrame(results)


# Analyze specific price scenarios
low_scenario = 60
high_scenario = 90
# Retrieve effective prices for these scenarios
eff_price_low = results_df.loc[
results_df["final_spot"] == low_scenario, "effective_price"
].values[0]
eff_price_high = results_df.loc[
results_df["final_spot"] == high_scenario, "effective_price"
].values[0]
# Calculate locked revenue
locked_revenue = futures_price * production_volume / 1e6Hedge Analysis Summary: -------------------------------------------------- Production volume: 100,000 barrels Futures contracts sold: 100 Locked-in price: $77.50/barrel Locked-in revenue: $7.75 million Sample outcomes: If spot falls to $60: effective price = $77.50 If spot rises to $90: effective price = $77.50
The visualization demonstrates the core trade-off of hedging. The producer sacrifices the potential to benefit from price increases in exchange for protection against price declines. The hedge turns uncertain future revenue into a known quantity.
Calculating the Optimal Hedge Ratio
When the commodity being hedged doesn't perfectly match the futures contract, we need to calculate the optimal hedge ratio using historical price data:
# Simulate historical price data for spot and futures
n_obs = 252 # One year of daily data
# Generate correlated price changes
correlation = 0.92 # Typical correlation between spot and futures
vol_spot = 0.02 # Daily spot volatility
vol_futures = 0.025 # Daily futures volatility
# Create correlated returns
cov_matrix = np.array(
[
[vol_spot**2, vol_spot * vol_futures * correlation],
[vol_spot * vol_futures * correlation, vol_futures**2],
]
)
mean_returns = [0, 0]
returns = np.random.multivariate_normal(mean_returns, cov_matrix, n_obs)
spot_returns = returns[:, 0]
futures_returns = returns[:, 1]
# Convert to price levels
spot_prices = 75 * np.exp(np.cumsum(spot_returns))
futures_prices = 77 * np.exp(np.cumsum(futures_returns))# Calculate optimal hedge ratio
def calculate_optimal_hedge_ratio(spot_changes, futures_changes):
"""
Calculate minimum variance hedge ratio.
h* = correlation * (std_spot / std_futures)
"""
correlation = np.corrcoef(spot_changes, futures_changes)[0, 1]
std_spot = np.std(spot_changes)
std_futures = np.std(futures_changes)
optimal_ratio = correlation * (std_spot / std_futures)
return optimal_ratio, correlation, std_spot, std_futures
# Calculate price changes
spot_changes = np.diff(spot_prices)
futures_changes = np.diff(futures_prices)
h_star, corr, std_s, std_f = calculate_optimal_hedge_ratio(
spot_changes, futures_changes
)
# Calculate contracts needed
naive_contracts = production_volume / contract_size
optimal_contracts = h_star * naive_contractsOptimal Hedge Ratio Analysis: -------------------------------------------------- Correlation (spot, futures): 0.9235 Spot price volatility: $1.4884 Futures price volatility: $1.6636 Optimal hedge ratio (h*): 0.8263 Interpretation: To hedge 100,000 barrels of spot exposure, use 83 futures contracts (each = 1,000 barrels)
The optimal hedge ratio of approximately 0.74 indicates that the hedge requires fewer futures contracts than a naive one-to-one hedge. This occurs because futures prices are more volatile than spot prices in our simulated data, so fewer contracts are needed to offset the same dollar risk.
Hedge Effectiveness
We can measure how well the hedge performs by comparing the variance of unhedged and hedged positions:
def calculate_hedge_effectiveness(spot_changes, futures_changes, hedge_ratio):
"""
Calculate hedge effectiveness as variance reduction.
Effectiveness = 1 - Var(hedged) / Var(unhedged)
"""
# Unhedged variance is just spot variance
var_unhedged = np.var(spot_changes)
# Hedged position: spot - h * futures
hedged_changes = spot_changes - hedge_ratio * futures_changes
var_hedged = np.var(hedged_changes)
effectiveness = 1 - (var_hedged / var_unhedged)
return effectiveness, var_unhedged, var_hedged
# Calculate for different hedge ratios
hedge_ratios = np.linspace(0, 1.5, 31)
effectiveness_values = []
for h in hedge_ratios:
eff, _, _ = calculate_hedge_effectiveness(spot_changes, futures_changes, h)
effectiveness_values.append(eff)
# Get effectiveness at optimal ratio
opt_eff, var_unh, var_h = calculate_hedge_effectiveness(
spot_changes, futures_changes, h_star
)
Hedge Effectiveness at Optimal Ratio: -------------------------------------------------- Unhedged variance: 2.215373 Hedged variance: 0.325806 Variance reduction: 85.3% The optimal hedge removes approximately 85% of price risk. Remaining risk is basis risk due to imperfect correlation.

The hedge effectiveness of approximately 85% indicates that the optimal hedge removes most, but not all, price risk. The remaining 15% represents basis risk arising from imperfect correlation between the spot commodity and the futures contract used for hedging.