Covariance measures how two assets’ returns vary together. Positive values indicate movement in the same direction; negative values indicate movement in opposite directions. Because share prices have different scales, compare percentage or log returns rather than absolute prices. section 7.2.2
Use covariance carefully when comparing portfolio assets:
- Calculate it from a DataFrame of log returns, then multiply by the number of trading days to annualize the covariance matrix. section 7.2.2
- Read the sign as direction, but not the magnitude as relationship strength; correlation standardizes covariance and supplies that missing scale. section 7.2.2
- Treat observed dependencies as period-specific: relationships among Microsoft, Amazon, and Alphabet can differ in other years. section 7.2.2
Three-stock covariance matrix
For annualized log returns, Microsoft and Amazon have covariance 0.03887, Microsoft and Alphabet 0.03239, and Amazon and Alphabet 0.04290. All are positive, suggesting these returns tended to move together during the tested period. section 7.2.2
cov_matrix = log_returns.cov() * TRADING_DAYS cov_matrix
Build the annualized covariance matrix with `log_returns.cov() * TRADING_DAYS`. section 7.2.2




