<jupyter_start><jupyter_text>High-level R tutorial  Full Version: https://cryptocurrencyresearch.org/  Install Packages<jupyter_code>install.packages("pacman")
library(pacman)<jupyter_output>Warning message:
"package 'pacman' was built under R version 3.6.3"<jupyter_text>Now we can use the `p_load()` function to install and load all other packages we will need:<jupyter_code>p_load("pins","dplyr","ggplot2","caret","xgboost","kernlab","tsibble","fabletools","fable","feasts","urca") # can vctrs be removed?<jupyter_output><empty_output><jupyter_text>Get the data We can get the data using the `pins` package:<jupyter_code>board_register(name = "pins_board", url = "https://raw.githubusercontent.com/predictcrypto/pins/master/", board = "datatxt")
cryptodata <- pin_get(name = "cryptodatadownload_ETH_Binance")<jupyter_output><empty_output><jupyter_text>Preview data:<jupyter_code>cryptodata<jupyter_output><empty_output><jupyter_text>Clean Data<jupyter_code>cryptodata <- mutate(cryptodata, Volatility = ((High - Low)/Low)*100)<jupyter_output><empty_output><jupyter_text>We can look at the new column `Volatility`<jupyter_code>head(cryptodata$Volatility)<jupyter_output><empty_output><jupyter_text>Remove Symbol column:<jupyter_code>cryptodata <- select(cryptodata, -Symbol)<jupyter_output><empty_output><jupyter_text>Train/Test Split<jupyter_code>cryptodata_train <- head(cryptodata, as.integer(nrow(cryptodata)*.8))
cryptodata_test <- tail(cryptodata, as.integer(nrow(cryptodata)*.2))<jupyter_output><empty_output><jupyter_text>Visualization<jupyter_code>ggplot(data = cryptodata, aes(x = DateTime, y = Close))
price_chart <- ggplot(data = cryptodata, aes(x = DateTime, y = Close)) +
  geom_line()
# Show chart
price_chart<jupyter_output><empty_output><jupyter_text>Predictive Models  Simple linear regression:<jupyter_code>lm(data = cryptodata_train, formula = "Target24HourClose ~ .")<jupyter_output><empty_output><jupyter_text>Making a linear regression model using the `caret` package:<jupyter_code>lm_fit <- train(Target24HourClose ~ .,
                    data = cryptodata_train,
                    method = "lm")
lm_fit<jupyter_output><empty_output><jupyter_text>XGBoost model:<jupyter_code>xgb_fit <- train(Target24HourClose ~ . ,
                    data = cryptodata_train,
                    method = "xgbLinear")<jupyter_output><empty_output><jupyter_text>Additional options in `caret::train()`:<jupyter_code>svm_fit <- train(Target24HourClose ~ . ,
                    data = cryptodata_train,
                    method = "svmPoly",
                    preProc = c("center", "scale"))
svm_fit<jupyter_output><empty_output><jupyter_text>Time-Aware Cross Validation<jupyter_code>train_control <- trainControl(method = "timeslice",
                              initialWindow = 31,
                              horizon = 1,
                              fixedWindow = TRUE,
                              number = 5)
                              #,search = 'grid')<jupyter_output><empty_output><jupyter_text>Linear Model with cross validation:<jupyter_code>lm_fit <- train(Target24HourClose ~ . ,
                    data = cryptodata_train,
                    method = "lm",
                    trControl = train_control)
lm_fit<jupyter_output><empty_output><jupyter_text>Using XGBoost with cross validation: (Commented out because takes a long time)<jupyter_code>#xgb_fit <- train(Target24HourClose ~ . ,
#                    data = cryptodata_train,
#                    method = "xgbLinear",
#                    trControl = train_control)
#xgb_fit<jupyter_output><empty_output><jupyter_text>Make Predictions<jupyter_code>xgb_pred <- predict(xgb_fit, newdata = cryptodata_test)
head(xgb_pred)<jupyter_output><empty_output><jupyter_text>Evaluate Performance<jupyter_code>postResample(pred = xgb_pred, obs = cryptodata_test$Close)<jupyter_output><empty_output><jupyter_text>Timeseries Data Prep  Make a tsibble<jupyter_code>cryptodata_ts <- as_tsibble(cryptodata, index = DateTime)
cryptodata_ts<jupyter_output><empty_output><jupyter_text>Are there any gaps?<jupyter_code>has_gaps(cryptodata_ts)<jupyter_output><empty_output><jupyter_text>Find gaps<jupyter_code>scan_gaps(cryptodata_ts)<jupyter_output><empty_output><jupyter_text>Fill data gaps<jupyter_code>cryptodata_ts <- fill_gaps(cryptodata_ts)<jupyter_output><empty_output><jupyter_text>Train/Test Split<jupyter_code>ts_train <- head(cryptodata_ts, as.integer(nrow(cryptodata)*.8))
ts_test <- tail(cryptodata_ts, as.integer(nrow(cryptodata)*.2))<jupyter_output><empty_output><jupyter_text>Timeseries Predictive Modeling  Simple naive model<jupyter_code>naive_model <- model(ts_train, naive = NAIVE(Close))
naive_model<jupyter_output><empty_output><jupyter_text>Compare predictions to what actually happens with this approach:<jupyter_code>augment(naive_model)<jupyter_output><empty_output><jupyter_text>Make multiple models at the same time<jupyter_code>ts_models <- model(ts_train, snaive = SNAIVE(Close ~ lag("week")),
                             arima = ARIMA(Close))
ts_models<jupyter_output><empty_output><jupyter_text>We can look at the terms chosen for the ARIMA model:<jupyter_code>tidy(ts_models)<jupyter_output><empty_output><jupyter_text>Forecast<jupyter_code>ts_forecasts <- forecast(ts_models, h = '1 day')
ts_forecasts<jupyter_output><empty_output><jupyter_text>Accuracy on test set (all timeseries models)<jupyter_code>accuracy(ts_forecasts, ts_test)
remotes::update_packages("rlang")<jupyter_output>
{'fraction_non_alphanumeric': 0.11430651619949035, 'fraction_numerical': 0.005096468875136513, 'mean_word_length': 5.487603305785124, 'pattern_counts': {'":': 0, '<': 135, '<?xml version=': 0, '>': 115, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '29', 'dir': 'jupyter-structured-clean-dedup', 'id': '214715', 'license': 'MIT', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1900, 'n_words': 265, 'path': 'high-level/high-level_jupyter.ipynb', 'repo_name': 'ries9112/cryptocurrencyresearch-org-old', 'size': '5494'}