Skip to content

tq_performance cannot pass vector for Rf, PerformanceAnalytics does #46

Open
@apsteinmetz

Description

@apsteinmetz

In the performance analytics package, "Rf" is a variable that can be passed as a single value which tq_performance accepts, or a vector, which tq_performance does not.

set.seed(12345)
RaRf<-tibble(date=as.Date(as.yearmon("2009-01-01")+seq(1/12,3,1/12),frac=1),
       Ra=rnorm(3*12,.06/12,.01),
       Rf=rnorm(3*12,.02/12,.001))


RaRf_xts<-as_xts(RaRf,date_col = date)

#in tidyquant -------------------------
# vector for Rf NOT accepted
RaRf %>%
  tq_performance(Ra = Ra, Rf = Rf, performance_fun = SharpeRatio)

#Error in tq_performance_.tbl_df(data = data, Ra = lazyeval::expr_text(Ra),  : 
#object 'ret' not found
#In addition: Warning message:
#  In fun_performance(eval(parse(text = Ra)), ...) : object 'Rf' not found

#in PerformanceAnalytics -------------------------
# vector for Rf accepted
SharpeRatio(RaRf_xts$Ra,RaRF_xts$Rf)
                                       Ra
#StdDev Sharpe (Rf=0.2%, p=95%): 0.5956861
#VaR Sharpe (Rf=0.2%, p=95%):    0.6704678
#ES Sharpe (Rf=0.2%, p=95%):     0.4820222

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions