Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Order Target Percent

Has anyone else noticed or have any issues with using order_target_percent and 0 as the percentage?

        order_target_percent(stock,0,limit_price=None,stop_price=None)

On occasion I see this behavior when running the backtester and I don't understand why.

2010-01-05 07:32:00 TNA BUY 863 $22.94 $19,794.63
2010-01-12 11:22:00 TNA SELL -862 $22.32 ($19,242.43)
2010-01-12 11:23:00 TNA SELL -1 $12.38 ($12.38)
2010-01-15 13:47:00 TNA BUY 845 $22.83 $19,293.88
2010-01-20 08:07:00 TNA SELL -845 $22.69 ($19,174.74)

So on the first call of order_target_percent(stock,0) it sells all but 1 of the shares I own. Then on the next run through it will sell the remaining 1 share.

My expectation is that order_target_percent(stock,0) would be the same as order(stock,-context.portfolio[stock].amount).

Is this just me or has anyone else seen this behavior?

3 responses

One possibility is that the order you're making is too large to be filled in that minute. Our default slippage model will only let you trade 25% of the volume on any given bar (minute or day bar, depending). So if you try to make a big order, more than 25% of the volume, it gets spread out across multiple bars.

Another possibility is that there is a bug!

If you share the algorithm that causes that problem, we can take a look. Or you can email our help team at [email protected] if you're not comfortable sharing the algo.

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.

Hello Brian,

If you want to see if this sort of issue is caused by the default volume slippage model you can specify a fixed slippage model and see if the issue perists::

set_slippage(slippage.FixedSlippage(spread=0.0))  

P.

Thanks for the help. I submitted this to Jess S. by email.

The slippage change had no impact on the results. I also tried order(stock,-context.portfolio[stock].amount,limit_price=None,stop_price=None). Using the order method (instead of order_target_percent) corrects the issue.