quantmod

Change line colors of technical indicators made by R quantmod TTR?

折月煮酒 提交于 2020-02-04 07:32:07
问题 I tried to plot with chartSeries in the R package quantmod, and add SMI lines using the addSMI() method. SMI generates two lines - the solid line is visible while the dotted line is not. Can anybody propose a way to change the color of the dotted line so that it is more noticeable? Here are the codes. I also attached an image generated. library(quantmod) x<-getSymbols("IBM", src='yahoo', from="2014-11-20", to="2015-05-20", auto.assign=FALSE) chartSeries(x, name=paste(stockFirmName,"(",stock,"

R appears to fail to execute a line in a function [duplicate]

时光毁灭记忆、已成空白 提交于 2020-01-26 02:09:17
问题 This question already has an answer here : addSMA not drawn on graph when called from function (1 answer) Closed 6 years ago . I'm a bit puzzled. I have a created a custom function: doGraph <- function(x){ dev.new(); symb <- getSymbols(x, auto.assign = FALSE); chartSeries(symb, subset = 'last 3 months', name=x); addBBands(); addMACD(); } doGraph("AAPL") The above code does not add the Bollinger Bands, as I would expect (by the addBBands() call). However, if I remove the addMACD() call, the

How to calculate percentage change from different rows over different spans

早过忘川 提交于 2020-01-21 10:02:49
问题 I am trying to calculate the percentage change in price for quarterly data of companies recognized by a gvkey (1001, 1384, etc...). and it's corresponding quarterly stock price, PRCCQ . gvkey PRCCQ 1 1004 23.750 2 1004 13.875 3 1004 11.250 4 1004 10.375 5 1004 13.600 6 1004 14.000 7 1004 17.060 8 1004 8.150 9 1004 7.400 10 1004 11.440 11 1004 6.200 12 1004 5.500 13 1004 4.450 14 1004 4.500 15 1004 8.010 What I am trying to do is add 8 columns showing 1 quarter return, 2 quarter return, etc.

How to calculate percentage change from different rows over different spans

拈花ヽ惹草 提交于 2020-01-21 10:02:25
问题 I am trying to calculate the percentage change in price for quarterly data of companies recognized by a gvkey (1001, 1384, etc...). and it's corresponding quarterly stock price, PRCCQ . gvkey PRCCQ 1 1004 23.750 2 1004 13.875 3 1004 11.250 4 1004 10.375 5 1004 13.600 6 1004 14.000 7 1004 17.060 8 1004 8.150 9 1004 7.400 10 1004 11.440 11 1004 6.200 12 1004 5.500 13 1004 4.450 14 1004 4.500 15 1004 8.010 What I am trying to do is add 8 columns showing 1 quarter return, 2 quarter return, etc.

Adding Points, Legends and Text to plots using xts objects

岁酱吖の 提交于 2020-01-12 07:49:04
问题 I am starting on a bit of analysis on pairs of stocks (pairs trading) and here is the function I wrote for producing a graph (pairs.report - listed below). I need to plot three different lines in a single plot. The function I have listed does what I want it to do, but it will take a bit of work if I want a fine customisation in the x-axis (the time line). As it is, it prints just the years (for 10 years of data) or the months (for 6 months of data) in the x-axis, with no formatting for ticks.

R use apply function on xts zoo class

狂风中的少年 提交于 2020-01-11 13:37:09
问题 I am new in R and I try to use apply function on the xts zoo class, however it shows error. I have a formula: ((2*Close-High-Low)/(High-Low)) * Volume Input: y <- getSymbols("0005.HK", auto.assign = FALSE, src = "yahoo") Error: y$II <- apply(y,2,function(x) (2Cl(x) - Hi(x) - Lo(x)) / ((Hi(x) - Lo(x)) * Vo(stk))) Error: unexpected symbol in "apply(y,2,function(x) (2Cl" and then I tried another one: Error: y$II <- apply(y,2,function(x) (2(x[,4]) - x[,2] - x[,3]) / (x[,2] - x[,3]) * x[,5]) Error

R quantmod chart_Series: using large fonts for y axis

倾然丶 夕夏残阳落幕 提交于 2020-01-11 11:27:54
问题 I am trying to use a larger font size for those who have poor eyesight. library(quantmod) getSymbols("SPY", from="2013-11-01", to=Sys.Date()) chart_Series(SPY) myPars <-chart_pars() myPars$cex<-1.5 chart1 <- chart_Series(SPY, pars=myPars) chart1 However, when I do this, only a part of the y axis numbers scale are shown. Is it possible to shift the chart, so the y axis numbers scale are not cut off. Thank you for your help. 回答1: When I try your code (Note this is in R 3.1.0 in R studio though)

ggplot2: highlight chart area

时光毁灭记忆、已成空白 提交于 2020-01-10 03:58:30
问题 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

Finding the second highest value in quantmod by time period

試著忘記壹切 提交于 2020-01-05 05:37:26
问题 I am trying to find the maximal and the second largest value during a 6 months interval. I am using runMax to find the first value but I can't figure out how to do for the second one. Here's my code so far: library(quantmod) library(TTR) getSymbols("GOOGL") GOOGL_mo<-to.monthly(GOOGL)#to get monthly data GOOGL_mo$Max_6mo<-runMax(GOOGL.High, 6)#add a column with the max value during a 6 months period I would like to add another column with the second largest value to have something like this:

Cron job in R shiny - shiny task schedule in shinyapps io

霸气de小男生 提交于 2020-01-03 19:01:26
问题 I am planing on getting stock data from yahoo finance at the end of each business day (using quantmod). this data is then used to update my shiny app. Now I have to do this manually, I update my csv file which I than upload to shinyapps.io each day. This csv is used for the app. Is there a way to fully automate this in shiny/shinyapps.io ? Now I know that this has been asked here before, at least in a similar setting. However there has not been a helpful answer provided to setting up a cron