def btc_sply(self, to_blk):
     df = btc_supply_schedule(to_blk).btc_supply_function()
     #Calculate projected S2F Models Valuations
     btc_s2f_model = regression_analysis().regression_constants()['btc_s2f']
     df['CapS2Fmodel'] = np.exp(
         float(btc_s2f_model['coefficient']) * np.log(df['S2F_ideal']) +
         float(btc_s2f_model['intercept']))
     df['PriceS2Fmodel'] = df['CapS2Fmodel'] / df['Sply_ideal']
     #Calc S2F Model - Bitcoins Plan B Model
     planb_s2f_model = regression_analysis().regression_constants()['planb']
     df['PricePlanBmodel'] = np.exp(
         float(planb_s2f_model['coefficient']) * np.log(df['S2F_ideal']) +
         float(planb_s2f_model['intercept']))
     df['CapPlanBmodel'] = df['PricePlanBmodel'] * df['Sply_ideal']
     return df
Esempio n. 2
0
    def btc_pricing_models(self):
        print('...Calculating Bitcoin pricing models...')
        _real = self.btc_real()
        df = _real

        # Average Cap and Average Price
        df['CapAvg'] = df['CapMrktCurUSD'].fillna(
            0.0001)  #Fill not quite to zero for Log charts/calcs
        df['CapAvg'] = df['CapAvg'].expanding().mean()
        df['PriceAvg'] = df['CapAvg'] / df['SplyCur']
        # Delta Cap and Delta Price
        df['CapDelta'] = df['CapRealUSD'] - df['CapAvg']
        df['PriceDelta'] = df['CapDelta'] / df['SplyCur']
        # Top Cap and Top Price
        df['CapTop'] = df['CapAvg'] * self.topcapconst
        df['PriceTop'] = df['CapTop'] / df['SplyCur']

        #Calc S2F Model - Specific to Bitcoin
        btc_s2f_model = regression_analysis().ln_regression(
            df, 'S2F', 'CapMrktCurUSD', 'date')['model_params']
        df['CapS2Fmodel'] = np.exp(
            float(btc_s2f_model['coefficient']) * np.log(df['S2F']) +
            float(btc_s2f_model['intercept']))
        df['PriceS2Fmodel'] = df['CapS2Fmodel'] / df['SplyCur']
        #Calc S2F Model - Bitcoins Plan B Model
        planb_s2f_model = regression_analysis().regression_constants()['planb']
        df['CapPlanBmodel'] = np.exp(
            float(planb_s2f_model['coefficient']) * np.log(df['S2F']) +
            float(planb_s2f_model['intercept']))
        df['PricePlanBmodel'] = df['CapPlanBmodel'] / df['SplyCur']

        # Inflow Cap and Inflow Price
        df['CapInflow'] = df['DailyIssuedUSD'].expanding().sum()
        df['PriceInflow'] = df['CapInflow'] / df['SplyCur']

        # Fee Cap and Fee Price
        df['CapFee'] = df['FeeTotUSD'].expanding().sum()
        df['PriceFee'] = df['CapFee'] / df['SplyCur']

        #Calculate Miner Income
        df['MinerIncome'] = df['CapInflow'] + df['CapFee']
        df['FeesPct'] = df['CapFee'] / df['MinerIncome']
        df['MinerCap'] = df['MinerIncome'].expanding().sum()

        #Moving Averages
        df['PriceUSD_128DMA'] = df['PriceUSD'].rolling(128).mean()
        df['PriceUSD_200DMA'] = df['PriceUSD'].rolling(200).mean()
        return df
Esempio n. 3
0
 def ltc_pricing_models(self):
     print('...Calculating Litecoin pricing models...')
     _real = self.ltc_real()
     df = _real
     #Calc S2F Model - Specific to Litecoin
     btc_s2f_model = regression_analysis().ln_regression(
         df, 'S2F', 'CapMrktCurUSD', 'date')['model_params']
     df['CapS2Fmodel'] = np.exp(
         float(btc_s2f_model['coefficient']) * np.log(df['S2F']) +
         float(btc_s2f_model['intercept']))
     df['PriceS2Fmodel'] = df['CapS2Fmodel'] / df['SplyCur']
     #Calc S2F Model - Bitcoins Plan B Model
     planb_s2f_model = regression_analysis().regression_constants()['planb']
     df['CapPlanBmodel'] = np.exp(
         float(planb_s2f_model['coefficient']) * np.log(df['S2F']) +
         float(planb_s2f_model['intercept']))
     df['PricePlanBmodel'] = df['CapPlanBmodel'] / df['SplyCur']
     return df
Esempio n. 4
0
    def dcr_sply(self, to_blk):  #Calculate Theoretical Supply Curve
        """
        Calculates the theoretical supply curve by block height
        INPUTS:
            to_blk      = Integer, block height to calcuate up to (from 0)
        OUTPUT COLUMNS:
            'blk'               - block height
            'blk_reward'        - Total block reward
            'Sply_ideal'        - Ideal Total Supply (DCR)
            'PoWSply_ideal'     - Ideal PoW Issued Supply (DCR)
            'PoSSply_ideal'     - Ideal PoS Issued Supply incl. 4% Premine (DCR)
            'FundSply_ideal'    - Ideal Treasury Issued Supply incl. 4% Premine (DCR)
            'inflation_ideal'   - Idealised Inflation Rate
            'S2F_ideal'         - Idealised Stock-to-Flow Ratio
            'CapS2Fmodel'       - Calculated S2F Market Cap (Linear Regression Constants)
            'PriceS2Fmodel'     - Calculated S2F Price (Linear Regression Constants)
            'CapPlanBmodel'     - Calculated S2F Market Cap (Plan B Model for Bitcoin)
            'PricePlanBmodel'   - Calculated S2F Price (Plan B Model for Bitcoin)
            'dust_limit_S2F'    - Dust Limit Price based off 'PriceS2Fmodel'
        """
        df = dcr_supply_schedule(to_blk).dcr_supply_function()
        #Calculate projected S2F Models Valuations
        #(Uses defined constants in general.regression_analysis)
        dcr_s2f_model = regression_analysis().regression_constants()['dcr_s2f']
        df['CapS2Fmodel'] = (np.exp(
            float(dcr_s2f_model['coefficient']) * np.log(df['S2F_ideal']) +
            float(dcr_s2f_model['intercept'])))
        df['PriceS2Fmodel'] = df['CapS2Fmodel'] / df['Sply_ideal']

        #Calc S2F Model - Bitcoin Plan B Model
        planb_s2f_model = regression_analysis().regression_constants()['planb']
        df['CapPlanBmodel'] = (np.exp(
            float(planb_s2f_model['coefficient']) * np.log(df['S2F_ideal']) +
            float(planb_s2f_model['intercept'])))
        df['PricePlanBmodel'] = df['CapPlanBmodel'] / df['Sply_ideal']

        #Calculate dust limit price according to S2F model
        df['dust_limit_S2F'] = df['PriceS2Fmodel'] / 1e8 * self.dust_limit
        return df
#Compile into a single dataframe with all coins
BTC_data = BTC2.dropna(axis=0)
BTC_data = pd.merge_asof(BTC_data, LTC2, on='date')
BTC_data = pd.merge_asof(BTC_data, BCH2, on='date')
BTC_data = pd.merge_asof(BTC_data, DAS2, on='date')
BTC_data = pd.merge_asof(BTC_data, DCR2, on='date')
BTC_data = pd.merge_asof(BTC_data, XMR2, on='date')
BTC_data = pd.merge_asof(BTC_data, ZEC2, on='date')
BTC_data = pd.merge_asof(BTC_data, ETH2, on='date')
BTC_data = pd.merge_asof(BTC_data, XRP2, on='date')

BTC_data

regression_analysis().ln_regression(
    BTC_data[['date', prefix + 'BTC', prefix + 'LTC']].dropna(axis=0),
    prefix + 'BTC', prefix + 'LTC', 'date')
regression_analysis().ln_regression(
    BTC_data[['date', prefix + 'BTC', prefix + 'BCH']].dropna(axis=0),
    prefix + 'BTC', prefix + 'BCH', 'date')
regression_analysis().ln_regression(
    BTC_data[['date', prefix + 'BTC', prefix + 'DAS']].dropna(axis=0),
    prefix + 'BTC', prefix + 'DAS', 'date')
regression_analysis().ln_regression(
    BTC_data[['date', prefix + 'BTC', prefix + 'DCR']].dropna(axis=0),
    prefix + 'BTC', prefix + 'DCR', 'date')
regression_analysis().ln_regression(
    BTC_data[['date', prefix + 'BTC', prefix + 'XMR']].dropna(axis=0),
    prefix + 'BTC', prefix + 'XMR', 'date')
regression_analysis().ln_regression(
    BTC_data[['date', prefix + 'BTC', prefix + 'ZEC']].dropna(axis=0),
Esempio n. 6
0
"""
#############################################################################
                    LINEAR REGRESSION - TxTfr vs MC
#############################################################################
"""
#Performan Linear Regression between x-Market Cap and y-TxTfr
# Intention is to estimate growth of transaction base vs Market Value
#Concept of Veblen good, more value = more demand
BTC_regr = BTC_coin[['CapMrktCurUSD', 'TxTfrCnt', 'blk']]
#Fill MCap forwards from early pricing data and then eliminate zeros (log-log regression)
BTC_regr['CapMrktCurUSD'] = BTC_coin['CapMrktCurUSD'].fillna(method='ffill')
BTC_regr['CapMrktCurUSD'] = BTC_regr['CapMrktCurUSD'].fillna(value=0)
BTC_regr = BTC_regr[BTC_regr['CapMrktCurUSD'] > 0]
BTC_regr = BTC_regr[BTC_regr['TxTfrCnt'] > 0]
#Run Regression Model and extract parameters
model = regression_analysis().ln_regression(BTC_regr, 'CapMrktCurUSD',
                                            'TxTfrCnt', 'blk')
intercept = float(model['model_params']['intercept'])
coefficient = float(model['model_params']['coefficient'])
#Apply regression model assuming Plan Bs MCap S2f model
BTC_sply_fwd = BTC_sply  #[BTC_sply['blk']>blk_cur]
BTC_sply_fwd = BTC_sply_fwd[[
    'blk', 'Sply_ideal', 'PricePlanBmodel', 'CapPlanBmodel'
]]
BTC_sply_fwd['TxTfrCnt'] = np.exp(intercept + coefficient *
                                  np.log(BTC_sply_fwd['CapPlanBmodel']))

loop_data = [[
    0,
    1,
], []]
x_data = [
Esempio n. 7
0
 def dcr_real(self):
     """
     Compiles Coinmetrics (dcr_coin) and dcrdata (dcr_natv) for general data analytics
     OUTPUT COLUMNS:
         TIME VARIABLES
             'date'                  - Datetime 
             'blk'                   - Block Height
             'age_days'              - Coin Age in Days
             'age_sply'              - Coin age in Supply (SplyCur/21M)
             'window'                - Count of difficulty window
             'CapMrktCurUSD'         - Market Cap (USD)
             'CapRealUSD'            - Realised Cap (USD)
             'PriceBTC'              - Price in BTC
             'PriceUSD'              - Price in USD
             'PriceRealUSD'          - Realised Price (USD)
             'DailyIssuedNtv'        - Daily DCR Issued
             'DailyIssuedUSD'        - Daily Issued USD
             'TxTfrValNtv'           - Daily Transferred DCR
             'TxTfrValUSD'           - Daily Transferred USD
             'FeeTotNtv'             - Total Fees DCR
             'FeeTotUSD'             - Total Fees USD
             'S2F'                   - Actual Stock-to-Flow Ratio
             'inf_pct_ann'           - Annual Inflation Rate
             'SplyCur'               - DCR Supply (Coinmetrics)
             'dcr_sply'              - DCR Supply (dcrdata)
             'dcr_tic_sply_avg'      - Average DCR Supply locked in Tickets over day
             'tic_day'               - Number of Tickets purchased that day
             'tic_price_avg'         - Average ticket price over the day
             'tic_pool_avg'          - Number of tickets in Pool (Target 40,960)
             'DiffMean'              - Average PoW Difficulty on day (Coinmetrics)
             'pow_diff_avg'          - Average PoW Difficulty on day (dcrdata)
             'pow_hashrate_THs_avg'  - Average PoW Hashrate on day (TH/s)
             'pow_work_TH'           - Cummulative PoW in TH
     """
     print(
         '...Combining Decred specific metrics - (coinmetrics + dcrdata)...'
     )
     _coin = self.dcr_coin()  #Coinmetrics by date
     _natv = self.dcr_natv()  #dcrdata API by block
     #_blk_max = int(_coin['blk'][_coin.index[-1]])
     #Cull _coin to Key Columns
     _coin = _coin[[
         'date', 'blk', 'age_days', 'age_sply', 'CapMrktCurUSD',
         'CapRealUSD', 'DiffMean', 'PriceBTC', 'PriceUSD', 'PriceRealUSD',
         'SplyCur', 'DailyIssuedNtv', 'DailyIssuedUSD', 'S2F',
         'inf_pct_ann', 'TxTfrValNtv', 'TxTfrValUSD', 'FeeTotNtv',
         'FeeTotUSD'
     ]]
     _coin['CapS2FModel'] = regression_analysis()
     #Add new columns for transferring _natv data to_coin
     _coin['tic_day'] = 0.0
     _coin['tic_price_avg'] = 0.0
     _coin['tic_pool_avg'] = 0.0
     _coin['dcr_tic_sply_avg'] = 0.0
     _coin['pow_diff_avg'] = 0.0
     _coin['pow_hashrate_THs_avg'] = 0.0
     blk_from = 0  #Captures last _coin block (block from)
     _row = 0  #Captures current block height (natv is by block)
     for i in _coin['blk']:
         #Sum tickets bought on the day
         _coin.loc[_row, ['tic_day']] = (
             float(_natv.loc[blk_from:i,
                             ['tic_blk']].sum())  #tickets bought that day
         )
         #Average Ticket price over day
         _coin.loc[_row, ['tic_price_avg']] = (
             float(_natv.loc[blk_from:i,
                             ['tic_price']].mean())  #avg tic price that day
         )
         #Average Tickets in Pool over day
         _coin.loc[_row, ['tic_pool_avg']] = (
             float(_natv.loc[blk_from:i,
                             ['tic_pool']].mean())  #avg tic price that day
         )
         #Average DCR Locked in Tickets over day
         _coin.loc[_row, ['dcr_tic_sply_avg']] = (
             float(_natv.loc[
                 blk_from:i,
                 ['dcr_tic_sply']].mean())  #avg tic price that day
         )
         #Average PoW Difficulty
         _coin.loc[_row, ['pow_diff_avg']] = (
             float(_natv.loc[blk_from:i,
                             ['pow_diff']].mean())  #avg hashrate that day
         )
         #Average PoW Hashrate in TH/s
         _coin.loc[_row, ['pow_hashrate_THs_avg']] = (
             float(_natv.loc[
                 blk_from:i,
                 ['pow_hashrate_THs']].mean())  #avg hashrate that day
         )
         blk_from = i
         _row += 1
     #Merge _coin and _natv
     df = pd.merge(_coin,
                   _natv.drop([
                       'tic_cnt_window', 'pow_diff', 'pow_hashrate_THs',
                       'tic_pool', 'dcr_tic_sply'
                   ],
                              axis=1),
                   on='blk',
                   how='left')
     #Compile into final ordered dataframe
     df = df[[
         'date',
         'blk',
         'age_days',
         'age_sply',
         'window',  #Time Metrics
         'CapMrktCurUSD',
         'CapRealUSD',
         'PriceBTC',
         'PriceUSD',
         'PriceRealUSD',  #Value Metrics
         'DailyIssuedNtv',
         'DailyIssuedUSD',
         'TxTfrValNtv',
         'TxTfrValUSD',  #Transaction Metrics
         'FeeTotNtv',
         'FeeTotUSD',  #Fee Metrics
         'S2F',
         'inf_pct_ann',
         'SplyCur',
         'dcr_sply',  #Supply Metrics
         'dcr_tic_sply_avg',
         'tic_day',
         'tic_price_avg',
         'tic_pool_avg',  #Ticket Metrics
         'DiffMean',
         'pow_diff_avg',
         'pow_hashrate_THs_avg',
         'pow_work_TH'  #PoW Metrics
     ]]
     return df