quantmod

getSymbols and using lapply, Cl, and merge to extract close prices

怎甘沉沦 提交于 2019-11-28 00:35:24
I've been messing around with this for some time. I recently started using the quantmod package to perform analytics on stock prices. I have a ticker vector that looks like the following: > tickers [1] "SPY" "DIA" "IWM" "SMH" "OIH" "XLY" "XLP" "XLE" "XLI" "XLB" "XLK" "XLU" "XLV" [14] "QQQ" > str(tickers) chr [1:14] "SPY" "DIA" "IWM" "SMH" "OIH" "XLY" "XLP" "XLE" ... I wrote a function called myX to use in a lapply call to save prices for every stock in the vector tickers. It has the following code: myX <- function(tickers, start, end) { require(quantmod) getSymbols(tickers, from=start, to=end)

addSMA not drawn on graph when called from function

*爱你&永不变心* 提交于 2019-11-28 00:14:56
I am a newbie for R and have got stuck here. I am trying to draw a graph with price, sma and ema. When I call the graph from the command line it draws fine including price, sma and ema: tickers = c("BIIB","ISRG","AIG","FITB","GE","JNY","VIAB","WFM","WMB") x= 1 print(paste("Preparing ADX graph for :",paste(tickers[x]))) tmp <- read.csv(paste(tickers[x],".csv", sep=""),as.is=TRUE, header=TRUE, row.names=NULL) tmp$Date<-as.Date(tmp$Date) ydat = xts(tmp[,-1],tmp$Date) names(ydat) <- c("Open","High","Low","Close","Volume","Adjusted") # convert it into montly price ydat.monthly <- to.monthly(ydat)

R obtaining rownames date using quantmod

為{幸葍}努か 提交于 2019-11-27 19:24:54
问题 Using quantmod and collecting data from Yahoo. I am trying to get the dates that are in rownames. However I am just getting NULL. library("quantmod") sp500 <- new.env() getSymbols("^GSPC", env = sp500, src = "yahoo", from = as.Date("2008-01-04"), to = Sys.Date()) GSPC <- get("GSPC", envir = sp500) date1 <- rownames(GSPC) date1 > NULL I would be grateful for your help into getting the rowname dates into a vector. 回答1: You need to use the index function. The xts object isn't the same as a

Merge getSymbols result into one xts object

一世执手 提交于 2019-11-27 15:46:18
I have the following code: library(quantmod) tckrs <- c("TLT", "LQD", "HYG", "SPY", "DBC") NumTckrs <- length(tckrs) getSymbols(tckrs, from="1900-01-01", to=Sys.Date()) # merge to allign the start dates MainDF <- merge(Ad(TLT), Ad(LQD), Ad(HYG), Ad(SPY), Ad(DBC), all=FALSE) I would like to not have to repeat the stock symbols in the last line. Does anyone know how this could be done? Load all the data into an environment, then call Ad on each, and merge them. Also note that getSymbols returns an xts object by default, therefore your MainDF is an xts object, not a data.frame. library(quantmod)

Quantmod Error 'cannot open URL'

∥☆過路亽.° 提交于 2019-11-27 15:17:04
I started to experience an error today with the quantmod package. Anybody else have the same error when running this code (or requesting symbols in general)? library(quantmod) getSymbols("CPIAUCNS",src="FRED") Error: Error in download.file(paste(FRED.URL, "/", Symbols[[i]], "/", "downloaddata/", : cannot open URL 'http://research.stlouisfed.org/fred2/series/CPIAUCNS/downloaddata/CPIAUCNS.csv' The URL itself works fine. FRED changed the URL scheme from http:// to https://. I'm working on determining a patch that will work on all platforms. The current code still works for me on Windows if -

R/quantmod: multiple charts all using the same y-axis

自古美人都是妖i 提交于 2019-11-27 15:14:08
问题 I'm trying to plot 6 days of intraday data as 6 charts. Quantmod's experimental chart_Series() function works with par() settings. I've pre-loaded the data into bars (a vector of XTS objects) so my code looks like this: par(mfrow=c(3,2)) #3 rows, 2 columns for(d in bars){ print(chart_Series(d, type = "candlesticks") ) } This works, but each chart has its own different y-axis scale. I wanted to set a y-range that covers all 6 days, but cannot find a way to do this. I tried this: ylim=c(18000

Error in model.frame.default: variable lengths differ

给你一囗甜甜゛ 提交于 2019-11-27 14:01:25
On running a gam model using the mgcv package, I encountered a strange error message which I am unable to understand: “Error in model.frame.default(formula = death ~ pm10 + Lag(resid1, 1) + : variable lengths differ (found for 'Lag(resid1, 1)')”. The number of observations used in model1 is exactly the same as the length of the deviance residual, thus I think this error is not related to difference in data size or length. I found a fairly related error message on the web here , but that post did not receive an adequate answer, so it is not helpful to my problem. Reproducible example and data

quantmod omitting tickers in getSymbols

白昼怎懂夜的黑 提交于 2019-11-27 06:29:23
问题 I'm a complete beginner in R. I want to download historical data about current companies in S&P500 using getSymbols for a few periods. Obviously, some of companies didn't exist in a given period and R stops downloading data for the next tickers. Is there any way to enable getSymbols to simply omit tickers if their data are not existing? It would be much easier to just get the S&P 500 list for that period, but unfortunately it's not free. 回答1: You can use try within sapply like this: library

Access odd-named object returned by getSymbols

爱⌒轻易说出口 提交于 2019-11-27 05:37:21
I'm downloading data from Yahoo using quantmod : > getSymbols("HNZ-A.TO") [1] "HNZ-A.TO" Warning message: In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, : downloaded length 70893 != reported length 200 The file shows up in my R workspace. The data is there and I can use edit to see the object, but I can't use the object. For example: > head(HNZ-A.TO) Error in head(HNZ - A.TO) : object 'HNZ' not found What can I do to use this object? Use back-ticks or get . HNZA.TO <- `HNZ-A.TO` HNZA.TO <- get("HNZ-A.TO") Or you could avoid this all-together by setting auto.assign=FALSE

Quantmod, getSymbols error trying to replicate answer

心不动则不痛 提交于 2019-11-27 03:37:45
问题 I just downloaded the package Quantmod and have been playing with getSymbols . I want to be able to get data for multiple stocks as in this question: getSymbols and using lapply, Cl, and merge to extract close prices. Unfortuantely, when I try to duplicate the answer: tickers <- c("SPY","DIA","IWM","SMH","OIH","XLY", "XLP","XLE","XLI","XLB","XLK","XLU") getSymbols(tickers, from="2001-03-01", to="2011-03-11") I get the following error message: Error in download.file(paste(yahoo.URL, "s=",