library(tidyverse)
library(tsibble)
library(ggplot2)
library(lubridate)
library(readxl)
library(gridExtra)
library(dplyr)
library(patchwork)
library(zoo)
library(fable)
library(feasts)
library(fabletools)
library(urca)
Kordyuk_Lab_6_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")
%>%
tesla filter(year(Date) == 2020) %>%
autoplot(High) +
labs(y = "Найвища щоденна ціна акції у 2020 році", x = "День")
%>%
tesla filter(year(Date) == 2020) %>%
autoplot(difference(High)) +
labs(y = "Найвища щоденна ціна акції у 2020 році", x = "День")
%>%
tesla ACF(High) %>% autoplot()
%>%
tesla ACF(difference(High)) %>% autoplot()
%>%
tesla autoplot(log(Volume))
%>%
tesla autoplot(log(Volume) %>%
difference(12))
KPSS ТЕСТ
%>%
tesla features(High, unitroot_kpss)
# A tibble: 1 × 2
kpss_stat kpss_pvalue
<dbl> <dbl>
1 15.8 0.01
%>%
tesla features(High, unitroot_ndiffs)
# A tibble: 1 × 1
ndiffs
<int>
1 1
АВТОМАТИЧНИЙ ВИБІР ПОРЯДКУ РІЗНИЦЬ
%>% mutate(log_sales = log(High)) %>%
tesla features(log_sales, list(unitroot_nsdiffs, feat_stl))
# A tibble: 1 × 10
nsdiffs trend_stren…¹ seaso…² seaso…³ seaso…⁴ spikin…⁵ linea…⁶ curva…⁷ stl_e…⁸
<int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 0 1.00 0.192 0 5 1.24e-12 40.1 -11.1 0.389
# … with 1 more variable: stl_e_acf10 <dbl>, and abbreviated variable names
# ¹trend_strength, ²seasonal_strength_week, ³seasonal_peak_week,
# ⁴seasonal_trough_week, ⁵spikiness, ⁶linearity, ⁷curvature, ⁸stl_e_acf1
ARIMA
%>% filter(year(Date) == 2020) %>%
tesla model(ARIMA(Volume)) %>%
report()
Series: Volume
Model: ARIMA(2,1,1)(2,0,1)[7]
Coefficients:
ar1 ar2 ma1 sar1 sar2 sma1
0.7866 -0.1316 -0.9741 0.5099 0.0930 -0.5406
s.e. 0.0547 0.0537 0.0199 0.3445 0.0591 0.3431
sigma^2 estimated as 5.855e+15: log likelihood=-7141.55
AIC=14297.11 AICc=14297.42 BIC=14324.41
%>%
tesla ACF(High) %>%
autoplot()
%>%
tesla PACF(Volume) %>%
autoplot()