Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Best way for beginners to seek help

All,

It feels silly to post basic questions about coding in the IDE on this forum where the discourse seems to be generally at a higher level. Nonetheless, in trying to overcome the learning curve, I know that I would greatly benefit from being able to ask short, simple questions that an experienced developer can answer in short simple snippets. For example, just to get my feet wet, I'm trying to write a simple mean reverting algorithm that will buy at tomorrow's daily open if today's close is below the five day weighted moving average of the daily low and sell at tomorrow's daily open if today's close is above the five day weighted moving average of the daily high.

Also, are the public algorithms only to be found embedded in Community posts? Or is there a collection of stand-alone algorithms that can be perused?

Thank you all for your patience.

4 responses

Welcome Kenneth!

Some of the community posts can be pretty advanced, but don't let that discourage you from posting. As I am sure you've noticed there are a lot of posts seeking help, or asking for help with bugs.

I believe that the best way for beginners to seek help is by learning as much as possible before you start coding. Here are some resources...

https://www.quantopian.com/posts/new-to-this-whole-thing
https://www.quantopian.com/posts/whats-the-best-way-to-get-started
https://www.quantopian.com/posts/why-am-i-getting-error-update-universe-only-allowed-in-before-start-trading-function-seems-nested-to-me
https://www.quantopian.com/posts/simple-tutorial-for-quantopian

While this is kind of a bummer to say its nonetheless true: struggle is good. So after you've taken a look at those posts, struggled a bit and are feeling a little more comfortable with quant finance/programming, then I'd post your issues. If you simply post a request for an algorithm without putting in much work of your own, you'll typically not get a great response. But If you show folks that you've put in the work, but are still having issues or just want tips on how to improve I guarantee you will get more feedback. Another positive route to try is cloning existing algorithms and adding your own ideas to them. Often these highly cloned algos have good discussions going and you may be able to find your answer in the thread. Plus, when you post your version, you will get feedback as well.

For some algorithms you can peruse, check the bottom of the help docs

https://www.quantopian.com/help#sample-algos

Hope that gives you a little bit of insight.

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.

Thank you for your reply, James.

Here is where I got stuck. (I haven't even gotten to the WMA yet!)

I get the following error on the line beginning "elif" : Runtime exception: TypeError: 'float' object has no attribute '__getitem__'

def initialize(context):  
    # top 1% of stocks by $ volume  
    set_universe(universe.DollarVolumeUniverse(floor_percentile=99, ceiling_percentile=100))

def handle_data(context, data):  
    for s in data:  
        # get current position  
        position = context.portfolio.positions[s]

        # get historical prices  
        highs = history(5, '1d', 'high')  
        lows = history(5, '1d', 'low')

        # go long if yesterday's close is below the prior five days' average low (to be changed once debugged to wma)  
        if(position == 0):  
            if data[s].close_price[-2] < lows.mean():  
                order(s, 1)

        # exit position if yesterday's close is above the prior five days' average high (to be changed once debugged to wma)  
        elif data[s].close_price[-2] > highs.mean():  
                order(s, 0)

So data is a very important animal in the Quantopian IDE. What data is is a collection of attributes for the given security in the current bar. These attributes include that bar's opening price, low, volume, sid, etc... The issue you are running into is that you are calling:

data[s].close_price[-2] So this doesn't mean much because .close_price is just a number for the closing price for the security in the current bar. Since you want yesterday's closing price you'll need to make a call to history for the closing price. Something like this should work...

closes = history(5, "1d", "close_price")  
yesterday_close = closes[-2]  

Let me know how that goes.

Kenneth,

Also, are the public algorithms only to be found embedded in Community posts? Or is there a collection of stand-alone algorithms that can be perused?

We've collected links to a number of algorithms from the forum on the quantapolis.com wiki. You can find them on the Algorithms page. Yes, shameless self-promotion but I hope it helps.