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

Hey guys,

So I have started to use Quantopian recently (and love it so much!!). Even though I am pretty good with Python (at least that is what i think) I still am having trouble on writing a full algorithm (I am trying to write one using Fundamentals data). I have successfully used pipeline to get the stocks that I want, but am having trouble with implementing the buys and the sells. Specifically, how to tell the program to buy this stock with some logic behind it and how to sell (the same or some other) stock.

I have gone through tons of resources. Checked out other users' algorithms, went through both Quantopian and non Quantopian (https://www.youtube.com/watch?v=RxjIOXstxCk) resources, but am still having trouble. Any suggestions for other resources?

P.S. the link above is this guy 'sentdex'. His tutorials are the best!! It would still be relevant, but Quantopian updated the systems recently.

P.P.S Sorry for the long post and thanks for all the help.

4 responses

Have you gone through the Getting Started tutorial yet? It covers some of the basics with ordering. http://www.quantopian.com/tutorials/getting-started

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 did. With this tutorial I did gain knowledge on how to schedule buys and sells, but only for a manually typed security (e.g sid(24)). What I can't seem to understand is how to schedule buys and sells for a list of securities that changes from day to day. Thanks for the reply.

Rasul, I would recommend taking a look at some of the Pipeline examples on the help page.

As you can see, a list of equities to trade is usually constructed by taking the .index of a subset of the DataFrame returned by pipeline_output. Then the usual procedure is to schedule a daily "rebalancing" function, which iterates over the list of equities in a for loop, allocating some percentage of the portfolio to each one using order_target_percent (help link).

If you've created your account recently, there should already be a "Sample Mean Reversion Algorithm" listed on your algorithms page. That algorithm fully implements buying and selling stocks from the output of a pipeline. Take a look at that one for an example of a rebalancing function.

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.

Thanks Nathan,

That helps a lot.