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

From what I understand the code is run on every bar when you do a backtest, so on daily it would cause the code to be run once a day in the past. How does the paper trading simulator handle the code? Does it run once a minute?

For example if my code consists of buying 100 shares if the 20SMA is > 100SMA, will it buy 100 shares every minute?

And this question leads me to one more. How are time scales established for SMAs? In backtest it uses daily or minute according to how you run the backtest. What about paper/live trading?

Thanks!

3 responses

Hi Luke,

Live trading and paper trading run on minute bars (once per minute). This is why we require you to run a backtest in minute mode before you try to paper trade or live trade. Here are the relevant docs on paper trading/live trading.

Your question about whether your code will buy 100 shares every minute will depend on the surrounding logic in your code. Typically, we suggest using the order_target_percent() function so that you order up to a certain number of shares, instead of continuously ordering stocks. As well, you will want to use get_open_orders() to check that your orders have filled before placing another order (and hence, ordering more than you wanted to with order_target_percent()). You can also use the schedule_function() method to schedule certain functions to only run at certain times/days/weeks/ etc.

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.

It does, thanks Jamie.

Let me ask you a question then regarding how orders are handled via backtest and how it would translate into live trading.

This is my code...

if (current_price < 30)  
        order(context.security, +100, style=LimitOrder(30))  

Lets say the minute bar closes go as follows...

30.01, 29.96, 30.05, 30.10

Would I get filled? Or will the order only be placed on the 29.96 bar, but not executed?

In your example, the order is submitted at 29.96 and filled at 30.05 in backtesting.

In live trading, the order is instantly sent to the broker and they fill it according to the market.

EDIT: I made an error in my original response. The order will be submitted and filled at $29.96 in accordance with the slippage model (in backtesting).

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.