quantmod

R - How can I change date format when I plot an xts & zoo object?

*爱你&永不变心* 提交于 2019-12-02 00:04:21
I am wondering how I can change date format. The code I am working on is following: library(quantmod) getSymbols("AAPL") price_AAPL <- AAPL[,6] plot(price_AAPL, main = "The price of AAPL") This results I want to alter date format from "%m %d %Y" as shown in the graphic to "%b-%d-%Y" So I tried following after searching some tips: plot(price_AAPL, main = "The price of AAPL", xaxt="n") axis.Date(1, at=seq(head(index(price_AAPL),1), tail(index(price_AAPL),1), length.out=5), format="%b-%d-%Y", las=2) But this doesn't help, and doesn't even show any labeling on x-axis. I suppose that I might did

getFinancials (quantmod) and tq_get (tidy quant) not working?

若如初见. 提交于 2019-12-01 23:39:46
I'm getting the same error in both quantmod and tinyquant for financials data. Can anyone see if this is reproducable? Is this a google finance server issue? None of the below functions have been working for me.I'm not sure if it's me or the server. tq_get("AAPL", get= "financials") [1] NA Warning message: x = 'AAPL', get = 'financials': Error in thead[x]:thead[x + 1]: NA/NaN argument and: getFin("AAPL") Error in thead[x]:thead[x + 1] : NA/NaN argument Can somebody help? Yes I get the same issue for the past couple of days as well. I think it may have to do with a change on the part of Google

Issue with quantmod add_TA and chart_Series - lines and text disappear after next add_TA is called

寵の児 提交于 2019-12-01 17:16:52
I am using new chart_Series and add_TA quite a lot. It works very well for me and I find it very useful. I am trying to add a few things (horizontal lines and some text) on a graph. Here problems start to occur. After horizontal lines and text are drawn correctly they disappear if I call subsequent add_TA ... Please see the example code below which reproduces the problem: library(quantmod) getSymbols("SPY") dev.new() chart_Series(SPY) add_TA(ADX(HLC(SPY))$ADX) abline(h=15, col="red") abline(h=35, col="green") text(10, 7, "Text and horizontal lines disappear after next add_TA is called", col=

getSymbols downloading data for multiple symbols and calculate returns

非 Y 不嫁゛ 提交于 2019-12-01 13:48:27
I'm currently downloading stock data using GetSymbols from the Quantmod package and calculating the daily stock returns, and then combining the data into a dataframe. I would like to do this for a very large set of stock symbols. See example below. In stead of doing this manually I would like to use a For Loop if possible or maybe use one of the apply functions, however I can not find the solution. This is what I currently do: Symbols<-c ("XOM","MSFT","JNJ","GE","CVX","WFC","PG","JPM","VZ","PFE","T","IBM","MRK","BAC","DIS","ORCL","PM","INTC","SLB") length(Symbols) #daily returns for selected

rpy2 importr failing with xts and quantmod

落花浮王杯 提交于 2019-12-01 06:09:41
问题 I'm new to rpy2 and am having trouble using importr to import the R packages 'xts' and 'quantmod' Code is: from rpy2.robjects.packages import importr xts = importr('xts') quantmod = importr('quantmod') Errors are: LibraryError: Conflict when converting R symbol in the package "xts" to a Python symbol (.subset.xts -> _subset_xts while there is already _subset_xts) LibraryError: Conflict when converting R symbol in the package "quantmod" to a Python symbol (skeleton.TA -> skeleton_TA while

Date information disappears when save to CSV

蓝咒 提交于 2019-11-30 23:05:53
I am trying to pull some data in from the internet and then export it to a CSV file, but I am loosing my date information in the CSV file. I can't figure out why. I'm new to R so please keep responses simple. Here is my code: Library(quantmod) getSymbols("SPY", from = "2012-01-01", to = "2012-12-31") write.csv(SPY, "C:/SPY.csv") as SPY is a xts/zoo object this will do the trick: replace: write.csv(SPY, "C:/SPY.csv") with write.zoo(SPY,"C:/SPY.csv",index.name="Date",sep=",") DariusS Try: write.csv(SPY, file= "SPY.csv", row.names = index(SPY)) Are you sure that the date information is being lost

Vertical Histogram

心已入冬 提交于 2019-11-30 14:02:37
I'd like to do a vertical histogram. Ideally I should be able to put multiple on a single plot per day. If this could be combined with quantmod experimental chart_Series or some other library capable of drawing bars for a time series that would be great. Please see the attached screenshot. Ideally I could plot something like this. Is there anything built in or existing libraries that can help with this? I wrote something a year or so ago to do vertical histograms in base graphics. Here it is, with a usage example. VerticalHist <- function(x, xscale = NULL, xwidth, hist, fillCol = "gray80",

R quantmod chartSeries newTA chob - modify legend and axis (primary and secundary)

谁说胖子不能爱 提交于 2019-11-30 10:21:20
This is an advanced question. I use my own layout for the chartSeries quantmod function, and I can even create my own newTA. Everything works fine. But ... What I want to do but I can't: a) Manipulate the legend of each of the 3 charts: - move to other corner, (from "topleft" to "topright") - change the content - remove completely if needed ... b) My indicator generates 2 legends: value1 value2 same as above ... how could I modify them? how could I delete them? c) control position and range of yaxis (place it on the left / right or even remove them same when there is a secundary axis on the

Web scraping of key stats in Yahoo! Finance with R

自作多情 提交于 2019-11-30 07:52:26
问题 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

Convert daily to weekly/monthly data with R

我是研究僧i 提交于 2019-11-30 07:02:30
问题 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