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_4_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(High > 100) %>%
autoplot(Volume) +
labs(title = "Об'єм проданих акцій за день за умови, що у цей день максимальна
ціна була більше 100 доларів", y = "Штук")
Модель для прогнозування
<- tesla %>%
fit model(trend_model = TSLM(High ~ trend()))
%>% slice(1:3) fit
# A mable: 1 x 1
trend_model
<model>
1 <TSLM>
Прогноз найвищої щоденної ціни акції на 1 рік
<- fit %>%
forecast_model ::forecast(h = "1 year")
fabletools
%>%
forecast_model autoplot()
Білий шум
gg_tsresiduals(fit)
Довірчі інтервали
%>%
forecast_model hilo(level = 95)
# A tsibble: 365 x 5 [1D]
# Key: .model [1]
.model Date High .mean `95%`
<chr> <date> <dist> <dbl> <hilo>
1 trend_model 2022-10-29 N(353, 2552) 353. [254.4233, 452.4460]95
2 trend_model 2022-10-30 N(354, 2552) 354. [254.6968, 452.7202]95
3 trend_model 2022-10-31 N(354, 2552) 354. [254.9703, 452.9943]95
4 trend_model 2022-11-01 N(354, 2552) 354. [255.2439, 453.2684]95
5 trend_model 2022-11-02 N(355, 2552) 355. [255.5174, 453.5426]95
6 trend_model 2022-11-03 N(355, 2552) 355. [255.7909, 453.8167]95
7 trend_model 2022-11-04 N(355, 2552) 355. [256.0644, 454.0909]95
8 trend_model 2022-11-05 N(355, 2552) 355. [256.3380, 454.3650]95
9 trend_model 2022-11-06 N(356, 2552) 356. [256.6115, 454.6391]95
10 trend_model 2022-11-07 N(356, 2552) 356. [256.8850, 454.9133]95
# … with 355 more rows