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

发布于 2024-10-05 19:45:21 字数 787 浏览 5 评论 0原文

我正在尝试对从雅虎检索到的数据实现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

若水微香 2024-10-12 19:45:21

我在发布代码时犯了一个错误。应该是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)  

I made a mistake in posting the code. It should be stk1 and 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)  
过期情话 2024-10-12 19:45:21

您似乎正在回归价格水平,这很容易受到格兰杰和纽博尔德所说的“虚假回归”的影响。您可能想首先转换为返回,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文