Pemulusan
Install Packagaes
library(forecast)## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(TTR)
library(readxl)
library(tseries)
library(TTR)
library(TSA)## Registered S3 methods overwritten by 'TSA':
## method from
## fitted.Arima forecast
## plot.Arima forecast
##
## Attaching package: 'TSA'
## The following objects are masked from 'package:stats':
##
## acf, arima
## The following object is masked from 'package:utils':
##
## tar
library(ggplot2)
library(kableExtra)
library(imputeTS)##
## Attaching package: 'imputeTS'
## The following object is masked from 'package:tseries':
##
## na.remove
library(tseries)
library(dplyr)##
## Attaching package: 'dplyr'
## The following object is masked from 'package:kableExtra':
##
## group_rows
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyverse)## ── Attaching packages
## ───────────────────────────────────────
## tidyverse 1.3.2 ──
## ✔ tibble 3.1.8 ✔ purrr 0.3.4
## ✔ tidyr 1.2.0 ✔ stringr 1.4.0
## ✔ readr 2.1.2 ✔ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::group_rows() masks kableExtra::group_rows()
## ✖ dplyr::lag() masks stats::lag()
## ✖ readr::spec() masks TSA::spec()
library(graphics)
library(lmtest)## Loading required package: zoo
##
## Attaching package: 'zoo'
##
## The following object is masked from 'package:imputeTS':
##
## na.locf
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
Latar Belakang
Data yang digunakan pada proses forecasting adalah Kurs Transaksi Mata Uang yang dilakukan oleh Bank Indonesia pada rentang periode 1 tahun dengan perhitungan data harian, 1 Januari hingga 31 Desember 2021 terhadap mata uang Britania Raya, Pound sterling
Import Data
data <- read_excel("~/Downloads/kurs transaksi GBP.xlsx")
ts.data <- ts(data)
head(data)## # A tibble: 6 × 2
## Tanggal Kurs_Jual
## <dttm> <dbl>
## 1 2021-01-04 00:00:00 19128.
## 2 2021-01-05 00:00:00 19038.
## 3 2021-01-06 00:00:00 19044.
## 4 2021-01-07 00:00:00 19024.
## 5 2021-01-08 00:00:00 19158.
## 6 2021-01-11 00:00:00 19225.
str(data)## tibble [256 × 2] (S3: tbl_df/tbl/data.frame)
## $ Tanggal : POSIXct[1:256], format: "2021-01-04" "2021-01-05" ...
## $ Kurs_Jual: num [1:256] 19128 19038 19044 19024 19158 ...
Eksplorasi Data
data$Tanggal <- as.Date(data$Tanggal)
ggplot(data, aes(x=Tanggal, y= Kurs_Jual))+
geom_line()+
scale_x_date(date_breaks = "2 month", date_labels = "%Y %b %d") +
labs(title = "Plot Time Series Data Kurs Transaksi GBP",
subtitle = "(Januari 2021 sd Desember 2021)",
y="Kurs Jual GBP") +
theme(plot.title = element_text(face = "bold", hjust=.5),
plot.subtitle = element_text(hjust=.5))
## Time Series Plot Data Training dan Testing
p=0.8
freq_train=as.integer(p*nrow(data))
data$Tanggal <- as.Date(data$Tanggal)
ggplot(data, aes(x=Tanggal, y=Kurs_Jual)) +
geom_line() +
scale_x_date(date_breaks = "2 month", date_labels = "%Y %b %d") +
labs(title = "Plot Time Series Data Kurs Transaksi GBP",
subtitle = "(Januari 2021 sd Desember 2021)",
y="Kurs Jual GBP") +
geom_vline(aes(xintercept = Tanggal[freq_train],
col="Frequency_Train_Data"), lty=2, lwd=.7) +
theme(plot.title = element_text(face = "bold", hjust=.5),
plot.subtitle = element_text(hjust=.5),
legend.position = "bottom") +
scale_color_manual(name = "", values = c(Frequency_Train_Data="red"))data[freq_train,1]## # A tibble: 1 × 1
## Tanggal
## <date>
## 1 2021-10-19