我在 r 中使用以下代码读取股票价格的 CSV 文件。
library(quantmod)
#column headings ("open","high","low","close","volume","adj.")
fmt <- '%Y-%m-%d'
SPY <- read.zoo("~/Stocks/csv/SPY.csv",header=TRUE,sep=',',tz='',format=fmt,index=0:1)
plot(SPY['open'])
Run Code Online (Sandbox Code Playgroud)
我可以成功地用于plot(SPY)绘制所有列。
我将如何按名称仅选择一列,例如仅绘制“打开”列?我已经尝试了很多事情,例如plot(SPY['open'])但无法弄清楚。
有人可以帮忙吗?非常感谢!
I\xe2\x80\x99m 尝试使用quantmodR 中的包从雅虎获取财务数据。它在我的个人笔记本电脑(Mac 和 Win)上完美运行。但我无法让它在我的工作计算机(Win7)上运行。
我的代码是:
\ngetSymbols("JPM", src = "yahoo")\nRun Code Online (Sandbox Code Playgroud)\n请注意,它仅不适用于我公司的笔记本电脑。
\n这是错误代码:
\nError in curl::curl_download(cu, tmp, handle = h) : \nSSL certificate problem: unable to get local issuer certificate\nRun Code Online (Sandbox Code Playgroud)\n我尝试通过以下方式解决问题:
\n安装httr包
删除curl并quantmod重新安装
更新到最新版本的 R、RStudio curl、、、httr和RCurlquantmod
安装openssl包
放ssl_verifypeer = 0L
之前添加以下内容getSymbols
options(download.file.method = "wget", download.file.extra …
我正在研究基本 RSI 交易信号。当股票低于 20 RSI 时买入 100 股,当股票高于 80 RSI 时平仓。
发生的情况是,一旦股票跌破 20,我就买入 100 股,如果股票再次跌破 20,而 RSI 没有首先达到 80,我最终会再买入 100 股(总共 200 股)。
一旦我有了一个仓位,我就不想再增加了。谢谢。
rm.strat(portfolio.st)
rm.strat(strategy.st)
rm.strat(account.st)
#setup
Sys.setenv(TZ = "UTC")
stock.str = "AAPL"
currency('USD')
stock("AAPL", currency= "USD", multiplier = 1)
initDate = "2010-01-01"
startDate = "2011-01-01"
to = Sys.Date()
initEq = 100000
portfolio.st = account.st = strategy.st = 'rsi'
getSymbols("AAPL", from = initDate)
initPortf(portfolio.st, symbols = stock.str,
initDate = initDate)
initAcct(account.st,
portfolio.st,
initDate = initDate, initEq = initEq)
initOrders(portfolio.st, …Run Code Online (Sandbox Code Playgroud) 我遇到了使用R/quantmod包的一个问题.我可以获得韩国的股票信息,但我没有获得日本的信息:
getSymbols("DEXKOUS",src="FRED") #load Korea
[1] "DEXKOUS"
getSymbols("DEXJPUS",src="FRED") #load Japan
Error as.POSIXlt.character(x, tz, ...) :
character string is not in a standard unambiguous format
Run Code Online (Sandbox Code Playgroud)
欢迎您的意见.
sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=Chinese (Simplified)_People's Republic of China.936
[2] LC_CTYPE=Chinese (Simplified)_People's Republic of China.936
[3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_People's Republic of China.936
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] PerformanceAnalytics_1.0.3.2 quantmod_0.3-17 TTR_0.21-0
[4] xts_0.8-2 zoo_1.7-4 …Run Code Online (Sandbox Code Playgroud) 假设我想要在R Rross Profit on Total Revenue中回归.我需要这方面的数据,越多越好.我发现CRAN上有一个非常有用的库:quantmod,它可以满足我的需要.
library(quantmod)
getFinancials(Symbol="AMD", src="google")
#to get the names of the matrix: rownames(AMD.f$IS$A)
Total.Revenue<-AMD.f$IS$A["Revenue",]
Gross.Profit<-AMD.f$IS$A["Gross Profit",]
#finally:
reg1<-lm(Gross.Profit~Total.Revenue)
Run Code Online (Sandbox Code Playgroud)
我所遇到的最大问题是这个库只能获取4年的数据(4次观察,并且只有4次观察才能进行回归).有没有其他方式(可能是其他库)可以获得超过4年的数据?