如何解决如何在R中表示高于或低于SMA的收盘价?
很高兴找到这个社区!
作为一个开始的项目,我希望检查一下当价格高于SMA时开仓并在价格低于SMA时平仓的情况。
我目前正在R中编写脚本,如下所示:
`##############################
# 0 - Load libraries
##############################
require(quantmod)
require(PerformanceAnalytics)
require(TTR)
# Step 1: Get the data
loadSymbols("^GSPC")
# Step 2: Create your indicator
SMA <- SMA(x = (GSPC),n = 200)
# Step 3: Construct your trading rule
signal <- Lag(ifelse(SMA$SMA > CLV(GSPC),1,-1))
# Step 4: The trading rules/equity curve
ret <- ROC(Cl(GSPC))*signal
ret <- ret[2009-06-02/2020-09-07]
eq <- exp(cumsum(ret))
plot(eq)
# Step 5: Evaluate strategy performance
table.Drawdowns(ret,top=10)
table.DownsideRisk(ret)
charts.PerformanceSummary(ret)
plot(cl(GSPC))
lines(sma,col = "Blue")`
运行脚本时,脚本不产生任何输出。我已经重新安装了所有软件包,并且正在运行R版本3.6。
请有人告诉我为什么?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。