A dive into understanding the correlation between different stock tickers and crypto currencies.
Here's why:
- By understanding asset correlation I can better adjust my portfolio for future investements.
- Learn about Negative Correlation and it's meaning!
- Find the hidden insights of different company stocks and their values 🤔
This section should list any major frameworks/libraries used to bootstrap your project. Leave any add-ons/plugins for the acknowledgements section. Here are a few examples.
There are a couple of prerequisites that had to be installed for this project, outlined below.
1- We have to install packages
pip install matplotlib seaborn pandas
- You may run into troubles with your pip version if it's not the last updated version.
- To update pip run the command below:
pip install pip --upgrade
2- Yahoo Finance API recently went through some changes with the pandas-datareader
- You might have to install data-reader through Conda CMD if you're using Jupyter through Anaconda like me
- In addition you might have to install the package in a cell on the notebook itself through:
!pip install pandas-datareader
To use the Yahoo Finance API directly you can use the following command
get_data_yahoo
Then you can implement the data you want to read from the API by feeding the Ticker and the sart and finishing time.
To get the price changes and ploting a visualization I used the following cell:
for ticker in tickers:
plt.plot(combined[ticker], label=ticker)
plt.legend(loc="upper right")
plt.show
You can than change the scaling to logarithmic to get a better visualization of the ticker changes
After getting the price differences I set an empty list in addition to a list of stocks or Crypto currencies I wanted to find the correlation in. You can use something like the code cell below:
for chip in chips:
data_chip = pdr.get_data_yahoo(chip, start, now)
if len(colnames_chip) == 0:
#Take the closest adjusted price and copy it
combined_chip = data_chip[['Adj Close']].copy()
else:
combined_chip = combined_chip.join(data_chip['Adj Close'])
#Append to the colnames to know which stock we already added
colnames_chip.append(chip)
combined_chip.columns = colnames_chip
Next you can input the data in a combined list and visualize a seaborn heatmap, the result should look like below:
Arya Moghadddam - [email protected]
I used these resources to validate my findings and learn more about different aspects of asset correlation.