quantmod

How to load CSV data file into R for use with quantmod

淺唱寂寞╮ 提交于 2019-11-30 04:08:03
I am new to R and have just started to use it. I am currently experimenting with the quantmod package. The quantmod package seems to do most of what I want to do, however, I dont want to use the getSymbols() function to fetch data into R. Instead, I want to use my own data - stored as csv files on my local disc. I want to be able to slurp the data from my CSV files for use with quantmod. I came accros this article , which shows how to do read CSV files for use with quantmod, but I don't like it for at least 2 reasons: It writes a new (reformatted) CSV file to disc before loading into quantmod.

ggplot2: highlight chart area

▼魔方 西西 提交于 2019-11-29 10:44:09
I am working with some time series data and would like to highlight chart area whenever certain conditions become true. For example: require(ggplot2) require(quantmod) initDate <- "1993-01-31" endDate <- "2012-08-10" symbols <- c("SPY") getSymbols(symbols, from=initDate, to=endDate, index.class=c("POSIXt","POSIXct")) spy<-SPY$SPY.Adjusted spy$sma<-SMA(spy$SPY.Adjusted,200) spy<-spy[-(1:199),] spy<-as.data.frame(spy) ggplot(spy,aes(x=index(spy),y=spy$SPY.Adjusted))+geom_line()+geom_line(aes(x=index(spy),y=spy$sma)) The above code plots the the data, but how can I highlight the section when ever

Obtain date column from xts object [duplicate]

旧城冷巷雨未停 提交于 2019-11-29 10:36:55
This question already has an answer here: Access zoo or xts index 2 answers I used getSymbols to obtain stock data, and it returned something like this: > require(quantmod) > getSymbols(AAPL) > head(AAPL) AAPL.Open AAPL.High AAPL.Low AAPL.Close 2007-01-03 86.29 86.58 81.90 83.80 2007-01-04 84.05 85.95 83.82 85.66 2007-01-05 85.77 86.20 84.40 85.05 2007-01-08 85.96 86.53 85.28 85.47 2007-01-09 86.45 92.98 85.15 92.57 2007-01-10 94.75 97.80 93.45 97.00 > str(AAPL) An ‘xts’ object on 2007-01-03/2015-02-23 containing: Data: num [1:2049, 1:6] 86.3 84 85.8 86 86.5 ... - attr(*, "dimnames")=List of 2

Web scraping of key stats in Yahoo! Finance with R

孤街浪徒 提交于 2019-11-29 05:22:07
Is anyone experienced in scraping data from the Yahoo! Finance key statistics page with R? I am familiar scraping data directly from html using read_html , html_nodes() , and html_text() from rvest package. However, this web page MSFT key stats is a bit complicated, I am not sure if all the stats are kept in XHR, JS, or Doc. I am guessing the data is stored in JSON. If anyone knows a good way to extract and parse data for this web page with R, kindly answer my question, great thanks in advance! Or if there is a more convenient way to extract these metrics via quantmod or Quandl , kindly let me

How to load CSV data file into R for use with quantmod

微笑、不失礼 提交于 2019-11-29 01:59:15
问题 I am new to R and have just started to use it. I am currently experimenting with the quantmod package. The quantmod package seems to do most of what I want to do, however, I dont want to use the getSymbols() function to fetch data into R. Instead, I want to use my own data - stored as csv files on my local disc. I want to be able to slurp the data from my CSV files for use with quantmod. I came accros this article, which shows how to do read CSV files for use with quantmod, but I don't like

Convert daily to weekly/monthly data with R

天涯浪子 提交于 2019-11-29 00:10:49
I have daily prices series over a wide range of products; I want to convert to a new dataframe with weekly or monthly data. I first used xts in order to apply the to.weekly function...which works only for OHLC format. I am sure there may exist a function similar to to.weekly but for dataframe where the format is not OHLC. There a different posts already related to this as the following: Does rollapply() allow an array of results from call to function? or Averaging daily data into weekly data I am eventually using: length(bra) 1 2416 test<-bra[seq(1,2416,7),] Would there be a more efficient

R obtaining rownames date using quantmod

对着背影说爱祢 提交于 2019-11-28 12:07:21
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. You need to use the index function. The xts object isn't the same as a normal data.frame , and has its own way of handling dimension names. # Return all dates index(GSPC) Your code is

quantmod omitting tickers in getSymbols

流过昼夜 提交于 2019-11-28 11:45:34
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. You can use try within sapply like this: library(quantmod) WoW <- new.env() ## sapply(SiP, function(x){ try( getSymbols( x, from=as.Date("2001-01-01"), to=as

Exact time stamp on quantmod currency (FX) data

青春壹個敷衍的年華 提交于 2019-11-28 05:34:34
问题 we may collect daily data from Oanda and Yahoo finance with the quantmod package as such: getFX("USD/JPY",from="2007-01-01", to = Sys.Date()) getSymbols("EUR=X",src="yahoo",from="2002-01-01",auto.assign=F) After checking data carefully, you may notice that values from these sources are significantly different. I then wonder what exactly was the time taken the time stamp of the day for each source? It does not look to be at midnight GMT. I would appreciate if you have a clue. Thank you. 回答1:

Obtain date column from xts object [duplicate]

百般思念 提交于 2019-11-28 03:49:18
问题 This question already has an answer here: Access zoo or xts index 2 answers I used getSymbols to obtain stock data, and it returned something like this: > require(quantmod) > getSymbols(AAPL) > head(AAPL) AAPL.Open AAPL.High AAPL.Low AAPL.Close 2007-01-03 86.29 86.58 81.90 83.80 2007-01-04 84.05 85.95 83.82 85.66 2007-01-05 85.77 86.20 84.40 85.05 2007-01-08 85.96 86.53 85.28 85.47 2007-01-09 86.45 92.98 85.15 92.57 2007-01-10 94.75 97.80 93.45 97.00 > str(AAPL) An ‘xts’ object on 2007-01-03