Backtest with benchmark

My question is : how can I backtest my stretagey comparing to a benchmark in Python? And most importantly, how can I get access to the information ratio from backtesting in Python?


Using R notebook, I can do

“backtest(port, bench=‘ES’)”

to get the full analysis comparing to a benchmark. Most importantly, I can get the information ratio, which corresponds to 50% of the points!


However, the backtest function in Python does not support the input of “bench”. We can do

“port.backtest()”,

but cannot do

“port.backtest(bench=‘ES’)”.

I have checked the source code of function “portfolio” in Qlib, and I found the backtest() function , but unfortunately, I coundn’t found anything about backtesting with a benchmark. Also the backtest function does not return the P&L data to the users, which makes the calculation of information ratio impossible.


I am hoping to find a way to either get the information ratio w.r.t a benchmark directly from a backtest or get the P&L data from a backtest, so that I can compute the information ratio myself.


Thanks,



Hi,

We’ll be adding the benchmark option soon to the Python version.

In the meantime, use the “portfolioReturns” attribute. If you portfolio is called “port” then port.portfolioReturns gives you the time series of daily portfolio returns.

Please not that ES is not the benchmark for this competition. Use getHistoryData(‘SPW Index’) to get the benchmark. You can compute benchmark daily returns from this.

with the 2 above features, computing the information ratio should be straightforward.

Hi Herve,


Thank you for the response. That clears everything!


Cheers,