0

我一直在尝试使用 PerformanceAnalytics 包中的 SharpeRatio 函数。我正在尝试将夏普比率应用于动物园对象,但认为结果不好。谁能说我为什么不能像 rollapply(dreturns.z,FUN="SharpeRatio",by.column=T,width=20,align="right") 那样应用它?另一个问题,这个函数 SharpeRatio 作为一个参数 FUN。我如何用 rollapply 定义它,因为 rollapply 还定义了参数 FUN ?

    dprices.z = get.hist.quote(instrument="VTI", quote="AdjClose",start="2013-07-01",
                                               provider="yahoo", origin="1970-01-01",
                                               compression="d",retclass="zoo")

    dreturns.z =dprices.z / lag(dprices.z,k=-1) -1
    rownames(dreturns.z)=as.character(index(dreturns.z))

    tail(rollapply(dreturns.z,FUN=mean,width=20,align="right") / sqrt(rollapply(dreturns.z,FUN=var,width=20,align="right")))
            AdjClose
2013-09-26 0.4093935
2013-09-27 0.3366035
2013-09-30 0.3531433
2013-10-01 0.3745384
2013-10-02 0.2891515
2013-10-03 0.1851469  
    StdDevSharpeRatio = function(x) {SharpeRatio(x,FUN="StdDev")}
    VaRSharpeRatio = function(x) {SharpeRatio(x,FUN="VaR")}
    ESSharpeRatio= function(x) {SharpeRatio(x,FUN="ES")}

    tail(rollapply(dreturns.z,FUN="StdDevSharpeRatio",width=20,align="right"))
            AdjClose
2013-09-26 0.4093935
2013-09-27 0.3366035
2013-09-30 0.3531433
2013-10-01 0.3745384
2013-10-02 0.2891515
2013-10-03 0.1851469
    tail(rollapply(dreturns.z,FUN="VaRSharpeRatio",width=20,align="right"))
            AdjClose
2013-09-26 0.3473634
2013-09-27 0.2746835
2013-09-30 0.2947952
2013-10-01 0.3147704
2013-10-02 0.2383431
2013-10-03 0.1373277
    tail(rollapply(dreturns.z,FUN="ESSharpeRatio",width=20,align="right"))
            AdjClose
2013-09-26 0.4093935
2013-09-27 0.3366035
2013-09-30 0.3531433
2013-10-01 0.3745384
2013-10-02 0.2891515
2013-10-03 0.1851469
    tail(rollapply(dreturns.z,FUN="SharpeRatio",by.column=T,width=20,align="right"))
              AdjClose
2013-09-26 -0.07070451
2013-09-27 -0.25525289
2013-09-30 -0.14237154
2013-10-01 -0.10778731
2013-10-02 -0.16874505
2013-10-03 -0.09659218
4

1 回答 1

0

由于我不是 Sharp Ratios 专家,您期望得到什么结果?无论如何,不​​要忘记您假设无风险利率为 0(因为默认SharpeRatio(R, Rf = 0, p = 0.95)值为 0),这可能会使您的结果产生偏差。

关于你问题的后半部分,我会做这样的事情:

rollapply(dreturns.z, FUN = function(x) SharpeRatio(x, FUN = "StdDev"),
           by.column=T, width=20, align="right")

希望这可以帮助....

于 2013-10-06T13:39:54.193 回答