In this Notebook, I analyze the following five semiconductor stocks: HD, INTC, AMD, MU, NVDA, and TSM. Then, I choose the stock with the least correlation to JNJ in order to diversify a portfolio. The data was generated using the GOOGLEFINANCE historical market data script.
To learn more about diversification and how correlation in a portfolio helps to minimize risk, review this article on diversification.
-
I Imported the Pandas and Plotly Express libraries.
-
Read the CSV file into a DataFrame and set the date column as the index.
-
Used the
pct_changefunction to calculate the daily returns. -
Dropped any rows with missing data.
-
Created a correlation matrix.
-
Created a heatmap using the correlation matrix.
-
Used the
unstackfunction to find the best stock pair for diversification. -
Last, I explain which semiconductor stock would be the best candidate to add to the existing portfolio and why.