This project analyzes and visualizes the correlation between multiple cryptocurrency tokens using historical price data from the CoinGecko Pro API.
- Fetch historical price data for any set of tokens
- Calculate log returns and token volatility
- Generate a correlation heatmap for selected tokens
- Save and load processed data for fast analysis
-
Clone the repository
-
Install dependencies
pip install -r requirements.txt -
Add your CoinGecko Pro API key
- Create a
.envfile in thetoken_heatmapfolder:GECKO_API=your_api_key_here
- Create a
-
Fetch and save token price data
- Run
01_data.ipynbto fetch historical prices for your chosen tokens and save the DataFrame.
- Run
-
Analyze correlations
- Open
token_correlation.ipynbto load the saved data, calculate log returns, volatility, and plot the correlation heatmap.
- Open
# Fetch prices for Bitcoin, Ethereum, and Solana
token_ids = ["bitcoin", "ethereum", "solana"]
api_key = os.getenv("GECKO_API")
df_prices = fetch_token_prices(token_ids, api_key=api_key)# Plot correlation heatmap
corr = df_prices.pct_change().apply(lambda x: np.log1p(x)).corr()
sns.heatmap(corr, annot=True, cmap='coolwarm', vmin=-1, vmax=1)
plt.title("Token Correlation Heatmap")
plt.show()- Python 3.8+
- requests
- pandas
- numpy
- matplotlib
- seaborn
- python-dotenv
- joblib
MIT License
**Feel free to fork :)