【问题标题】:Doing an intervention analysis using ARIMA model of stock data in R使用 R 中股票数据的 ARIMA 模型进行干预分析
【发布时间】:2019-05-12 16:02:48
【问题描述】:

我的干预分析存在一些问题。我正在模拟 Nvidia (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")

【问题讨论】:

    标签: r time-series xts arima


    【解决方案1】:

    我又花了几个小时来处理模型参数。我没有使用“纯跳跃”干预变量(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")
    

    【讨论】:

      猜你喜欢
      • 2020-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-23
      • 1970-01-01
      • 2019-11-16
      • 2021-05-20
      相关资源
      最近更新 更多