Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Selling more than I buy? With set_only_long()

Hello, Thank all of you Quantopians for your contributions.

Building from the template here: https://www.quantopian.com/posts/robinhood-live-trading-update-stop-waiting-3-days-with-robinhood-instant

I looked into my transaction details after being concerned that something wasn't quite right. This is a backtest, not live.
In one day, it will say that i've bought 5 for previously in the day, and then it will sell -5 over and over again about 50 times over, at the exact same time, for the exact same price.

It appears to be selling 50X more than what i've bought. Does anyone have some insights into what is going on here?

These are very long logs, or I may have just tried to add up all the numbers. As a side note - is there any way to download transaction details or daily positions and gains in a .csv file?

Any info is appreciated.

Thank you,
Chris

5 responses

Sometimes I also get this error message:

TradingControlViolation
There was a runtime error on line 331.
Order for -129 shares of Equity(30658 [NOK]) at 2016-04-29 14:00:00+00:00 violates trading constraint LongOnly().

Hello Christopher,
You may want to try some of this code, this may help your multiple order problem:
for security in context.longs.index:
if get_open_orders(security):
continue
if data.can_trade(security):
order_target_percent(security, weight)

That is in my code, thanks.

Chris, it's impossible to provide good troubleshooting without the code. If you share the backtest we'll be able to see what's going on. The obvious but useless answer is "something in your business logic is causing the sell order to placed repeatedly" but the why isn't discernible without more information.

The best way to evaluate your transactions is to load the data into the research environment. You can use the get_backtest() command and load your data that way. Unfortunately, downloading isn't available because it would make it too easy for people to download the data. Our vendor agreements don't permit downloadable data.

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.

I have seen this if I accidentally order by percentage =0 twice in the same function...I think you need to wait for one "tick" to occur before the get open orders will report it correctly as open.