library(tidyverse)
library(tsibble)
library(ggplot2)
library(lubridate)
library(readxl)
library(gridExtra)
library(dplyr)
library(patchwork)
library(zoo)
library(fable)
library(feasts)
library(fabletools)
Kordyuk_Lab_5_Report
<- as_tsibble(read_csv("TSLA.csv"), index = Date)%>%
tesla glimpse()
Rows: 965
Columns: 7
$ Date <date> 2019-01-02, 2019-01-03, 2019-01-04, 2019-01-07, 2019-01-0…
$ Open <dbl> 20.40667, 20.46667, 20.40000, 21.44800, 22.79733, 22.36667…
$ High <dbl> 21.00867, 20.62667, 21.20000, 22.44933, 22.93400, 22.90000…
$ Low <dbl> 19.92000, 19.82533, 20.18200, 21.18333, 21.80133, 22.09800…
$ Close <dbl> 20.67467, 20.02400, 21.17933, 22.33067, 22.35667, 22.56867…
$ `Adj Close` <dbl> 20.67467, 20.02400, 21.17933, 22.33067, 22.35667, 22.56867…
$ Volume <dbl> 174879000, 104478000, 110911500, 113268000, 105127500, 814…
Заповнюємо пропуски
= tesla %>%
tesla fill_gaps() %>%
fill(Open, .direction = "down") %>%
fill(High, .direction = "down") %>%
fill(Low, .direction = "down") %>%
fill(Close, .direction = "down") %>%
fill(`Adj Close`, .direction = "down") %>%
fill(Volume, .direction = "down")
Модель ETS(A, N, N)
За замовчуванням підбираються оптимальні значення для α та ℓ0.
<- tesla %>%
fit model(ANN = ETS(High ~ error("A") + trend("N") + season("N"))) %>%
report()
Series: High
Model: ETS(A,N,N)
Smoothing parameters:
alpha = 0.9998998
Initial states:
l[0]
20.89667
sigma^2: 33.1481
AIC AICc BIC
15000.32 15000.34 15016.04
Графік максимальної щоденної ціни акції Tesla
components(fit) %>%
autoplot()
Прогноз макс. ціни акції за день
%>%
fit ::forecast(h = 5) %>%
fabletoolsautoplot(tesla) +
labs(y = "Зріст ціни", title = "Прогноз макс. ціни акції за день")
Об’єм продажів акцій за день за моделлю ETS(A, N, N)
<- tesla %>%
volume model(ANN = ETS(Volume ~ error("A") + trend("N") + season("N"))) %>%
report()
Series: Volume
Model: ETS(A,N,N)
Smoothing parameters:
alpha = 0.8955726
Initial states:
l[0]
118625434
sigma^2: 2.829563e+15
AIC AICc BIC
59781.09 59781.11 59796.81
Прогноз максимальної ціни акції за день за моделлю ETS(A, Ad, N)
%>%
tesla model(holt = ETS(High ~ error("A") + trend("Ad") + season("N"))) %>%
::forecast(h = 30) %>%
fabletoolsautoplot(tesla)
Максимальна ціна акції за день за моделлю ETS(A, A, A)
%>%
tesla model(ETS(High ~ error("A") + trend("A") + season("A"))) %>%
report()
Series: High
Model: ETS(A,A,A)
Smoothing parameters:
alpha = 0.9985636
beta = 0.000100091
gamma = 0.001436298
Initial states:
l[0] b[0] s[0] s[-1] s[-2] s[-3] s[-4]
21.82687 0.1471006 0.627123 0.4970544 -0.09540433 -0.7444616 -0.7429909
s[-5] s[-6]
0.09309973 0.3655797
sigma^2: 33.0687
AIC AICc BIC
15005.93 15006.16 15068.83
Прогноз об’єму продажів акцій за день
%>%
tesla model(ETS(Low)) %>%
::forecast() %>%
fabletoolsautoplot(tesla)
Точність моделі ETS(A, A, A) найнижчої ціни акції за день
%>%
tesla model(auto = ETS(Low),
AAA = ETS(Low ~ error("A") + trend("A") + season("A"))) %>%
::accuracy() fabletools
# A tibble: 2 × 10
.model .type ME RMSE MAE MPE MAPE MASE RMSSE ACF1
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 auto Training -0.0349 5.89 3.09 0.0155 2.01 0.293 0.356 0.0924
2 AAA Training 0.107 5.88 3.13 0.396 2.35 0.297 0.355 0.0935