Created
April 3, 2019 20:00
-
-
Save simplymathematics/1daf484c95a80acc910003b52ec7673a to your computer and use it in GitHub Desktop.
BTC forecasting models R
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
--- | |
title: "R Notebook" | |
output: html_notebook | |
--- | |
```{r} | |
library(forecast) | |
library(curl) | |
library(rjson) | |
yesterday = Sys.Date()-1 | |
start = "2013-08-01" | |
url <- paste0("https://api.coindesk.com/v1/bpi/historical/close.json?start=", start, "&end=", yesterday) | |
curl_download(url, destfile = "btc.json") | |
json_data <- fromJSON(file = "btc.json") | |
raw.data <- as.data.frame(t(as.data.frame(json_data$bpi)))$V1 | |
ts <- ts(raw.data, start =1, frequency = 12) | |
autoplot(ts, xlab = "Months Since 2013-08-01", ylab = "Bitcoin Price Index (USD)") | |
``` | |
```{r} | |
ndiffs(ts) | |
ts <- diff(ts) | |
ndiffs(ts) | |
``` | |
```{r} | |
model1 <- ses(ts) | |
model2 <- holt(ts) | |
model3 <- hw(ts) | |
model4 <- auto.arima(ts) | |
pred4 <- predict(model4, 7) | |
pred4 | |
autoplot(model1) | |
autoplot(model2) | |
autoplot(model3) | |
#ts.plot(ts, pred4) | |
``` | |
Sorry about the lack of docs. Here's a book instead: https://otexts.com/fpp2/. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment