Back to Community
Short selling in backtester, time for improvement?

Is it possible to increase the accuracy of the backtester for short positions given they are the essence of longshort strategies.

Things like

  • stocks banned from shorting
  • delayed execution until stocks are located for shorting
  • margin requirements that commonly go up to 5x in live trading
  • borrowing costs going up to 20-30% for some stocks

Feels like there is room for significant improvement on this front.

22 responses

Here is one more request about this from Igor Rivin.

Here is more info:

as stocks get to the end of QTradeableStocksUS() you will learn that they either can not be borrowed for shorting or a small number of shares would be.

Bigger problem are ETFs which are much harder to borrow.

  • More info on margin requirements

I've often experienced situations where in order to short stock you need to have 5x the value of shorted stock in your account.

And there is the borrowing cost which is typically 7%-10% but depending on the stock can go as high as 30%-50%.

These factos obviously significantly influence the accuracy of backtesting and almost always in the unwanted direction.


as stocks get to the end of QTradeableStocksUS()

Just curious...what is meant by the "end"?

Hi vladimir and Vladimir,

We definitely agree that our simulation can be improved with respect to shorting equities. We're understand how this can negatively impact your workflow. This is in our backlog. Unfortunately, this work is behind other projects in terms of overall prioritization.

Thank you for the input as even in these cases where we can't take action in the short term, it is always very helpful to hear which product shortcomings are impacting the community's workflow.

All the best,


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.

@grant lower trading volume "end" of the set

@payne I'll take any answer as better than none at this moment

This issue would seem to be germane to writing real-world-viable algos for the Q hedge fund, right? How does Q address it today in evaluating algos for the fund? It seems that it could be quite risky to put capital against algos that are tilted toward lower dollar-volume stocks without being able to model performance accurately. However, without a means to do accurate modeling, profitable algos could be bypassed (if the Q fund tilt is toward high dollar-volume stocks, to avoid the risk of inaccurate modeling). It would seem that this wouldn't be a low-priority issue. What am I missing?

I guess one painful way would be to paper-trade with the new Q hedge fund broker, assuming they accurately model low dollar-volume stocks, but this would incur a time delay (~ 6 months?) and potentially expense, if the broker charges for this service.

Conversely, it might be a way to "game" the contest with unrealistic algos...

Figured out that the currently best way to simulate borrowing cost for shorted stock is through slippage.

If you trade daily:

set_slippage(slippage.FixedBasisPointsSlippage(basis_points=8, volume_limit=0.1))

This would have an effect of reducing your CAGR by about 10% which is the average stock borrowing cost. Default slippage model is 5 basis points.

The biggest problem remains the liquidity. In many cases the short orders would not fill, even when using QTradableStocksUS universe.

Hi Josh -

In the end, I'm not sure this is the right perspective:

We're understand how this can negatively impact your workflow.

Y'all are the ones needing to make a buck on your Q fund. So, it is not a nuisance "workflow" issue, but rather something that could impact your profitability. It sounds like it is sorta "in the noise" at this point for you. Is this a correct assessment? If so, it would be interesting to understand how you make that conclusion. Maybe there is some sort of rule-of-thumb or back-of-the-envelope estimate that would allow you to say for algos that conform to the contest and Q fund criteria, the risk of out-of-sample real-money trading not matching a backtest is negligible.

This is a huge issue. The real life shorting is vastly different to what the back-tester shows. The biggest problem remains simply inability to borrow stock to short when needed by the algo, at capacity needed. Most of the borrowing is capped at $500k-1m while for many stocks your short will simply not work as there is no stock to borrow (tested extensively in live trading using IB). In my tests this could affect 50%-80% of CAGR on the short side.

I suspect that contest algos run vastly inferior to their backtests in live trading unless Q has a way to always borrow stock somehow.

Thanks Vladimir -

One thing to keep in mind is that the goal, as I understand, is to combine a relatively large number (30 or more) of diverse algos and trade them in the 1337 Street Fund. So, even if a given algo needs a large short position in stock XYZ, if the 1337 Street Fund portfolio is truly diverse, it should be partially offset by long XYZ positions in other algos on any given day.

If I'm thinking about this correctly, a relevant and accurate model would need to include the fact that the algo would be combined with other algos in the 1337 Street Fund. It might not make sense to impose a model for shorting that ignores the end application of the algo; it will be combined with a large number of diverse algos, and it is the net result that really matters. So, for Q to write a model, it would need to have some assumptions in it about the diversification of the 1337 Street Fund, right?

In the context of the new arrangement with FactSet (see, a model to be applied at the individual algo level would seem to be more important. I would think that the Quantopian Enterprise institutional users would need a better model for shorting.

I am not seeing that model applicable Grant. If you think the algos in the model would cancel each other out in such fashion then surely alpha would be diminished. I think a more realistic scenario is large demand to short a combined basket of stocks like 50 of them at a time. Lets also assume Q's ultimate goal is to run a $500m fund and that algos trade once a daily on average.

That means that about 50 stocks would need about $5m worth of borrowing each day. In my experience this is not possible through IB as a broker which has considerable liquidity. With Q500 universe it might be possible (and that would be a stretch too) but simply not plausible with the extended QTUS universe. What I've seen in practice is an average ability to short about $1m worth of stock across this universe, and this average includes a lot of cases where for some stock there would be no ability to borrow at all.

Thanks Vladimir -

Sounds like this may be a gross inaccuracy in the Quantopian backtester, if I'm understanding your drift. Perhaps it is hard to model, and thus has not been implemented for the simulation? Anyway, I gather there won't be any engagement on the part of Q on this topic, given Josh's statement "This is in our backlog. Unfortunately, this work is behind other projects in terms of overall prioritization." Presumably, they feel that algos using the QTUS and conforming to the contest rules will require minimal patching up, prior to going live with real money. But I think you are saying that they'll need further assessment, to understand the impact of shorting, and potentially changes will be required by authors. This would kinda suck--wait six months for out-of-sample data, only to find out that the simulation was off.

Yep I would be interested in what Quantopian has to say about this

  • Do they experience trouble borrowing stock with live algos?
  • If not why not (different broker, agreement, lower capacity, algo structure...)

Stumbled upon a discovery today that could help turn the tide on this one.

IB basically maintains a FTP file (API anyone? :) with all stock information, current borrowing fees and how many shares available for borrow. A historical record would help solve the shorting problem.

And with a little code this could be made a datapoint in pipeline using this

Will poke a bit more, hopefully getting answers to some questions.

If you analyze that file, the number of stocks with full short liquidity (as indicated by >10M shares available to borrow to sell short) is 551. It feels that this information should in some way influence QTUS universe.

Last time I checked there were about 1800 stocks in QTUS. That means that for 2/3 of the universe you are unlikely to have short liquidity needed by the capacity of the fund.

So either
- Capacity of the fund is much smaller
- Fund is not using IB as brokerage

Hi vladimir, Quantopian does not use IB as a its prime broker.

Thanks Josh. Do you find any of the discussion relevant? Do you mind telling what broker do you use?

Maybe the answer should be:

We have absolutely no shorting availability problem of any kind for all the stocks in the QTU universe. We can always borrow enough at nominal fees, just like our commissions which are in the order of $0.001 per share. So, shorting fees are not a major consideration to say the least. And we just disposed of the problem of availability.

But then, I might be wrong.

I don't believe I can publicly disclose our prime broker.

In practice, we can't borrow everything nor can we borrow everything we might want at reasonable fees. That said, in the realm of "biggest problems we face simulating reality as part of the allocation process", this isn't at the top of the list as negatively impacting us. As such isn't currently a focus.

Hi Josh,

I'm wondering if you'd be willing to share what's up at the top of priorities for improving simulation? Is there anything we should be mindful of when designing strategies? My guess is that it might have something to do with the default slippage model, perhaps being too costly for liquid stocks, and too generous for illiquid stocks? That or perhaps possible look-ahead bias maybe in the 'price' bar? (I'm just speculating, not accusing).

While I'm in the game of speculating, my guess is that your PB is MS, based primarily on that you seem to be designing your global markets roll out around their MSCI ACWI.



Would be interested in details on:

"biggest problems we face simulating reality as part of the allocation process", this isn't at the top of the list as negatively impacting us

What is the list? How does each problem contribute? What is the plan to address the major contributors to simulation inaccuracy?