quantmod

Merge new row into an existing xts ( purpose: to add current stock quote to historical object from quantmod)

泪湿孤枕 提交于 2019-12-06 10:40:22
问题 What I like to do is to get and attach current stock price to an historical xts object. example, require(quantmod) x=getSymbols("AAPL", from = "2014-10-27" ,auto.assign=FALSE) q = getQuote('AAPL') # this produces, > tail(x) AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted 2015-05-06 126.56 126.75 123.36 125.01 72141000 124.49 2015-05-07 124.77 126.08 124.02 125.26 43940900 125.26 2015-05-08 126.68 127.62 126.11 127.62 55550400 127.62 2015-05-11 127.39 127.56 125.63 126.32

How to overlay multiple TA in new plot using quantmod?

守給你的承諾、 提交于 2019-12-06 05:56:21
问题 We can plot candle stick chart using chart series function chartSeries(Cl(PSEC)) I have created some custom values ( I1 , I2 and I3 ) which I want to plot together(overlay) outside the candle stick pattern. I have used addTA() for this purpose chartSeries(Cl(PSEC)), TA="addTA(I1,col=2);addTA(I2,col=3);addTA(I3,col=4)") The problem is that it plots four plots for Cl(PSEC),I1,I2 and I3 separately instead of two plots which I want Cl(PSEC) and (I1,I2,I3) EDITED For clarity I am giving a sample

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

*爱你&永不变心* 提交于 2019-12-06 04:29: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,type="discrete")[-1] Now I obtain RSI signals by applying the RSI function to each asset rsi.fct =

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

╄→гoц情女王★ 提交于 2019-12-06 04:23:30
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 I have so far. Any advice on implementing the last step would be greatly appreciated. Thanks in advance

quantmod::getFX function returns “character in a standard unambiguous format”

这一生的挚爱 提交于 2019-12-06 03:53:34
I have been using quantmod::getFX on an almost daily basis recently, and for some reason today it makes my shiny app crashes. I updated R, all my packages, tried the function on two different computers, but still get the same error. To replicate the problem: library(quantmod) getFX("EUR/USD") The error is: Error in charToDate(x) : character string is not in a standard unambiguous format Let me know if you need further information. 来源: https://stackoverflow.com/questions/43289123/quantmodgetfx-function-returns-character-in-a-standard-unambiguous-format

R quantmod:getFinancials

依然范特西╮ 提交于 2019-12-06 03:37:52
I'm trying to import the financials statements of all the companies listed on the NYSE whose market cap is in greater than the first quartile of the sample. Here is my code : require(TTR) require(quantmod) data.init="2013/01/01" start.date <- as.numeric(gsub("/", "",data.init)) nyse.symbols <- stockSymbols("NYSE")[,-c(3,5)] nyse.symbols <- na.omit(nyse.symbols[which(nyse.symbols[,"MarketCap"]>0),]) ######## Selection Criteria # Filter 1 : stock mkt cap > 1st quartile --> remove the less liquid stocks mktcap.filter <- quantile(nyse.symbols[,"MarketCap"],0.25) nyse.symbols <- nyse.symbols[which

XTS dates from different sources. Using R to calculate beta

喜欢而已 提交于 2019-12-06 02:25:44
问题 I'm somewhat new to R. I imagine my error will be trivial to the experienced. I'm attempting to write an R program that will calculate beta for a number of stocks. The stock symbols are read from Input.csv , and the data is downloaded from yahoo. The code then loops through a beta calculation for each stock and outputs a csv summarizing the regressions. I got the code to work when a single risk free rate was assumed in all periods, but I believe I may need to use the actual risk free rate in

Change background color panel based on year in ggplot R

我的未来我决定 提交于 2019-12-06 01:24:00
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? bouncyball We can use geom_rect for separating the backgrounds. ggplot()+ geom_rect(aes(xmin = as.Date("2015-01-01"), xmax = as.Date("2015-12-31"), ymin = -Inf, ymax = Inf, fill = '2015'), alpha = .2)+ geom_rect(aes

Removing NA columns in xts

走远了吗. 提交于 2019-12-06 00:50:16
问题 I have an xts in the following format a b c d e f ...... 2011-01-03 11.40 NA 23.12 0.23 123.11 NA ...... 2011-01-04 11.49 NA 23.15 1.11 111.11 NA ...... 2011-01-05 NA NA 23.11 1.23 142.32 NA ...... 2011-01-06 11.64 NA 39.01 NA 124.21 NA ...... 2011-01-07 13.84 NA 12.12 1.53 152.12 NA ...... Is there a function I can apply to generate a new xts or data.frame missing the columns containing only NA? The position of the columns with the NAs isn't static so just removing those columns by name or

an alternative Quantmod ZigZag overlay

空扰寡人 提交于 2019-12-06 00:11:56
问题 i'm currently using quantmod ZigZag overlay and i noticed it is calculated a bit differently then the original overlay. I've demonstrated the difference in the following picture of RDWR using ZigZag(5%) with quantmod and a with a different program. as you can see quantmod is missing allot of significant points peaks and highs. you can also see the difference pretty clearly when using StockCharts. I think it's because of the way quantmod smooth the trend. the algorithm should be using both