Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Backtesting sells too much?

Hey all!

I apologize if this seems like a silly question, but I was testing the sample algorithm with a few different stocks for fun, when I noticed that the Transaction Details section would say something like:

BUY 100
SELL -100
SELL -100
SELL -100

These orders would be the first to pop up. It's a little concerning, because one can't sell shares that one does not have. :P

Am I missing something here? Also, I put in a capital of $200, but the algorithm is trading 100s of shares which are totalling much more than the $200 capital I specified.

Again, I'm sorry if this is a silly question or I'm just missing something, but thanks ahead of time for the help. :)

edit: Upon further investigation, I realize the sample algorithm just buys and sells stocks all willy nilly. Thanks anyway!

3 responses

I guess we might need more realistic short selling and perhaps to specify trades as a percentage (weight) of overall portfolio value and / or available tradable value (cash + margin) and / or total exposure (long + abs short)

Hi Daniel - right now Quantopian doesn't institute any limits, so it will let you sell stock you don't own (= shorting a stock), as well as borrow cash to buy stock. It's up to you to set appropriate limits in your algorithm.

We've thought about building a risk management layer that sits on top of the algorithm that will refuse orders if certain limits are hit. It's on our list of features we'd like to build, but right now we're focused on building live trading integration.

thanks,
Jean

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.

Take a look at the sample algorithm's max_notional and min_notional. Use those to control the algo behavior.

If you're using really small capital amounts like $200, you'll need to write better control code, though. The control code there assume that you are trading with a lot of money and if you miss by a few thousand dollars it's no big deal.

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.