import plotly.graph_objects as go
import plotly.io as pio
pio.renderers.default = "browser"

from checkonchain.general.coinmetrics_api import *
from checkonchain.btconchain.btc_add_metrics import *
from checkonchain.dcronchain.dcr_add_metrics import *

from checkonchain.general.regression_analysis import *

#Pull Coinmetrics Data for Coins
BTC = btc_add_metrics().btc_coin()
LTC = Coinmetrics_api('ltc', "2011-10-07", today).convert_to_pd()
BCH = Coinmetrics_api('bch', "2017-08-01", today).convert_to_pd()
DAS = Coinmetrics_api('dash', "2014-01-19", today).convert_to_pd()
DCR = dcr_add_metrics().dcr_coin()
XMR = Coinmetrics_api('xmr', "2014-04-18", today).convert_to_pd()
ZEC = Coinmetrics_api('zec', "2016-10-28", today).convert_to_pd()
ETH = Coinmetrics_api('eth', "2015-07-30", today).convert_to_pd()
XRP = Coinmetrics_api('xrp', "2013-01-01", today).convert_to_pd()

#Reduce dataset down to date and a single metric
metric = "CapMrktCurUSD"
BTC2 = BTC[['date', metric]]
LTC2 = LTC[['date', metric]]
BCH2 = BCH[['date', metric]]
DAS2 = DAS[['date', metric]]
DCR2 = DCR[['date', metric]]
XMR2 = XMR[['date', metric]]
ZEC2 = ZEC[['date', metric]]
ETH2 = ETH[['date', metric]]
BTC_sply = btc_add_metrics().btc_sply_curtailed(
    2400000)  #Theoretical Supply curve
BTC_real = btc_add_metrics().btc_real()  #Actual Performance
BTC_half = btc_supply_schedule(0).btc_halvings_stepped(
)  # Calculate Max-Min step to plot up Bitcoin halvings
# Blockchain.com hashrate w/ coinmetrics block (UPDATE 5 Oct 2019)
# Note need to add coinmetrics block manually
BTC_hash = btc_add_metrics().btc_hash()  #Actual Performance
#BTC_hash = pd.read_csv(r"btconchain\data\btc_blockchaincom_hashrate.csv")
#BTC_hash
#BTC_hash = pd.concat([BTC_hash.set_index('blk',drop=False),BTC_real[['blk','date']].set_index('blk',drop=True)],axis=1,join='inner')
#BTC_hash = BTC_hash.drop(BTC_hash.index[0])
#BTC_hash.reset_index(drop=True)
"""##### Decred #####"""
print('CALCULATING DECRED DATAFRAMES')
DCR_sply = dcr_add_metrics().dcr_sply(2400000 * 2 -
                                      33600 * 2)  #Theoretical Supply curve
DCR_real = dcr_add_metrics().dcr_real()  #Actual Market Performance
DCR_natv = dcr_add_metrics().dcr_natv()  #Actual On-chain Performance
# Calculate the btc_block where supply = 1.68million BTC
dcr_btc_blk_start = int(BTC_sply[BTC_sply['Sply_ideal'] == 1680000]['blk'])
# Create btc_blk height  (1BTC block == 2 DCR blocks)
DCR_sply['btc_blk'] = dcr_btc_blk_start + 0.5 * DCR_sply['blk']
DCR_real['btc_blk'] = dcr_btc_blk_start + 0.5 * DCR_real['blk']
"""##### Litecoin #####"""
print('CALCULATING LITECOIN DATAFRAMES')
#LTC_sply = ltc_add_metrics().ltc_sply(1200000*4) #Theoretical Supply curve
#LTC_real = ltc_add_metrics().ltc_real() #Actual Performance
#Calculate BTC block height assuming LTC launched on same date (0.25x)
#LTC_sply['btc_blk'] = 0.25*LTC_sply['blk']
#LTC_real['btc_blk'] = 0.25*LTC_real['blk']
"""**************************************************************************
예제 #3
0
#Onchain DCR Volumes
from checkonchain.general.standard_charts import *
from checkonchain.dcronchain.dcr_add_metrics import *

DCR_subs = dcr_add_metrics().dcr_ticket_models()

loop_data = [[0, 1, 2, 3, 4], []]
x_data = [
    DCR_subs['date'],
    DCR_subs['date'],
    DCR_subs['date'],
    DCR_subs['date'],
    DCR_subs['date'],
]
y_data = [
    DCR_subs['PoW_income_usd'].cumsum() / DCR_subs['SplyCur'],
    DCR_subs['PoS_income_usd'].cumsum() / DCR_subs['SplyCur'],
    DCR_subs['Fund_income_usd'].cumsum() / DCR_subs['SplyCur'],
    DCR_subs['Total_income_usd'].cumsum() / DCR_subs['SplyCur'],
    DCR_subs['CapMrktCurUSD'] / DCR_subs['SplyCur'],
]
name_data = ['POW', 'POS', 'Treasury', 'Total', 'Market Cap']
color_data = [
    'rgb(250, 38, 53)', 'rgb(114, 49, 163)', 'rgb(255, 192, 0)',
    'rgb(20, 169, 233)', 'rgb(239, 125, 50)', 'rgb(156,225,143)'
]
dash_data = ['solid', 'solid', 'solid', 'solid', 'solid', 'solid']
width_data = [2, 2, 2, 2, 2, 2]
opacity_data = [1, 1, 1, 1, 1, 1]
legend_data = [True, True, True, True, True, True]  #
title_data = [
예제 #4
0
# Calculate and plot pre-mine specific curves
import pandas as pd
import numpy as np

from checkonchain.dcronchain.dcr_add_metrics import *
from checkonchain.general.standard_charts import *

#Pull DataFrames
DCR_real = dcr_add_metrics().dcr_real()
#Calculate max block
blk_max = int(DCR_real['blk'][DCR_real.index[-1]])
DCR_pre = dcr_supply_schedule(0).dcr_premine(DCR_real,blk_max)


loop_data = [[0,1,2,3,4,5,6]]
x_data = [
    DCR_pre['date'],
    DCR_pre['date'],
    DCR_pre['date'],
    DCR_pre['date'],
    DCR_pre['date'],
    DCR_pre['date'],
    DCR_pre['date']
]
y_data = [
    DCR_pre['PoWSply_ideal']/DCR_pre['Sply_ideal'],
    DCR_pre['PoSSply_ideal']/DCR_pre['Sply_ideal'],
    (DCR_pre['FundSply_ideal']-1.68e6/2)/DCR_pre['Sply_ideal'],
    DCR_pre['dcr_tic_sply_avg']/DCR_pre['Sply_ideal'],
    DCR_pre['pmine_c0']/DCR_pre['Sply_ideal'],
    DCR_pre['c0_spent_pos']/DCR_pre['Sply_ideal'],
예제 #5
0
#Consolidate Coinmetrics with Supply Curve and Ticket Data
from checkonchain.dcronchain.__init__ import *
from checkonchain.dcronchain.dcr_add_metrics import *

#Plotly libraries
import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots

#number of 'Lifetimes to Print
lifetimes = 1

#Coinmetrics Data
DCR_real = dcr_add_metrics().dcr_pricing_models()
DCR_coin = Coinmetrics_api('dcr', "2016-02-08", today, 12).add_metrics()
blk_max = int(DCR_coin['blk'][DCR_coin.index[-1]] * lifetimes)

#Supply Curve Data
DCR_sply = dcr_supply_schedule(blk_max).dcr_supply_function()

#dcrdata.org
DCR_diff = Extract_dcrdata().dcr_difficulty()
DCR_perf = Extract_dcrdata().dcr_performance()

print('Coinmetrics')
print(DCR_coin.columns)
print('Supply Curve')
print(DCR_sply.columns)
print('Difficulty')
print(DCR_diff.columns)
print('Performance')
예제 #6
0
repo_dir = os.environ["GITHUB_REPO"]


# Modules for generating small data insights
class ChartOverview:
    def __init__(self, df, column):
        self.values = df[column]
        self.name = column
        self.today = self.values[-1]
        self.yesterday = self.values[-2]
        self.past_week = self.values[-7]
        self.ma28 = self.values.rolling(window=28).mean()
        self.period28 = self.ma28[-1]


df = dcr_add_metrics().dcr_ticket_models()
df = dcr_add_metrics().metric_mvrv_relative_btc(df)
df = dcr_add_metrics().metric_mrkt_real_gradient_usd(df, 28)
df = dcr_add_metrics().metric_unrealised_PnL(df)
df = dcr_add_metrics().metric_mayer_multiple(df)
df = df.set_index('date')
# Export full DataFrame to CSV and JSON
df.to_csv(f'{repo_dir}/data/full_decred_data.csv')
df.to_json(f'{repo_dir}/data/full_decred_data.json', orient='split')

# Generate Chart Overview Table v1
# Details:
#  - Market Gradient uses 28 days

columns = 'CapMVRVCur,Mayer_Multiple,PriceBTC,MrktGradient,UnrealisedPnL_Net'.split(
    ',')