Skip to content

Instantly share code, notes, and snippets.

@mpizenberg
Created November 4, 2024 10:40
Show Gist options
  • Save mpizenberg/e228f0ef5c91b46d7560313787490875 to your computer and use it in GitHub Desktop.
Save mpizenberg/e228f0ef5c91b46d7560313787490875 to your computer and use it in GitHub Desktop.
Cardano analytics
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "matplotlib",
# "numpy",
# ]
# ///
# Start the script with "uv run reserves-treasury-plot.py"
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
# Initial values and parameters
initial_reserves = 7.66e9 # 7.66B ADA
initial_treasury = 1.58e9 # 1.58B ADA
epoch_days = 5
reward_rate = 0.003 # 0.3% per epoch
treasury_share = 0.20 # 20% of rewards go to treasury
years = 5
# Calculate number of epochs in 5 years
epochs = int((365 * years) / epoch_days)
# Initialize arrays to store values
reserves = np.zeros(epochs + 1)
treasury = np.zeros(epochs + 1)
dates = []
# Set initial values
reserves[0] = initial_reserves
treasury[0] = initial_treasury
current_date = datetime.now()
dates.append(current_date)
# Calculate values for each epoch
for i in range(1, epochs + 1):
# Calculate rewards for this epoch
epoch_rewards = reserves[i-1] * reward_rate
# Update reserves (subtract all rewards)
reserves[i] = reserves[i-1] - epoch_rewards
# Update treasury (add 20% of rewards)
treasury[i] = treasury[i-1] + (epoch_rewards * treasury_share)
# Add date
dates.append(current_date + timedelta(days=i*epoch_days))
# Create the visualization
plt.figure(figsize=(12, 6))
# Plot reserves
plt.plot(dates, reserves/1e9, label='Reserves', color='blue', linewidth=2)
# Plot treasury
plt.plot(dates, treasury/1e9, label='Treasury', color='green', linewidth=2)
# Customize the plot
plt.title('Cardano Reserves and Treasury Projection (5 Years)', pad=20)
plt.xlabel('Date')
plt.ylabel('Amount (Billion ADA)')
plt.grid(True, linestyle='--', alpha=0.7)
plt.legend()
# Rotate x-axis labels for better readability
plt.xticks(rotation=45)
# Format y-axis to show billions
plt.gca().yaxis.set_major_formatter(plt.FuncFormatter(lambda x, p: f'{x:.2f}B'))
# Adjust layout to prevent label cutoff
plt.tight_layout()
# Show the final values
final_reserves = reserves[-1]/1e9
final_treasury = treasury[-1]/1e9
print(f"After {years} years:")
print(f"Final reserves: {final_reserves:.2f}B ADA")
print(f"Final treasury: {final_treasury:.2f}B ADA")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment