Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Good idea, but doesn't seem to work

The backtester lets me buy more shares than I have cash, sell more shares than I have.

It doesn't seem to be able to track when an order is filled, i.e., I set target 100 shares and the order stays open for multiple days in the backtested with amount = 100 status = open.

Not really working enough to use.

3 responses

This will show you unfilled etc: https://www.quantopian.com/posts/track-orders

I was trying a few methods to manually track the orders, but my issue is that the ordering system doesn't seem tied into the account.

So, if I say

if <some condition>:  
    order_target(sid, 100)

in handle_data, it will merrily purchase blocks of 100 into eternity, not watching my account balance

further, if I have code that says

if <some condition> and <money in account>

it will still blow through it since the orders never close and (thus?) never decrease my account value

In any case, I just running a modified version of the "Sample Algorithm For a Basic Strategy" that came with the system, but running it against minute data instead of dailies.

The cash management is up to you to control in the algo. You can either trade within your account capital or take on leverage - there isn't a built-in margin model.

If you don't want to use leverage, then you should use the order_target functions (and it looks like you found them!). One caveat is they don't consider the status of open orders when making their target calculations. To prevent overfills, use the guard below. It skips any securities that have pending open orders:

for stock in data:  
  if get_open_orders(stock):  
     return  
   order_target(stock, 100)  
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.