import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import timesfm
from datetime import datetime, timedelta
file_path = '/Users/ningli/Downloads/rwa-asset-timeseries-export-1744949365800.csv'
stablecoin_data = pd.read_csv(file_path)
stablecoin_data['Date'] = pd.to_datetime(stablecoin_data['Date'])
print(f"Dataset shape: {stablecoin_data.shape}")
print(f"Date range: {stablecoin_data['Date'].min()} to {stablecoin_data['Date'].max()}")
stablecoin_columns = [col for col in stablecoin_data.columns
if col not in ['Timestamp', 'Date', 'Measure']]
print(f"Number of stablecoin types: {len(stablecoin_columns)}")
print(f"Stablecoin types: {stablecoin_columns}")
daily_totals = stablecoin_data.groupby('Date')[stablecoin_columns].sum().sum(axis=1).reset_index()
daily_totals.columns = ['Date', 'TotalStablecoinSize']
daily_totals = daily_totals.sort_values('Date')
print("\nDaily Total Stablecoin Market Size Statistics:")
print(daily_totals['TotalStablecoinSize'].describe())
print("\nFirst few days of data:")
print(daily_totals.head())
print("\nLast few days of data:")
print(daily_totals.tail())
tfm = timesfm.TimesFm(
hparams=timesfm.TimesFmHparams(
context_len=32,
horizon_len=1825,
input_patch_len=32,
output_patch_len=128,
num_layers=20,
model_dims=1280,
backend="cpu"
),
checkpoint=timesfm.TimesFmCheckpoint(
huggingface_repo_id="google/timesfm-1.0-200m-pytorch"),
)
forecast_input = daily_totals['TotalStablecoinSize'].values.reshape(1, -1)
frequency_input = [0]
point_forecast, experimental_quantile_forecast = tfm.forecast(
forecast_input,
freq=frequency_input,
)
last_date = daily_totals['Date'].iloc[-1]
forecast_dates = pd.date_range(start=last_date, periods=len(point_forecast[0]) + 1, inclusive='right')
forecast_df = pd.DataFrame({
'Date': forecast_dates,
'Forecast': point_forecast[0]
})
plt.figure(figsize=(16, 8))
plt.plot(daily_totals['Date'], daily_totals['TotalStablecoinSize'], label='Historical Stablecoin Market Size')
plt.plot(forecast_df['Date'], forecast_df['Forecast'], label='Forecast (5 Years)')
plt.xlabel('Date')
plt.ylabel('Total Stablecoin Market Size (USD)')
plt.title('Stablecoin Market Size Forecast (5 Years)')
plt.grid(True, alpha=0.3)
plt.legend()
current_size = daily_totals['TotalStablecoinSize'].iloc[-1]
future_size = forecast_df['Forecast'].iloc[-1]
growth_pct = ((future_size - current_size) / current_size) * 100
plt.annotate(f'Current Size: ${current_size/1e9:.2f}B',
xy=(last_date, current_size),
xytext=(10, 30), textcoords='offset points',
arrowprops=dict(arrowstyle='->'))
plt.annotate(f'Projected Size in 5 Years: ${future_size/1e9:.2f}B\nGrowth: {growth_pct:.2f}%',
xy=(forecast_dates[-1], future_size),
xytext=(-100, 30), textcoords='offset points',
arrowprops=dict(arrowstyle='->'))
plt.gcf().autofmt_xdate()
available_stablecoins = [coin for coin in stablecoin_columns if coin in ['USDT', 'USDC', 'BUSD', 'FRAX', 'DAI']]
print(f"Available major stablecoins: {available_stablecoins}")
if available_stablecoins:
stablecoin_data_pivoted = stablecoin_data.pivot_table(
index='Date',
values=available_stablecoins,
aggfunc='sum'
).reset_index()
plt.figure(figsize=(16, 8))
else:
print("No major stablecoins found in data. Skipping individual stablecoin chart.")
plt.show()
print("\nForecast Summary:")
print(f"Current total stablecoin market size: ${current_size/1e9:.2f} billion")
print(f"Projected market size in 5 years: ${future_size/1e9:.2f} billion")
print(f"Projected growth: {growth_pct:.2f}%")
print(f"Compound Annual Growth Rate (CAGR): {((future_size/current_size)**(1/5) - 1) * 100:.2f}%")