quantmod

R - Loading External Indicators into Quantstrat

你。 提交于 2019-12-04 11:48:30
问题 I noticed that Quantstrat typically takes indicators that are based on price. However, I would like to load several indicators that have been externally calculated along with the price data. For instance, I have 2 extra columns in a csv file that contain my indicators (numbered 1-9). I want to generate a signal based on the numbers in these columns. Thus far, I have been unable to get Quantstrat to read the columns in the csv file. I've attached my code below: library(quantmod) library

convert yyyymm on factor class to character class to be used with ChartSeries()

北慕城南 提交于 2019-12-04 05:09:32
问题 I read a CSV file using read.csv() command and I want to convert into xts and graph with chartSeries() . I changed into a matrix by doing: MyData <- as.matrix(MyData) When I convert to xts using MyData_xts <- xts(MyData[,-1], order.by=as.POSIXct(MyData[,1])) I get the following error message: Error in as.POSIXlt.character(as.character(x), ...) : character string is not in a standard unambiguous format The column that has my index is in the yyyymm format. I've read that that may be a problem,

quantmod - SSL: unable to get local issuer certificate in R

流过昼夜 提交于 2019-12-03 21:56:11
I’m trying to use quantmod package in R to get financial data from Yahoo. It works perfectly on my personal laptops (Mac and Win). But I cannot make it work on my working computer (Win7). My code is: getSymbols("JPM", src = "yahoo") Please note it only doesn't work on my company laptop. Here's the error code: Error in curl::curl_download(cu, tmp, handle = h) : SSL certificate problem: unable to get local issuer certificate I have tried to solve the problems in the following ways: install httr package Delete curl , quantmod and reinstall Update to the latest version of R, RStudio, curl , httr ,

Quantmod save tickers to files in a loop or lapply

我只是一个虾纸丫 提交于 2019-12-03 21:28:34
I am stuck with a minor quantmod problem; if anyone can suggest a tweak to my code, I’d really appreciate that. I don’t know progamming as such; maybe that’s why I miss the obvious. The problem is arising because getSymbols takes a string as input (e.g. "YHOO"), but returns just YHOO (without quotes) as the xts object which holds the data. Also, for market indices, Yahoo includes a caret in the string for the code (e.g. "^GSPC"), but quantmod returns plain GSPC as the data object. I am trying to download and save to individual binary files the data of multiple tickers. This is so as to create

Optimize moving averages calculation - is it possible?

纵饮孤独 提交于 2019-12-03 21:07:33
Is it possible to optimize (make it much faster) this piece of code: out <- do.call(rbind, lapply(split(Cl(cumulativeBars), "days"), function(x) { previousFullBars <- barsEndptCl[as.Date(index(barsEndptCl), tz=indexTZ(barsEndptCl)) < as.Date(last(index(x)), tz=indexTZ(x)), ] if (NROW(previousFullBars) >= 4) { last(SMA(last(rbind(previousFullBars, x), n=6), n=5)) } else { xts(NA, order.by=index(x)) } })) Below you can find my original question with all the code example that runs but a bit to slow for my needs. ORIGINAL QUESTION: After I was able to transform xts to lower frequency in cumulative

How to plot S&P 500 and Sotheby's Time Series in one ggplot?

独自空忆成欢 提交于 2019-12-03 20:36:50
I am downloading with the quantmod package the S&P 500 time series and the Sotheby's stock: library(zoo) library(tseries) library(quantmod) library(ggplot2) env1 = new.env() getSymbols("^GSPC", env = env1, src ="yahoo", from = as.Date("1988-06-01"),to = as.Date("2013-05-29")) GSPC = env1$GSPC gspc.df = data.frame(date=time(GSPC), coredata(GSPC)) env2 = new.env() getSymbols("BID", env = env2, src ="yahoo", from = as.Date("1988-06-01"),to = as.Date("2013-05-29")) BID = env2$BID sothebys.df = data.frame(date=time(BID), coredata(BID)) My objective is to merge or melt the Adjusted Prices together

How can I eliminate quote marks around parameters in R function?

吃可爱长大的小学妹 提交于 2019-12-03 16:28:06
Here are the first few lines of an R function that works: teetor <- function(x,y) { require("quantmod") require("tseries") alpha <- getSymbols(x, auto.assign=FALSE) bravo <- getSymbols(y, auto.assign=FALSE) t <- as.data.frame(merge(alpha, bravo)) # ... <boring unit root econometric code> } When I pass two stock symbols as function parameters, I need to enclose them with quotes: teetor("GLD", "GDX") I want to be able to simply type: teetor(GLD, GDX) There are several ways of doing this, but generally I wouldn't advise it. Typically calling something without quotes like that means that the

Adding Points, Legends and Text to plots using xts objects

杀马特。学长 韩版系。学妹 提交于 2019-12-03 14:10:37
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. If I use an xts object, i.e., if I use plot(xts-object-with-date-asset1-asset2, ...) instead of plot

How to create a technical indicator in quantmod package

僤鯓⒐⒋嵵緔 提交于 2019-12-03 07:44:20
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 previous two. The code I wrote in order to take the five values of a time series of closing prices of a stock

R - Loading External Indicators into Quantstrat

╄→гoц情女王★ 提交于 2019-12-03 07:14:13
I noticed that Quantstrat typically takes indicators that are based on price. However, I would like to load several indicators that have been externally calculated along with the price data. For instance, I have 2 extra columns in a csv file that contain my indicators (numbered 1-9). I want to generate a signal based on the numbers in these columns. Thus far, I have been unable to get Quantstrat to read the columns in the csv file. I've attached my code below: library(quantmod) library(quantstrat) library(PerformanceAnalytics) library(foreach) library(FinancialInstrument) getSymbols("SPY",