A comprehensive Python project for analyzing DeFi stablecoin yields and calculating a weighted “Prime Rate” for the DeFi ecosystem.
This project fetches data from DeFiLlama and other sources to:
config.py
- Centralized configuration with constants, API endpoints, and plotting stylesutils.py
- Common utility functions for data fetching, database operations, and plottingspr_fetcher_v1.py
- Main data fetcher that calculates the DeFi Prime Ratespr_plotter.py
- Visualization module for Prime Rate analysisspecific_pools_fetcher.py
- Fetcher for specific pool analysisspr_pool_identifier.py
- Pool data extraction and identification utilityyo_corr.py
- yoUSD correlation analysis with the Prime Ratecorr_analysis.py
- Market correlation analysis (BTC, ETH, SPY)spr_db_csv.py
- Database export utilitiesspr_test.py
- Testing module for correlation calculationsdata/defi_prime_rate.db
- SQLite database containing historical pool data512m_logo.png
- Logo for plot overlays.env
- Environment variables (not included, see setup)scripts/plotly_charts.js
- Main Plotly visualization script for DeFi Prime Rate analysisscripts/plotly_common.js
- Common utilities and configurations for Plotly chartsscripts/spr_charts.js
- Specific Prime Rate visualization componentsscripts/yo_corr_charts.js
- yoUSD correlation analysis visualizationsscripts/corr_analysis_charts.js
- Market correlation analysis chartsscripts/specific_pools_charts.js
- Specific pool comparison visualizationspip install -r requirements.txt
.env
file with your API key:
POLYGON_API_KEY=your_polygon_api_key_here
requests
- API callspandas
- Data manipulationmatplotlib
- Plotting and visualizationnumpy
- Numerical computationspython-dotenv
- Environment variable managementPillow
- Image processing for logo overlaysseaborn
- Enhanced plotting stylespython spr_fetcher_v1.py
This will:
python spr_plotter.py
Generates:
python specific_pools_fetcher.py
Creates visualizations comparing:
python yo_corr.py
Performs comprehensive analysis of yoUSD vs DeFi Prime Rate:
python corr_analysis.py
Analyzes correlations between:
python spr_db_csv.py
Exports specific pool data to CSV format for external analysis.
python spr_pool_identifier.py
Extracts and displays the latest APY and TVL data for pools 0-15 from the database with summary statistics.
python spr_test.py
Runs correlation calculation tests with both synthetic and real market data.
Edit config.py
to modify:
To analyze additional pools:
SPECIFIC_POOL_IDS
in config.py
POOL_NAMES
mappingDISPLAY_POOL_NAMES
if neededpool_data
Tabledate
(index) - Date of observationapy_Pool_N
- APY for pool NtvlUsd_Pool_N
- TVL in USD for pool Nweighted_apy
- Calculated weighted average APYma_apy_14d
- 14-day moving average APYpool_metadata
Tablepool_id
- DeFiLlama pool identifiername
- Pool namecurrent_tvl
- Current TVL in USDcurrent_apy
- Current APY percentagelast_updated
- Timestamp of last updateWhen adding new features:
config.py
for constantsutils.py
This project is for research and educational purposes.