current_date <- Sys.Date()
ts <- W.USD_edited
# ts <- PYTH.USD_edited
# ts <- LINK.USD_edited
# ts <- ETH.USD_edited
# ts <- BTC.USD_edited
# ts <- TIA.USD_edited
ts <- na.omit(ts)
# logEstimate = lm(log(ts$Close) ~ log(ts$Day))
logEstimate = lm(log(ts$Close) ~ ts$Day)
rmse <- sqrt(median(residuals(logEstimate)^2)) # root median squared error
estimate <- predict(logEstimate)
top_estimate <- estimate + rmse
estimate_066 <- estimate + 0.66 * rmse
estimate_033 <- estimate + 0.33 * rmse
estimate_minus_033 <- estimate - 0.33 * rmse
estimate_minus_066 <- estimate - 0.66 * rmse
bottom_estimate <- estimate - rmse
# generate text box content
last_close <- ts$Close[length(ts$Close)]
log_reg_pos = round(last_close / exp(estimate[[length(estimate)]]), digits = 2)
text_box_str <- paste("Generated: ", current_date,
", Last close: ", round(last_close, digits = 2),
", RMSE: ", round(rmse, digits = 3),
", +RMSE: ", round(exp(top_estimate[length(top_estimate)]), digits = 2),
", -RMSE: ", round(exp(bottom_estimate[length(bottom_estimate)]), digits = 2),
", last_close/last_estimate: ", log_reg_pos)
# plot
plot(ts$Day, log(ts$Close), type='l', col="blue",
xlab = "t", ylab = "close", xaxt="n", yaxt="n")
grid()
lines(ts$Day, top_estimate)
lines(ts$Day, estimate_066, lty="dotdash")
lines(ts$Day, estimate_033, lty="dotted")
lines(ts$Day, estimate_minus_033, lty="dashed")
lines(ts$Day, estimate_minus_066, lty="dotdash")
lines(ts$Day, bottom_estimate)
mtext(text_box_str, side=3, cex=0.8)
y_axis_labels_orig <- axis(side = 2, labels = FALSE)
y_axis_labels <- round(exp(y_axis_labels_orig), 2)
axis(side = 2, at=y_axis_labels_orig, labels = y_axis_labels)