Skip to content

Instantly share code, notes, and snippets.

@evd0kim
Created October 2, 2021 17:35
Show Gist options
  • Save evd0kim/431663655af9ad8648b45cf268a8f0d1 to your computer and use it in GitHub Desktop.
Save evd0kim/431663655af9ad8648b45cf268a8f0d1 to your computer and use it in GitHub Desktop.
MMV Indicator
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
# Set default figure size.
plt.rcParams['figure.figsize'] = (8, 5)
plt.style.use('dark_background')
btc_df = pd.read_csv("./data/csv/btc.csv",
parse_dates=['time'])
# Plot every 2nd step
every_i = 2
btc_df['AdrActCnt30D'] = btc_df['AdrActCnt'].rolling(window=30).mean()
btc_df['mmv'] = btc_df['CapMrktCurUSD']/btc_df['AdrActCnt30D']**2*1./np.exp(-3)
btc_df['Metcalfe'] = np.exp(-1)*btc_df['AdrActCnt30D']**2
fig, ax = plt.subplots(constrained_layout=True)
locator = mdates.AutoDateLocator()
formatter = mdates.ConciseDateFormatter(locator)
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)
ax.plot(btc_df['time'][::every_i],
btc_df['AdrActCnt'][::every_i],
label="Active Addresses")
ax.plot(btc_df['time'][::every_i],
btc_df['AdrActCnt30D'][::every_i],
label="MA 7D Active Addresses")
ax.set_ylabel('Active Addresses')
ax2 = ax.twinx()
ax2.plot(btc_df['time'][::every_i],
btc_df['PriceUSD'][::every_i],
c='red',
label="Price USD")
ax2.set_ylim([10, 70000])
ax2.set_yscale('log')
ax2.set_ylabel('Price, USD')
plt.xlabel(r'Date')
plt.grid(True)
fig.legend(loc='upper left', bbox_to_anchor=(0.1, 0., 0.1, 0.9), shadow=True, fontsize='medium')
plt.show()
"""
fig, ax = plt.subplots(constrained_layout=True)
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)
ax.plot(btc_df['time'][::every_i],
btc_df['mmv'][::every_i],
label="MMV")
ax.set_ylabel(r'$MMV$')
ax2 = ax.twinx()
ax2.plot(btc_df['time'][::every_i],
btc_df['PriceUSD'][::every_i],
c='red',
label="Price USD")
ax2.set_ylim([1, 100000])
ax2.set_yscale('log')
ax2.set_ylabel('Price, USD')
plt.xlabel(r'Date')
plt.grid(True)
fig.legend(loc='upper left', bbox_to_anchor=(0.1, 0., 0.1, 0.9), shadow=True, fontsize='medium')
plt.show()
fig, ax = plt.subplots(constrained_layout=True)
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)
ax.plot(btc_df['time'][::every_i],
btc_df['CapMrktCurUSD'][::every_i],
label="Cap")
ax.plot(btc_df['time'][::every_i],
btc_df['Metcalfe'][::every_i],
label="Metcalfe Value")
ax.set_ylabel(r'Market Cap, USD')
#ax2.set_ylim([1, 70000])
#ax2.set_yscale('log')
plt.xlabel(r'Date')
plt.grid(True)
fig.legend(loc='upper left', bbox_to_anchor=(0.1, 0., 0.1, 0.9), shadow=True, fontsize='medium')
plt.show()
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment