使用 version.string R 版本 2.11.0 (2010-04-22) quantmod "0.3-17"
Windows XP
使用该chartSeries功能时,图表上显示的线条颜色为绿色quantmod。type="line"我想将颜色从绿色更改为另一种颜色。
看起来我可以更改chartTheme,但主题没有显式地具有变量来更改线条的绘图显示颜色。
我可以在使用该功能时更改线条显示颜色 plot()- 那么是否可以使用chartSeries()in将线条图的显示更改为不同的颜色quantmod?
我想绘制一条多色的线,颜色基于一个因子中的相应值.例如,每日股票收盘价的时间序列,其上涨超过一定数量的天数为蓝色,其中已经完成的天数为红色,其他日期为红色.无聊的黑色.
我的数据在一个xts对象中(其中包含因子as.numeric(myfactor)),我想使用quantmod chartSeries或chart_Series函数.但如果这是不可能的,那么使用的东西plot就足够了.
一些样本数据:
library(xts)
x = xts( data.frame( v=(rnorm(50)+10)*10, type=floor(runif(50)*4) ),
order.by=as.Date("2001-01-01")+1:50)
Run Code Online (Sandbox Code Playgroud)
我可以像这样绘制它:
library(quantmod)
chartSeries(x$v)
addTA(x$type, type='p')
Run Code Online (Sandbox Code Playgroud)
即如果使用彩色线段,我觉得将底部图表中的信息与顶部图表相匹配会更容易.
我正在绘制 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()
Run Code Online (Sandbox Code Playgroud)
如何在 ggplot 中绘制收盘价,以便每年在绘图上都有不同的背景颜色图块?
我想用 Quantmod 做一个项目并比较股票图表。由于这些图表通常具有不同的绝对值,我想通过除以第一个值来标准化。
加载数据中
getSymbols(Symbols = "^IXIC", verbose = FALSE, warnings = TRUE, src = "yahoo", symbol.lookup = TRUE, auto.assign = getOption('getSymbols.auto.assign',TRUE))
IXIC_test1 <- IXIC/2
Run Code Online (Sandbox Code Playgroud)
效果很好,因为我再次得到了时间序列
> head(IXIC_test1)
IXIC.Open IXIC.High IXIC.Low IXIC.Close IXIC.Volume IXIC.Adjusted
2007-01-03 1214.860 1227.310 1197.330 1211.580 1217640000 1211.580
2007-01-04 1211.910 1230.255 1206.875 1226.715 1052105000 1226.715
2007-01-05 1222.535 1222.535 1210.295 1217.125 1030180000 1217.125
2007-01-08 1217.625 1222.815 1210.565 1219.100 952810000 1219.100
2007-01-09 1221.630 1224.935 1211.780 1221.915 1072080000 1221.915
2007-01-10 1217.020 1230.670 1213.950 1229.665 1137105000 1229.665
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用
IXIC_Norm <- IXIC/first(IXIC) …Run Code Online (Sandbox Code Playgroud) 过去几个月我一直在使用该功能,但最近几天它停止工作:
library(quantmod)
getFX("USD/JPY")
Error in open.connection(con, "rb") : HTTP error 404.
Run Code Online (Sandbox Code Playgroud)
其他人还有相同的疑问么?R 中有其他方法可以下载 FX 数据吗?
更新: quantmod 创建者为这个问题提供了一个修复程序,只需复制安装它的代码:
install.packages("curl")
library(devtools)
devtools::install_github("joshuaulrich/quantmod", ref="225_getsymbols_oanda")
Run Code Online (Sandbox Code Playgroud) 我认为使用xts对象添加点,图例和文本可以得到这个问题的答案,但显然不是......
require(quantmod)
getSymbols("SAM")
big.red.dot <- zoo(85, as.Date("2011-05-05"))
plot(SAM['2011'])
points( big.red.dot, col="red", pch=19, cex=5 )
Run Code Online (Sandbox Code Playgroud)
这个似乎直接来自教科书.?plot.zoo尽管不包含任何示例point().
我有以下几个data数据点的时间序列(请参阅dput()下面的可重复系列的输出).
data
2012-03-13 0.0099809886
2012-03-14 -0.0011633318
2012-03-15 0.0021057557
2012-03-16 -0.0039516504
2012-03-19 -0.0006950880
2012-03-20 -0.0064935065
2012-03-21 -0.0016389604
2012-03-22 0.0089264740
2012-03-23 0.0061047194
2012-03-26 -0.0032664489
2012-03-27 0.0016199954
2012-03-28 0.0123198512
2012-03-29 -0.0018399264
2012-03-30 0.0013828071
2012-04-02 -0.0134335155
2012-04-03 -0.0038999771
2012-04-04 0.0057816836
2012-04-05 0.0041695622
2012-04-10 0.0039627040
2012-04-11 -0.0007045561
2012-04-12 0.0063261481
2012-04-13 0.0030106531
2012-04-16 0.0004650081
2012-04-17 -0.0057924004
2012-04-18 0.0055337791
2012-04-19 0.0009157509
2012-04-20 -0.0004576659
2012-04-23 -0.0038857143
2012-04-24 0.0029960820
2012-04-26 -0.0074779062
Run Code Online (Sandbox Code Playgroud)
我想尝试获得n期滚动分位数的时间序列.
例如,要获得整个系列的上四分位,只需:
> quantile(se,.75)
75%
0.004117848
Run Code Online (Sandbox Code Playgroud)
但我想要的是有效地添加,data$rolling_quantile以便我可以有一个滚动的n期窗口,它构成了什么
我本以为apply.rolling(in Performance Analytics …
library(quantmod)
getSymbols("GDPC1",src = "FRED")
Run Code Online (Sandbox Code Playgroud)
我试图提取FRED中的数字经济/金融数据,但也提取元数据.我试图绘制CPI并将元数据作为标签/脚注.有没有办法使用quantmod包提取这些数据?
Title: Real Gross Domestic Product
Series ID: GDPC1
Source: U.S. Department of Commerce: Bureau of Economic Analysis
Release: Gross Domestic Product
Seasonal Adjustment: Seasonally Adjusted Annual Rate
Frequency: Quarterly
Units: Billions of Chained 2009 Dollars
Date Range: 1947-01-01 to 2014-01-01
Last Updated: 2014-06-25 7:51 AM CDT
Notes: BEA Account Code: A191RX1
Real gross domestic product is the inflation adjusted value of the
goods and services produced by labor and property located in the
United States. …Run Code Online (Sandbox Code Playgroud) 我想,以输出转换从getSymbols在quantmod包到一个数据帧.目前,我使用以下代码实现了这一点.
Data <- new.env()
getSymbols(Symbols = "EUR/USD", src = "oanda", from = "2005-01-01",
to = "2006-01-01", env = Data)
test <- as.data.frame(Data$EURUSD)
head(test)
Run Code Online (Sandbox Code Playgroud)
理想情况下,我想将这些代码简化为以下内容:
test <- as.data.frame(getSymbols(Symbols = "EUR/USD",
src = "oanda", from = "2005-01-01", to = "2006-01-01"))
Run Code Online (Sandbox Code Playgroud)
但这并不适用:
> head(test)
getSymbols(Symbols = "EUR/USD", src = "oanda", from = "2005-01-01", to = "2006-01-01")
1 EURUSD
Run Code Online (Sandbox Code Playgroud)
理想情况下,我希望EUR/USD在处理数据时避免引用该对,因为将来我将努力使这个组件动态,因此必须输入test <- as.data.frame(Data$EURUSD)破坏乐趣.我理想的代码就是这样的:
test <- as.data.frame(getSymbols(Symbols = *user input*,
src = "oanda", from = "2005-01-01", to = …Run Code Online (Sandbox Code Playgroud) 在尝试安装quantmod包时,我从xts包中得到以下错误:
> install.packages("quantmod", repos="http://R-Forge.R-project.org", type="source")
also installing the dependencies ‘xts’, ‘TTR’
?????? URL 'http://R-Forge.R-project.org/src/contrib/xts_0.9.874.tar.gz'
Content type 'application/x-gzip' length 538182 bytes (525 KB)
==================================================
downloaded 525 KB
?????? URL 'http://R-Forge.R-project.org/src/contrib/TTR_0.22-0.1.tar.gz'
Content type 'application/x-gzip' length 276426 bytes (269 KB)
==================================================
downloaded 269 KB
?????? URL 'http://R-Forge.R-project.org/src/contrib/quantmod_0.4-3.tar.gz'
Content type 'application/x-gzip' length 123464 bytes (120 KB)
==================================================
downloaded 120 KB
* installing *source* package ‘xts’ ...
** libs
clang -I/usr/local/Cellar/r/3.2.1/R.framework/Resources/include -DNDEBUG -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I"/usr/local/Cellar/r/3.2.1/R.framework/Versions/3.2/Resources/library/zoo/include" -fPIC -g -O2 -c add_class.c -o add_class.o
clang -I/usr/local/Cellar/r/3.2.1/R.framework/Resources/include -DNDEBUG …Run Code Online (Sandbox Code Playgroud)