【问题标题】:Using a quantile regression to fit stock data使用分位数回归拟合股票数据
【发布时间】:2011-05-20 03:11:06
【问题描述】:

我正在尝试对从 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)

【问题讨论】:

  • 我已经编辑了你原来的 Q。编写代码时,选择它并单击看起来像 101 的按钮。 # 通常用于此处的正常降价中的标题。您可以删除下面的答案,因为 Q 已更新为匹配。
  • 另外,skt2.x 是什么,你别在任何地方定义它。不应该是skt2吗?
  • 有趣的问题也是“你为什么要首先使用 Quantreg Quantile Regression”。就像您知道这是解决您的问题的最佳解决方案一样,还是出于其他原因?

标签: r regression quantile quantreg


【解决方案1】:

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

【讨论】:

  • 标记区域并点击“101010”按钮排版为代码。
【解决方案2】:

您似乎在回归价格水平,这很容易受到 Granger 和 Newbold 所说的“虚假回归”的影响。您可能想先转换为返回,quantmod 包等可以帮助您。

【讨论】:

    猜你喜欢
    • 2012-11-26
    • 1970-01-01
    • 2011-01-17
    • 2018-01-04
    • 2011-03-15
    • 1970-01-01
    • 2014-06-19
    • 1970-01-01
    • 2014-12-24
    相关资源
    最近更新 更多