Last active
August 29, 2015 14:00
-
-
Save rolandkofler/d13a0384c33b3d30d381 to your computer and use it in GitHub Desktop.
Regression of weekly average bitcoin prices since 2010
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a=read.csv('http://www.quandl.com/api/v1/datasets/BAVERAGE/USD.csv?&trim_start=2010-07-17&trim_end=2018-05-02&collapse=weekly&sort_order=desc', colClasses=c('Date'='Date')) | |
names(a)[2] <- "Weighted.Price" | |
fit=lm(formula=Weighted.Price~Date, data=a) | |
#abline(fit$coefficients) | |
summary(fit) | |
library(ggplot2) | |
library(scales) | |
m = lm(log10(Weighted.Price) ~ Date, a); | |
eq <- substitute(italic(y) == 10^(a + b %.% italic(x))*","~~italic(r)^2~"="~r2, | |
list(a = format(coef(m)[1], digits = 2), | |
b = format(coef(m)[2], digits = 2, decimal.mark=".", big.mark=",", , small.interval=3), | |
r2 = format(summary(m)$r.squared, digits = 3))) | |
regressionText=as.character(as.expression(eq)); | |
ggplot(a, aes(x = Date, y = log10(Weighted.Price))) + geom_line() + | |
scale_y_continuous(labels = math_format(10^.x)) + | |
theme_bw()+ theme(panel.grid.minor = element_blank())+ | |
annotation_logticks()+ | |
stat_smooth(method="lm")+ | |
labs(list(title = "Exponential Growth of average Bitcoin Price", x = "date", y = "USD average price"))+ | |
annotate("text", x = as.Date(250, a[nrow(a),1]), y = 2.11, label = regressionText, parse = TRUE) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
creates charts like this: Imgur