は上記の日付を使用して2つのシリーズ修正出発点
xiv <- read.table("D:/R Projects/Final Scripts/VIX_term_structure/xiv.txt", header=FALSE, stringsAsFactors=FALSE)
2010-12-02 6.559722e-02
2010-12-03 5.868252e-02
2010-12-06 1.911059e-02
2010-12-07 9.420547e-03
2010-12-08 1.734460e-02
2010-12-09 2.258762e-02
2010-12-10 8.547732e-03
2010-12-13 -1.418142e-02
2010-12-14 -6.724549e-03
2010-12-15 -2.176708e-02
2010-12-16 1.340342e-02
2010-12-17 2.195712e-02
2010-12-20 2.646760e-02
2010-12-21 1.640722e-02
2010-12-22 2.594454e-03
2010-12-23 -3.210416e-02
2010-12-27 -2.665218e-02
spy <- read.table("D:/R Projects/Final Scripts/VIX_term_structure/spy.txt", header=FALSE, stringsAsFactors =FALSE)
2010-12-02 1.280823e-02
2010-12-03 2.692895e-03
2010-12-06 -1.058301e-03
2010-12-07 5.706029e-04
2010-12-08 3.663117e-03
2010-12-09 3.894063e-03
2010-12-10 5.817504e-03
2010-12-13 6.424447e-04
2010-12-14 8.838366e-04
2010-12-15 -4.588375e-03
2010-12-16 5.817468e-03
2010-12-17 1.064127e-03
2010-12-20 2.413213e-03
2010-12-21 6.340508e-03
2010-12-22 3.109997e-03
2010-12-23 -1.431073e-03
2010-12-27 3.984963e-04
を取るには、私たちの例の準備をすることができます:その短いサンプルので、
# Prepare data for reproducible example
spy <- read.table("D:/R Projects/Final Scripts/VIX_term_structure/spy.txt", header=FALSE, stringsAsFactors =FALSE)
xiv <- read.table("D:/R Projects/Final Scripts/VIX_term_structure/xiv.txt", header=FALSE, stringsAsFactors=FALSE)
colnames(spy)[1] <- "Date"
colnames(spy)[2] <- "SPY"
colnames(xiv)[1] <- "Date"
colnames(xiv)[2] <- "XIV"
library(lubridate)
spy$Date <- ymd(spy$Date) # convert to date format
xiv$Date <- ymd(xiv$Date)
df <- merge(spy,xiv, by='Date') # Merge two series to one data frame
# Package roll for rolling linear regression
library(roll)
runs <- roll::roll_lm(x=as.matrix(df$SPY), y=as.matrix(df$XIV),width = 2, intercept = TRUE)
head(runs)
beta.spy.independant <- as.data.frame(runs$coefficients[, "x1"])
colnames(beta.spy.independant)[1] = "beta"
plot(beta.spy.independant$beta,type="l")
すべてが大丈夫です、よく我々回帰幅は2日間のみ実行してください。ですから、私がやりたいことは、回帰の開始点を修正し、それを完全なサンプル上で実行できるようにすることです。これは、スライディングウィンドウを選択するのとは対照的です。すなわち、2の幅は1:2、次に2:3,3:4などとなります。固定ウィンドウが1:2,1:3,1:4などの場合...
どうすればいいですか?