使用分位数回归来拟合股票数据
我正在尝试对从雅虎检索到的数据实现 quantreg 分位数回归函数。看来我需要对股票数据执行一个过程,以便 rq() 函数可以读取数据。我不知道该怎么做。我的问题是如何将 stocj 数据转换为 rq 函数能够读取的格式。谢谢
# Quantile Regression Fit Stock data
# Get Library
library(quantmod)
library(quantreg)
# Get Stock Data
stk1 <- getSymbols("DD", from="2009-12-31", auto.assign=FALSE)
stk2 <- getSymbols("GE", from="2009-12-31", auto.assign=FALSE)
#median (l1) regression fit for the stock data.
rq(stk1 ~ stk2.x,.5)
#the 1st quartile,
rq(stk1 ~ stk2.x,.25)
#note that 8 of the 21 points lie exactly on this plane in 4-space!
#this returns the full rq process
rq(stk1 ~ stk2.x, tau=-1)
#ordinary sample median --no rank inversion ci
rq(rnorm(50) ~ 1, ci=FALSE)
#weighted sample median
rq(rnorm(50) ~ 1, weights=runif(50),ci=FALSE)
I am trying to implement the quantreg
Quantile Regression function on data I retrieved from Yahoo. It appears I need to perform a procedure on the stock data so that the rq()
function can read the data. I am not sure how to do this. My question is how do I transform the stocj data into a format the rq
function will be able to read. Thanks
# Quantile Regression Fit Stock data
# Get Library
library(quantmod)
library(quantreg)
# Get Stock Data
stk1 <- getSymbols("DD", from="2009-12-31", auto.assign=FALSE)
stk2 <- getSymbols("GE", from="2009-12-31", auto.assign=FALSE)
#median (l1) regression fit for the stock data.
rq(stk1 ~ stk2.x,.5)
#the 1st quartile,
rq(stk1 ~ stk2.x,.25)
#note that 8 of the 21 points lie exactly on this plane in 4-space!
#this returns the full rq process
rq(stk1 ~ stk2.x, tau=-1)
#ordinary sample median --no rank inversion ci
rq(rnorm(50) ~ 1, ci=FALSE)
#weighted sample median
rq(rnorm(50) ~ 1, weights=runif(50),ci=FALSE)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在发布代码时犯了一个错误。应该是stk1和stk2
I made a mistake in posting the code. It should be stk1 and stk2
您似乎正在回归价格水平,这很容易受到格兰杰和纽博尔德所说的“虚假回归”的影响。您可能想首先转换为返回,Quantmod 包等可以帮助实现这一点。
You appear to regressing price levels which is susceptible to what Granger and Newbold called 'spurious regression'. You probably want to transform to returns first, the quantmod package et al can help with that.