使用分位数回归来拟合股票数据

时间:2010-12-04 06:29:46

标签: r regression quantile quantreg

我正在尝试对从Yahoo检索到的数据实施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)

2 个答案:

答案 0 :(得分:0)

我在发布代码时犯了一个错误。它应该是stk1和stk2

# 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)  

答案 1 :(得分:0)

您似乎回归价格水平,这很容易受到Granger和Newbold所谓的“虚假回归”的影响。您可能希望首先转换为返回值,quantmod包等可以帮助解决这个问题。