我的干预分析遇到一些问题。我正在建模当英伟达(NVDA)于2016年4月宣布深度学习超级计算机时对收盘价的影响。我添加了一个虚拟变量,该变量在干预日期之前为0,之后为1,并将其添加为回归变量在我的模型中。我的想法是,我无法理解输出,因为我从干预系数中从未得到任何重要信息。我不知道我做错了什么。这是我的代码:
rm(list=ls())
library('ggplot2'); library('forecast'); library('tseries'); library('xts'); library(quantmod) ; library(lmtest)
start <- as.Date("2005-01-01")
end <- as.Date("2018-10-01")
getSymbols("NVDA", src = "yahoo", from = start, to = end)
plot(NVDA[, "NVDA.Close"], main = "NVIDIA")
# Adding dummy intervention variable
intDate<-as.Date("2016-04-05") # sets the intervention Date
closing = NVDA[, "NVDA.Close"]
closing$Intervention = 0
for (i in 1:nrow(closing)){
if (index(closing[i,1]) < intDate){
closing[i,"Intervention"] = 0
}
if(index(closing[i,1]) >= intDate){
closing[i,"Intervention"] = 1
}
}
model<-auto.arima(closing[,"NVDA.Close"], xreg = closing[,"Intervention"])
model
coeftest(model)
dates = as.Date(index(closing),"YYYY-MM-DD")
fittedVal = xts(fitted.values(model), dates)
plot(NVDA[,"NVDA.Close"], col = "blue", type = "l")
lines(fittedVal, col = "red", type = "l")
答案 0 :(得分:0)
我花了几个小时弄乱了模型参数。我没有使用“纯跳跃”干预变量(0和1),而是尝试了200个周期内逐渐增加的效果。这有助于捕获干预效果并使所有系数显着,但是由于模型的残差不是正态分布的,因此我无法真正使用结果。这是我使用的代码:
rm(list=ls())
library('ggplot2'); library('forecast'); library('tseries'); library('xts'); library(quantmod) ; library(lmtest)
start <- as.Date("2005-01-01")
end <- as.Date("2018-10-01")
getSymbols("NVDA", src = "yahoo", from = start, to = end)
plot(NVDA[, "NVDA.Close"], main = "NVIDIA")
# Adding dummy intervention variable
intDate<-as.Date("2016-04-05")
closing = NVDA[, "NVDA.Close"]
periods = 200
count = 0
closing$Intervention = 0
for (i in 1:nrow(closing)){
if (index(closing[i,1]) < intDate){
closing[i,"Intervention"] = 0
}
if(index(closing[i,1]) >= intDate){
count = count + 1
if(count<=periods){
closing[i,"Intervention"] = count*0.025
}
if(count>periods){
closing[i,"Intervention"] = periods*0.025
}
}
}
model<-auto.arima(closing[,"NVDA.Close"], xreg = closing[,"Intervention"])
model
coeftest(model)
dates = as.Date(index(closing),"YYYY-MM-DD")
fittedVal = xts(fitted.values(model), dates)
plot(NVDA[,"NVDA.Close"], col = "blue", type = "l")
lines(fittedVal, col = "red", type = "l")