Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Initialization with Existing Portfolio of Securities

Can one use order() or otherwise set the per existing portfolio in initialization code?

When I tried, order() came back with runtime error when used in initialize(). What I am trying to do is start not from a blank portfolio with some amount of cash in it but with a portfolio that already has securities. This would be usefule when:

  1. Using quantopian for analysis while manually entering trades in another brokerage account.
  2. Using live trading in quantopian trading one algorithm, then switching to another algorithm.

One could run one algorithm live while thinking we are in a bull market, then switching to another for bear market. A bit like manual gear shift in a car.

3 responses

Well, you can call a function the first time handle_data is run. Then set context.flag=True to avoid running it twice.

You can iterate over a portfolio in context.bullstocks[] instead of over data[]. Just make sure to double check the security is still in data[] before using it.

Dennis's answer is the best available.

I think we'll build a feature permit you to initialize with a position at some point. However, to do it right, we need to know more than the stock and quantity. The cost basis would also be important.

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.

Agreed. Not a very important feature now, yet a nice thing to have thus I brought it up.

It may become important in the scenario #2 mentioned above, in real live trading giving ability to re-start with existing portfolio without liquidating it. I suspect very few people are trading now, but I also hope that will change soon. You guys have a really nice research platform with potential of becoming a robust trading platform for enthusiasts that may as well end up making some nice profits.

I am hesitant to start another thread for this, so I'll ask it here: is there an algorithm available that attempts to detect head and shoulders or any other technical analysis platform? I may attempt to write one unless it is already there.