Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating historical prices in quantmod

Tags:

r

xts

quantmod

Quantmod's getSymbols() fetches historical prices up till yesterday's close. I do my analysis in the morning and would like to update the series with the current quote (I only use adjusted prices). I can't seem to get it to work. When I use this code :

getSymbols('AGNC')
q <- getQuote('AGNC')
d <- Sys.Date()
qq<- q$Last
x <- zoo(qq,d)
t <- rbind.zoo(Ad(AGNC), x)
print(tail(t))

It prints out OK, but when I try to do something further, like:

dum <- dailyReturn(t)

I get the following error:

Error in colnames<-(*tmp*, value = "daily.returns") : attempt to set colnames on object with less than two dimensions

Any ideas?

like image 666
user1478354 Avatar asked Jan 20 '26 09:01

user1478354


1 Answers

library(quantmod)
getSymbols('AGNC')
q <- getQuote('AGNC')
d <- Sys.Date()
qq<- q$Last
x <- xts(qq,d)
t <- rbind(Ad(AGNC), x)
print(tail(t))
dailyReturn(t)
like image 75
GSee Avatar answered Jan 22 '26 00:01

GSee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!