I would like to use TidyQuant to produce several performance statistics from a dataframe of symbol returns. I have worked out that I can do the following to get the max and average drawdowns for each symbol:
maxDD <- monthlyReturns %>%
group_by(symbol) %>%
tq_performance(
Ra = Ra,
Rb = NULL,
performance_fun = maxDrawdown
)
avgDD <- monthlyReturns %>%
group_by(symbol) %>%
tq_performance(
Ra = Ra,
Rb = NULL,
performance_fun = AverageDrawdown
)
It strikes me that calling these 2 functions separately is very inefficient. Surely the function has to generate all drawdowns separately for each call before being able to calculate the max and the average.
Is there a way to make this more efficient by calling tq_performance once and giving it a list of similar sub functions so the required underlying data (drawdowns) only has to be computed once?