How to use a custom benchmark in a Zipline backtest

I’m somewhat new to zipline and would appreciate your help on this.

I’m trying to figure out how to use a custom benchmark in a zipline backtest. For example, suppose I want to create a composite benchmark that is a weighted average of the Vanguard sector ETFs according to their inverse volatilities. I tried doing something along the lines of running a backtest of a strategy that weights the ETFs according to their inverse volatilities, and then using the equity curve from the results file as a benchmark in a backtest for another strategy using set_benchmark(), but this would only work if the benchmark is in the data bundle I’m using.

This seems like it should be possible but I’m not sure how to go about it.

As you note, the benchmark must be in the bundle. But since the benchmark is not actually used in Zipline anyway but only in pyfolio, you could try to add the benchmark manually to the Zipline results CSV before passing it to pyfolio.

Thanks, this solves it.