quantmod

How to create a technical indicator in quantmod package

ぃ、小莉子 提交于 2019-12-21 02:41:42
问题 I'm a newbie to R and I am facing some problems with the creation of a technical indicator. More specifically, I want to create an indicator, Fibonacci , which will be added to the chartSeries and will consist of 5 horizontal lines. The data I am working with are the closing prices of a stock. So the graph I want to create will have one horizontal line in the point of the max closing price, one horizontal line in the point of the min closing price and three horizontal lines between the

Improving a function to get stock news data from google in R

时光怂恿深爱的人放手 提交于 2019-12-20 09:24:32
问题 I've written a function to grab and parse news data from Google for a given stock symbol, but I'm sure there are ways it could be improved. For starters, my function returns an object in the GMT timezone, rather than the user's current timezone, and it fails if passed a number greater than 299 (probably because google only returns 300 stories per stock). This is somewhat in response to my own question on stack overflow, and relies heavily on this blog post. tl;dr: how can I improve this

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

拜拜、爱过 提交于 2019-12-19 18:29:10
问题 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

getSymbols downloading data for multiple symbols and calculate returns

折月煮酒 提交于 2019-12-19 11:47:09
问题 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",

get xts objects from within an environment

依然范特西╮ 提交于 2019-12-19 08:39:31
问题 I have stored xts objects inside an environment. Can I subset these objects while they are stored in an environment, i.e. act upon them "in-place"? Can I extract these objects by referring to their colname ? Below an example of what I'm getting at. # environment in which to store data data <- new.env() # Set data tickers of interest tickers <- c("FEDFUNDS", "GDPPOT", "DGS10") # import data from FRED database library("quantmod") dta <- getSymbols( tickers , src = "FRED" , env = data , adjust =

Load multiple symbols using csv with quantmod

会有一股神秘感。 提交于 2019-12-19 02:40:12
问题 I am trying to load multiple symbols using a csv file rather than downloading from Yahoo. The original code works great and uses load.packages('quantmod') tickers = spl('TLT,IWM,GLD') data <- new.env() getSymbols(tickers, src = 'yahoo', from = '1980-01-01', env = data, auto.assign = T) when I try using the code below, however, it results in "subscript out of bounds" errors later in the script: load.packages('quantmod') tickers = spl('TLT,IWM,GLD') data <- new.env() getSymbols(tickers, src=

R Recession Dates Conversion

牧云@^-^@ 提交于 2019-12-18 17:29:54
问题 I am downloading recession band data into R via quantmod . Now this comes as a binary information (in xts format) looking like this (just the first recession period shown) 1857-01-01 0 1857-02-01 0 1857-03-01 0 1857-04-01 0 1857-05-01 0 1857-06-01 0 1857-07-01 1 1857-08-01 1 1857-09-01 1 1857-10-01 1 1857-11-01 1 1857-12-01 1 1858-01-01 1 1858-02-01 1 1858-03-01 1 1858-04-01 1 1858-05-01 1 1858-06-01 1 1858-07-01 1 1858-08-01 1 1858-09-01 1 1858-10-01 1 1858-11-01 1 1858-12-01 1 Now, I have

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

倾然丶 夕夏残阳落幕 提交于 2019-12-18 13:38:39
问题 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

Add vertical lines to quantmod::chart_Series

强颜欢笑 提交于 2019-12-18 12:23:57
问题 I want to add vertical lines on several dates on a certain graph. So far I haven't managed to achieve this simple task. This is what I tried: > s <- get(getSymbols('nvmi'))["2012::"] > d1 <- index(s[100]) > d1 [1] "2012-05-24" > chart_Series(s,TA="addLines(v=d1)") Error in get.current.chob() : improperly set or missing graphics device > chart_Series(s) > abline(v=d1) # nothing > add_TA("addLines(v=d1") Error in `[.data.frame`(lenv$xdata, Env$xsubset) : undefined columns selected From what I

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

心已入冬 提交于 2019-12-17 16:41:57
问题 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