Skip to content

Instantly share code, notes, and snippets.

@JeffBezanson
Created March 26, 2024 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffBezanson/818cddc8eafc6aab19cc78f188668c8c to your computer and use it in GitHub Desktop.
Save JeffBezanson/818cddc8eafc6aab19cc78f188668c8c to your computer and use it in GitHub Desktop.
using CSV, DataFrames, Plots, CurveFit, Dates, Statistics
btc = CSV.read("/home/jeff/Downloads/bitcoinity_data.csv", DataFrame)
mmiddle(x,y) = ismissing(x) ? y : ismissing(y) ? x : middle(x,y)
merged = mmiddle.(btc[!,:coinbase], btc[!,:others]) # use both coinbase and "other" (early) data
deleteat!(btc, findall(ismissing, merged))
logprice = log10.(mmiddle.(btc[!,:coinbase], btc[!,:others]))
logdays = map(x->log10((Date(x[1:10])-Date(2009,1,3)).value-1), btc[!,:Time]) # days since genesis block!
plot(logdays, logprice, title="Bitcoin price history log-log", xlabel="log(days)", ylabel="log(dollars)", label=nothing, yformatter=:plain)
a, power = linear_fit(logdays, logprice)
@show power
fitline = a .+ power*logdays
plot!(logdays, fitline, label="power law fit")
savefig("btcpriceloglog.png")
@show cor(fitline, logprice)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment