• このページは公開されるので個人情報などは記載しないこと。
  • 課題が完成したらknitしPublishする。

PCR 検査実施人数データ

d0 <- read.csv(file = ‘newly_confirmed_cases_daily.csv’)

x <- as.POSIXct(d0\(Date, format = '%Y/%m/%d') # 「/」で区切られていることに注意 y <- d0\)ALL

yhat <- rollmean(y, 31, na.pad = T)

kable(d0[300:305, 1:9])%>%kable_classic(‘striped’, full_width = F)

matplot(x = x, y = y, type = ‘l’, col = 3, main = ‘新規陽性者数の推移(日別)’, xlab = ‘年’, ylab = ‘陽性者数’) matlines(x = x, y = yhat, col = 1) grid() legend(‘topleft’, col = c(3, 1), lty = 1, legend = c(‘原系列’, ‘31日移動平均’))


ZOZO(証券コード:3092

library(quantmod)

z <- getSymbols(‘3092’, src=‘yahooj’, from = ‘2022-01-01’, to = ‘2022-12-31’, auto.assign = F)

データの保存

write.zoo(z, file = ‘zozo.csv’, sep = ‘,’, quote = F)

x <- as.POSIXct(index(z), format = ‘%Y-%m-%d’) y <- z[, ‘YJ3092.Close’]

1日分データをずらすことで当日の日付の株価が1日前のものになる。

ylag1 <- lag(y, k = 1)

align = ’right’で右寄せ移動平均となる。

yhat5 <- rollmean(ylag1, 5, fill = NA, align = ‘right’) yhat25 <- rollmean(ylag1, 25, fill = NA, align = ‘right’) yhat25c <- rollmean(y, 25, fill = NA) # 参考(通常の移動平均:中心化移動平均)

matplot(x, y, type = ‘l’, col = 3, main = ‘zozo(3092)’, xlab = ‘日’, ylab = ‘円’) matlines(x, yhat5, col = 2) matlines(x, yhat25, col = 4) matlines(x, yhat25c, col = 1) grid() legend(‘topleft’, col = c(3, 2, 4, 1), lty = 1, legend = c(‘株価’, ‘5日移動平均’, ‘25日移動平均’, ‘25日中心化移動平均(参考)’))