Skip to content

Asset Correlation Analysis on Stock tickers and Crypto currencies using Pandas and Seaborn

Notifications You must be signed in to change notification settings

AryaMoghaddam/Asset-Correlation-Analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 

Repository files navigation

Linkedin

Asset-Correlation-Analysis

Read my Medium article!

Medium

About The Project

image

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 🤔

Built With

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.

Getting Started

There are a couple of prerequisites that had to be installed for this project, outlined below.

Prerequisites

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

Yahoo Finance API

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.

Usage

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

image

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: image

Contact

Arya Moghadddam - [email protected]

Acknowledgments

I used these resources to validate my findings and learn more about different aspects of asset correlation.

About

Asset Correlation Analysis on Stock tickers and Crypto currencies using Pandas and Seaborn

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published