0
votes

I have been trying to work with the SharpeRatio function in the PerformanceAnalytics package. I am trying to rollapply the Sharpe Ratio over a zoo object but a think the results are not ok. Can anyone say why I cannot apply this like rollapply(dreturns.z,FUN="SharpeRatio",by.column=T,width=20,align="right")? One other question, this function SharpeRatio as one parameter FUN. How can I define it with rollapply since rollapply also defines the parameter 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
1

1 Answers

0
votes

Since I´m not an expert with Sharp Ratios, what results do you expect? Never the less, don´t forget that you assume a risk free rate of 0 (since the default for SharpeRatio(R, Rf = 0, p = 0.95) is zero), this might bias your results .

Regarding the second half of your question I would do something like this:

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

Hope this helps....