Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
New method: Use set_benchmark to customize the benchmark in your backtest!

We are excited to roll out an oft-requested API enhancement, the new set_benchmark() method!

You can now select any security in our universe to serve as the benchmark in your algo's backtests. If you do not call set_benchmark in the initialize() method you will default back to the SPY as the benchmark.

In the example attached I have a moving average crossover strategy using everyone's favorite stock (AAPL), but in this case I have also set AAPL as my benchmark -- allowing for a much fairer comparison of the strategy's added value over a simple buy-and-hold strategy with the same stock.

As with any new API method we'd love to hear your feedback and any questions you might come across.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

9 responses

Is it possible to turn off the benchmark or set it to zero? Equity market neutral strategies don't really need one.

Hi Karolis,

In the backtest, it's not possible to remove the benchmark. There will always be a benchmark present, either SPY or a custom one. It is meant to compare your strategy returns to the general market or to a single stock/ETF buy-and-hold performance.

I can see how it would be useful in your case to focus on the absolute returns. Perhaps you could click on the benchmark to remove it from the chart, similar to the behavior of the custom data plot variables. We'll take a look!

Cheers,
Alisa

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

On a backtest cumulative performance graph, if you click on the 'Benchmark' label, it will disappear from the graph and you can focus on the algorithm returns. This is also true for any variable on the custom data graph.

that works, tyvm!

Excellent feature. Thanks Jessica

Take a look at the SPDR Barclays 1-3 Month T-Bill ETF, it started trading under the ticker BIL on June 25, 2007. We have it in our database as sid(33948).

And here's a link for more information: https://www.spdrs.com/product/fund.seam?ticker=BIL

How do you identify the sid number for a specific security?

@matthew p

An easy way to get the SID for a security is to open a notebook and use the 'symbols' method. Run the code and it will return the SID (and a lot of other info). In the case below, the SID for IBM is 3766.

symbols('IBM')

Equity(3766, symbol=u'IBM', asset_name=u'INTL BUSINESS MACHINES CORP', exchange=u'NYSE', start_date=Timestamp('2002-01-01 00:00:00+0000', tz='UTC'), end_date=Timestamp('2017-05-02 00:00:00+0000', tz='UTC'), first_traded=None, auto_close_date=Timestamp('2017-05-05 00:00:00+0000', tz='UTC'), exchange_full=u'NEW YORK STOCK EXCHANGE')  

However, when using the 'set_benchmark' method it's expecting an equity object so either of the following will work (no need to know the SID if you know the ticker).

set_benchmark(symbol('IBM'))  
set_benchmark(sid(3766))

Can we have a feature such as set_benchmark('') for totally turning it off ? I have 2 reasons for this.

  1. This will make algorithm run faster (i guess)

  2. I actually use candlestick to test a logic for creating new position and liquadating existing position. So it is not a matter on how this logic is compared with SPY (or other equity). It is a matter on how often the logic is a suceess (which means a profit)) and how often the logic is a failure (which means a loss).