Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
HELP! How to Calculate Sharpe Ratio During Backtest?

Anyone have a clue how to calculate rolling Sharpe ratio during backtest?
I'd like to use rolling Sharpe ratio in my investment algorithm but I can't figure out how to compute or access the components I need, ie. portfolio return, standard deviation of portfolio returns and risk free rate over my chosen look back period.

2 responses

https://www.quantopian.com/posts/corrections-to-cumulative-risk-metrics

Maybe someone in the community would like to use some of this as a starting point to create an accurate Sharpe calculation?

If one assumes that the risk-free rate is 0 (as I believe Q does in their calculation of Sharpe), then would it be completely wrong to use the built in factors, like this to calculate Sharpe?

from quantopian.pipeline.factors import AnnualizedVolatility, Returns

simple_sharpe = Returns(window_length = 126) / AnnualizedVolatility(window_length = 126) 


Regarding risk-free rate = 0, would the overnight USD Libor rate (currently about 1.7% annualized I believe) be the correct one (for daily rebalancing algos), and also, should it be adjusted for inflation, in which case 0 probably wouldn't be too far off?

Hopefully someone more enlightened can answer these questions.