0

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)
lmo
  • 37,904
  • 9
  • 56
  • 69
  • I've edited your original Q. When writing code, select it and click the button that looks like `101`. `#` are normally used for headers in normal markdown here. Can you delete your answer below as the Q has been updated to match. – Gavin Simpson Dec 04 '10 at 09:39
  • also, what is `skt2.x`, yuo don't define it anywhere. Should it not be `skt2`? – Gavin Simpson Dec 04 '10 at 09:40
  • interesting question would be also 'why do you want to use Quantreg Quantile Regression' in the first place. Like you know that it is the best solution to your problem, or maybe some other reason? – mrsteve Dec 05 '10 at 07:16

2 Answers2

0

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)  
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
0

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.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725