Exploring Pearson Correlation in the World of Finance: A Deeper Understanding
Hello there!
As I embark on this blogging journey, I've decided to go
with the flow and see where it takes me. Today, it struck me that a great idea
for my first post could be about correlation - it's relatively simple,
frequently used, and, I believe, often overinterpreted.
code in which we take data , create df and present correlation matrix
results from the presentation of the first five rows of our df and correlation matrix
heat map of our correlation matrix
Correlation: Simple, But Is It Clear?
We started with a straightforward question: how are the
closing prices of different assets related to each other? Seems simple, right?
But as we dig deeper, the issue of time series stationarity emerges. Are our
data stable over time, or do their characteristics change?
ADF test
The Augmented Dickey-Fuller (ADF) Test: The Key to
Stationarity
To tackle this, we employed the ADF test. This test checks
whether a time series is non-stationary by looking for a unit root. Practically
speaking, if the test result (result[0]) is low and the p-value (result[1]) is
below 0.05, we can consider the series to be stationary.
Let's see how this works in practice. For gold (Gold):
p-value: 0.345811
Critical Values: -3.439 (1%), -2.865 (5%), -2.569 (10%)
The interpretation is straightforward: gold appears to be
non-stationary, which means we need to be cautious in interpreting its
correlation with other assets.
When we find a time series to be non-stationary, we can apply differencing, i.e., calculate the percentage changes in values. This often helps to stabilize the series, making it more suitable for correlation analysis.
code for percentage change correlation matrix
results of correlation matrix from closing prices and percentage changes
You can already see that the change we have made has brought a change in results .
heat map of our correlation matrix
Pearson Correlation: Not Just Numbers
We calculated the Pearson correlation coefficients, which
measure the strength and direction of the linear relationship between two
variables. Interestingly, Nasdaq and S&P show a strong correlation. This
makes sense as both indices often respond to similar market factors.
Remember, correlation does not imply causation. A high
correlation between two assets doesn't necessarily mean one influences the
other. It’s an important lesson on our path to deeper financial understanding.
In this post, we dived into the intriguing world of
correlation analysis, paying attention to the importance of stationarity and
methods of interpreting results. This is just the beginning of our journey.
More explorations, questions, and discoveries await.
Komentarze
Prześlij komentarz