quantmod

Calculate the average based on other columns

只谈情不闲聊 提交于 2019-12-08 06:46:10
问题 I want to calculate "average of the closing prices for the 5,10,30 consecutive trading days immediately preceding and including the Announcement Day, but excluding trading halt days (days on which trading volume is 0 or NA) For example, now we set 2014/5/7 is the Announcement day. then average of price for 5 consecutive days : average of (price of 2014/5/7,2014/5/5, 2014/5/2, 2014/4/30,2014/4/29), price of 2014/5/6 and 2014/5/1 was excluded due to 0 trading volume on those days. EDIT on 11/9

Equally Weighted Reallocation of Stock Portfolio at Specific Dates According to a Signal

喜欢而已 提交于 2019-12-07 20:33:33
问题 I want to reallocate a strategy portfolio at specific dates: require(PerformanceAnalytics) require(TTR) require(quantmod) Get asset prices and obtain the daily discrete Returns tickers = c("ABI.BR","AI.PA","AIR.PA","ALV.DE","ASML.AS") getSymbols(tickers, from="2012-01-01", to="2013-12-01") close.prices = do.call(merge, lapply(tickers, function(x) Cl(get(x)))) colnames(close.prices) = c("Anheuser-Busch InBev", "L'Air Liquide","AIRBUS GROUP","Allianz","ASML HLDG") assets.ret = ROC(close.prices

Download-Save-Load roundtrip with Quantmod in R

点点圈 提交于 2019-12-07 18:38:55
问题 I want to download data using quantmod, save them to files to be loaded later. The following piece of R code library(quantmod) symbols <- c("DEXUSUK", "STLFSI", "GDP") tmpdir <- tempdir() getSymbols(symbols, src="FRED") saveSymbols(symbols, file.path=tmpdir) rm(list = symbols) getSymbols(symbols, src="RData", dir=tmpdir, extension="RData") produces an error on the last line: Error in `colnames<-`(`*tmp*`, value = c("DEXUSUK.Open", "DEXUSUK.High", : length of 'dimnames' [2] not equal to array

Change background color panel based on year in ggplot R

﹥>﹥吖頭↗ 提交于 2019-12-07 18:01:51
问题 I'm plotting a time series for three different years 2013, 2014, 2015. require(quantmod) require(ggplot2) getSymbols("AAPL", from='2013-01-1') aapl.df = data.frame(date=time(AAPL), coredata(AAPL.Close)) ggplot(data=aapl.df, aes(x=date, y=AAPL.Close, group=1))+geom_line() How do I plot the closing price in ggplot such that each year has different background color tiles on the plot? 回答1: We can use geom_rect for separating the backgrounds. ggplot()+ geom_rect(aes(xmin = as.Date("2015-01-01"),

Getting stock news data from google in R [closed]

岁酱吖の 提交于 2019-12-07 17:23:10
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 9 months ago . I can use quantmod to get historical data and close-to-realtime quotes for stocks. I can also use quantmod to get financials data from Google. Are there any existing R packages that would let me grab Google's news feed for a given stock? If not, is there a package for reading and parsing RSS feeds in R? 回答1:

How to download multiple closing stock prices only with getSymbols into separate xts files?

自闭症网瘾萝莉.ら 提交于 2019-12-07 15:06:57
问题 How can I use getSymbols from the quantmod package to do the following: Download multiple stock price histories Select only the adjusted closing prices--i.e., suppress open/high/low and vol data Save each price history as a separate xts file, with dates I can implement steps 1 and 2, but I'm having trouble with step 3. StackOverflow has several posts on downloading and merging prices for multiple tickers, but I can't find instructions for downloading and saving in separate files. Here's what

How to show gaps in R/quantmod's chartSeries/candleChart plots

会有一股神秘感。 提交于 2019-12-07 03:19:48
问题 I am trying to show "gaps" in financial data using the plotting functions in the excellent quantmod package for R. Normally R allows you to show gaps in plots using NA values, as with: x<-1:10 y<-2*x y[4:7]<-NA plot(x,y,type="l") I would like to do something similar with R/quantmod's candleChart plots. However, rows of data containing NA's are removed before plotting (there is a na.omit command in the chartSeries code that does this) so I cannot see how to do this. An example is: require

Setting the last date collected to be a Monday

送分小仙女□ 提交于 2019-12-06 15:50:35
I can download a data set using Quantmod library(quantmod) getSymbols("SPY", from="2013-01-01", to=Sys.Date()) chartSeries(SPY) I would like the last data to be collected to be always on a Monday (so if I collect data on say Thursday, the Tuesday,Wednesday and Thursday data points will be filtered out). Is there a way to do this. Thank you for your help. replace your to=Sys.Date() with to=(Sys.Date()-c(6:0))[format((Sys.Date()-c(6:0)),"%w")=="1"] 来源: https://stackoverflow.com/questions/19320614/setting-the-last-date-collected-to-be-a-monday

Error in getSymbols function usage in R(https) [closed]

此生再无相见时 提交于 2019-12-06 14:27:36
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Running library(quantmod) getSymbols("^BSESN",src="yahoo") produces the following error message: Error in download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, : cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=F&a=0&b=01&c=2007&d=4&e=17&f=2017&g=d&q=q&y=0&z=F&x=.csv' In addition:

Download-Save-Load roundtrip with Quantmod in R

主宰稳场 提交于 2019-12-06 11:14:24
I want to download data using quantmod, save them to files to be loaded later. The following piece of R code library(quantmod) symbols <- c("DEXUSUK", "STLFSI", "GDP") tmpdir <- tempdir() getSymbols(symbols, src="FRED") saveSymbols(symbols, file.path=tmpdir) rm(list = symbols) getSymbols(symbols, src="RData", dir=tmpdir, extension="RData") produces an error on the last line: Error in `colnames<-`(`*tmp*`, value = c("DEXUSUK.Open", "DEXUSUK.High", : length of 'dimnames' [2] not equal to array extent Yet valid .RData files get created in the temp. location and can be load()-ed individually. Is