Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How Order_target_percent(stk, 1) works in real live trading ?

Hi,

Let's say that in the beginning my whole portfolio is AAPL.
When the code does :
Order_target_percent('AAPL',0)
Order_target_percent('MSFT',1)

What actually happens ?
Does the Quantopian system first sell apple, waits till everything is sold, and then buys Microsoft ?
Or it sends orders to sell apple and buy Microsoft without checking success ?

How do I protect myself from situations like failure of selling apple (from some reason), buying Microsoft with money I don't have.

6 responses

In live trading a market order would be placed to sell all your AAPL shares. If you have a cash account, your order to buy MSFT would be rejected. If you have a margin account then your order for MSFT would probably go through and your broker would lend you the funds.

Quantopian doesn't wait for funds to be available or any previous orders to complete. It just happily does what you tell it to. You will need to implement any cash management logic on your own. Maybe look at the documentation for how this can be done for Robinhood trading https://www.quantopian.com/help#sample-robinhood.

Thanks, your answer made it clear that I need to understand how to use quantopian correctly in live trading.

I'll be happy to read more answers regarding this issue, especially from people who are experienced in real live trading with quantopian.
I feel that I lack understanding on how exactly live trading works with quantopian.
Unfortunately I couldn't find a complete documentation on how it should be done, only bits and pieces (like the link you posted)

Cash management is important for sure.

Another tactic that you can use is to store the order_id when you place it, and then keep checking get order() until the order is filled. That, of course, assumes you have immediate access to your cash once you sell. If you have a settlement period, then cash management really is the only way.

To learn how real-money trading, you should do some paper trading. When you do the paper trading, add a lot of logging and record() variables. Track your cash, and your leverage, and your positions. You'll learn a lot about the ins and outs of the algorithm behavior that way. Real money trading isn't exactly, perfectly the same as paper trading, but it's a very good educator.

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.

Can you explain what is "paper trading" ?
I don't really understand what is it. what is the difference between paper trading and backtesting, and what is the difference between paper trading and real money.

  • Backtesting is running a simulation over purely historical data.
  • Paper trading is running an algorithm using live data, but not actually using real money. It's a simulation, like backtesting, but with live data.
  • Real money trading is when you hook up your algorithm to your brokerage account and start making real trades in the market.

Paper trading is offered through a broker. Interactive Brokers is a broker which works with Quantopian algorithms and also offers 'paper trading'. I don't believe Robinhood (another broker which can use Quantopian algorithms) offers 'paper trading'.

Basically, you open an account with Interactive Brokers. You select the account to be for 'paper trading'. You then fund the account with an initial balance of fake money (you don't actually deposit any cash). Then you trade. The broker will execute all your trades just like they would handle them in real money trading. This includes all the nuances like the t+3 rule and calculating margin interest and holding short orders to find shares etc. This way you get to see many of the 'gotchas' in real trading. You also see how the account statements work and the website is setup before doing live trading. It's also executing your algorithm real time and not against historical data as Dan Dunn alluded.

See https://www.interactivebrokers.com/en/software/am/am/manageaccount/papertradingaccount.htm