The Real GBTC Premium (Capriole Investments)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © caprioleio

//@version=5
indicator('The Real GBTC Premium (Capriole Investments)', overlay=false)

// gbtc btc per share based on 2% fee per annum. Data is from 04 Dec 2020

ticker = input.string('OTC:GBTC', 'Grayscale ticker', options=['OTC:GBTC', 'FTX:GBTCUSD'])

btc = request.security('COINBASE:BTCUSD', timeframe.period, close)
gbtc = nz(request.security(ticker, timeframe.period, close))
gbtc_v = nz(request.security(ticker, timeframe.period, volume))

btc_per_share_data = 0.00090292  // as at 19/7/2023: https://grayscale.com/products/grayscale-bitcoin-trust/
btc_share_date = timestamp(2023, 7, 19, 00, 00)
gbtc_fee = 0.02

days_since_data = (time - btc_share_date) / (60 * 60 * 24 * 1000 * 1440 / timeframe.multiplier)
btc_per_share = btc_per_share_data * math.pow(1 - gbtc_fee, days_since_data / 365)

premium = (gbtc / (btc * btc_per_share) - 1) * 100

trading = not(gbtc == gbtc[1] and gbtc_v == gbtc_v[1])

premium_fin = 0.0
premium_fin := trading ? premium : premium_fin[1]

clr = premium_fin < 0 ? color.red : color.green
plot(trading ? premium : na, style=plot.style_columns, color=color.new(clr,0))
plot(premium_fin, style=plot.style_columns, color=color.new(clr,40))

var table_source = table(na)
table_source := table.new(position=position.bottom_left, columns=1, rows=1, bgcolor=color.white, border_width=1)
table.cell(table_source, 0, 0, text='Source: Capriole Investments Limited', bgcolor=color.white, text_color=color.black, width=20, height=7, text_size=size.normal, text_halign=text.align_left)