Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Trouble with Shorting the SPY

I'm trying to short the S&P when my buy signal is off. Instead the numbers become impossible volatile (Sharpe ratios of 12000, drawdowns of 4 million percent). What is going on? ```

6 responses

Maybe this can help you figure out what's up with it.

It seems you are extremely leveraged. You may want to revise how the order() method works here: https://www.quantopian.com/help#api-order-methods. The context.portfolio.portfolio_value variable stores a value in dollars but it appears as though you are using this value to determine how many shares you would like to buy. You might be more interested in using the order_target() function or the order_target_percent() function to help control your orders better. The metrics that you are seeing are calculated relative to your starting capital so your crazy returns are a result of the fact that you are spending money that you don't have!

Does this help?

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.

No matter how I structure the order, the program uses leverage.
Would the placement of my order affect this?

If, for example, you used order_target_percent(sid(8554), 1.0), you would only order up to 100% of your portfolio value in sid(8554). That means that if you already had 100% of your portfolio invested in that stock when this line is executed, you wouldn't order any more. This would guard against any leverage.

I understand that. Even if the program uses an order_target_percent(x, -.02) the leverage still manages to become exponential.

Can you share your updated code with order_target_percent? The issue might be that you still have open orders when you try to place a new trade. Try using get_open_orders() to help check for this.