0

I am a total R newbie
So pardon me for this silly question
I want to do a regression of the stock log return on time
But I don't know how to extract the date as the X variable

Here is the R data

library(quantmod)
getSymbols("AMZN",src='yahoo',from="2010-01-01", to="2018-01-01")
Returns=dailyReturn(AMZN,subset=NULL,type='log',leading=TRUE)
lm(Returns,?????)

Thanks in advance!

Stephen
  • 7
  • 3
  • Maybe what you are looking for is ``arima``? – Ravi Dec 06 '19 at 06:36
  • Thanks for answering. No, just a simple regression against time – Stephen Dec 06 '19 at 06:38
  • ``arima`` is Time Series Regression. What you have is a time series, you can use ``arima`` in R to perform regression (x would be the time variable) – Ravi Dec 06 '19 at 06:44
  • I know, but how to do it in the simple linear regression ? The professor explicitly stated "Perform a simple linear regression of the log-return on time. " – Stephen Dec 06 '19 at 06:50

1 Answers1

1

Returns will be an xts object, so you need to use the index() function.

model <- lm(Returns$daily.returns ~ index(Returns))

Regardless of the model you end up building, index(Returns) will get you the vector of dates.

tim
  • 879
  • 1
  • 8
  • 26