我收到'找不到故障功能'错误。我已经加载了PerformanceAnalytics库。
代码:
install.packages("quantmod")
install.packages("PerformanceAnalytics")
require(quantmod)
require(PerformanceAnalytics)
getSymbols("AAPL")
AAPL.DF<-data.frame(Date=index(AAPL), coredata(AAPL[,1]))
AAPL.DF[,2]<-ROC(AAPL.DF[,2])
colnames(AAPL.DF)<-c("Date","rtn")
dailyRtn <- as.numeric(substring(AAPL.DF[,"rtn"],1,nchar(as.character(AAPL.DF[,"rtn"]))-1))
dailyDD <- as.vector(Drawdowns(dailyRtn/100))
下面的是控制台窗口中的o / p
> getSymbols("AAPL")
[1] "AAPL"
Warning message:
In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, :
downloaded length 109721 != reported length 200
> AAPL.DF<-data.frame(Date=index(AAPL), coredata(AAPL[,1]))
> AAPL.DF[,2]<-ROC(AAPL.DF[,2])
> colnames(AAPL.DF)<-c("Date","rtn")
> dailyRtn <- as.numeric(substring(AAPL.DF[,"rtn"],1,nchar(as.character(AAPL.DF[,"rtn"]))-1))
> dailyDD <- as.vector(Drawdowns(dailyRtn/100))
Error in as.vector(Drawdowns(dailyRtn/100)) :
could not find function "Drawdowns"
当我成功安装和加载PerformanceAnalytics库
时,我无法获得为什么我收到错误消息“Drawdown”功能无法找到答案 0 :(得分:0)
没有Drawdown功能。根据您正在做的事情,您可能有兴趣使用findDrawdowns或chart.Drawdown。您还可以简化代码以计算回报,如下所示:
require(quantmod)
require(PerformanceAnalytics)
getSymbols("AAPL")
# calculate returns based on Adjusted Close prices
AAPL.DF <- Return.calculate(AAPL[,6])[-1,]
dailyDD <- findDrawdowns(AAPL.DF)
chart.Drawdown(AAPL.DF)
我在原始代码中使用了Adjusted_Close价格(AAPL第6列)而非开放价格(AAPL第1列),因为2014年AAPL拆分的Addjusted_Close价格已经更正,而未调整未平仓价格