2013-10-04 63 views
0

我一直在嘗試使用PerformanceAnalytics包中的SharpeRatio函數。我試圖在動物園對象上翻轉夏普比率,但認爲結果不好。 任何人都可以說爲什麼我不能像rollapply這樣應用(dreturns.z,FUN =「SharpeRatio」,by.column = T,width = 20,align =「right」)? 另一個問題,這個函數SharpeRatio作爲一個參數FUN。我怎樣才能用rollapply定義它,因爲rollapply還定義了參數FUN?R - PerformanceAnalytics - SharpRatio rollapply zoo

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 

回答

0

因爲我不是夏普比率的專家,你期望什麼結果?永遠不要忘記,您假設無風險利率爲0(因爲SharpeRatio(R, Rf = 0, p = 0.95)的默認值爲零),這可能會影響您的結果。

關於你的問題的後半部分,我會做這樣的事情:

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

希望這有助於....