Finance 100 #49 · Investing View source on GitHub

Correlation Heatmap

Drop in price history for several assets and see a correlation heatmap instantly.

Price history

Results

Correlation matrix of monthly returns

Rolling correlation for the pair

How it works

Each price is turned into a simple return: r = price_t / price_(t-1) - 1. Returns are used rather than prices, because two prices that both trend up look correlated even when their moves are unrelated.

The correlation is Pearson's r, between -1 and 1: sum((x - mean x)(y - mean y)) / sqrt(sum((x - mean x)^2) x sum((y - mean y)^2)). Values near 1 mean the assets move together. Values near 0 mean little shared movement. Negative values mean they tend to move in opposite directions.

Missing prices are handled pair by pair. A month is dropped from a pair only when one of its two prices is blank, so the other assets still use that month. The rolling chart uses the trailing window you set, and it starts once the window is full.

Limits: monthly data over two years is a short sample, and correlations shift in stress periods. Correlation does not show cause, and it says nothing about valuation or returns. Prices in the sample are illustrative, not current quotes.