Correlation Matrix in Python: How Correlated are COVID-19 Cases and Different Financial Assets?

Correlation Matrix in Python: How Correlated are COVID-19 Cases and Different Financial Assets?

Correlation matrices provide a compact overview of pairwise association. This updated tutorial compares daily health-activity changes with financial-asset returns using both Pearson and Spearman correlation. The example is deterministic and designed to teach the method, not to estimate historical pandemic effects.

Use changes rather than price levels

Correlating trending cumulative cases and asset price levels can produce misleading relationships. The notebook works with daily growth and returns instead.

pearson = changes.corr(method="pearson")
spearman = changes.corr(method="spearman")

Pearson correlation measures linear association. Spearman correlation works on ranks and captures monotonic association with less sensitivity to extreme magnitudes.

Health activity and financial asset correlation matrices

sns.heatmap(
    matrix,
    annot=True,
    fmt=".2f",
    cmap="vlag",
    center=0,
    vmin=-1,
    vmax=1,
)

Correlation does not establish causation. Real health and market data require aligned calendars, reporting-lag treatment, robustness checks across periods, correction for multiple comparisons, and a causal design before making policy or investment claims.

Florian Follonier

Florian Follonier · Cloud Solution Architect at Microsoft

Florian Follonier (PhD) is a Cloud Solution Architect at Microsoft based in Zurich and the author of relataly.com, writing hands-on tutorials on machine learning, Python, RAG, and AI agents.

3 Commentsarchived from the original site

  • Phil the Lobster
    Awesome Dude!!
  • CreedSutton
    amazing blog thank you this elaborating 🥰
  • j0hnnywa1ker
    I tried running your code, but I got this error:  File ~\anaconda3\Lib\site-packages\pandas_datareader\yahoo\daily.py:153 in _read_one_data   data = j["context"]["dispatcher"]["stores"]["HistoricalPriceStore"] TypeError: string indices must be integers, not 'str' could you please help me, what should I do? Thanks