半導体指数、レーザーテックと10年債利回り

SOX指数と米国10年債利回り、デイトレ銘柄レーザーテックの時系列の関係をプロットした。

library(tidyquant)
library(dplyr)
library(ggplot2)
soxlt <- tidyquant::tq_get(c("^SOX","6920.T","^TNX"))
soxlt.tail <- soxlt %>% group_by(symbol) %>%  do(tail(., n=60))
ggplot(soxlt.tail[!is.na(soxlt.tail$close),], aes(x=date, y=close, group=symbol,color=symbol,fill=symbol))+
    geom_point() + geom_line() + geom_smooth(method = "loess") + facet_grid(symbol~., scales="free_y") + theme_minimal()

$SOXLと$XOMのGeneralized Additive Model解析

最近チャートを見ている$SOXLと$XOMのGeneralized Additive Model解析を行った。

library(tidyquant)
library(mgcv)
soxl <- tidyquant::tq_get("SOXL")
soxl$year <- as.integer(format(as.Date(soxl$date), "%Y"))
soxl$month <- as.integer(format(as.Date(soxl$date), "%m"))

fit <- gam(close ~ s(year, month), data=soxl)
plot(fit, rug = FALSE, se = FALSE, n2 = 80, main = "SOXL")
vis.gam(fit, theta = 30, phi = 30)

SOXLのGAM fit結果の3D View

エクソンモービルは下記のようなcontour plotとなる。

XOMのGAM fit結果