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

One of the problems I have with this platform is that things that are too easy to do in other platforms are too complex here. Still I want to try because there are other advantages but I can find my way through the maze of information. Can anyone help to code this double outside day without fancy functions but just straight simple code that I can use to test any symbol I want here?

If low of yesterday > low of today AND high of two days ago > low of yesterday AND high of yesterday > high of two days ago AND high of today > high of yesterday then buy 100 shares at the close

13 responses

I do share Ricardo's opinion on things seeming complex. Lucas, thank you for sharing he videos. I'd like to share my experience too. Like Ricardo's requirement of straight simple code to perform a straight simple task I've been meaning to do the same for the past 2 months now.

I am a C, C++, Java, PHP, C#, MATLAB, programmer and have looked through introductory videos in Python. However, in the past 2-3 months even through I've looked through several of the tutorial videos and racked my brain through the help section and API docs, somehow simple code still is confusing. Basically to answer a simple question I've had to go through videos (40min +) and by the time the next question arises, answering them is a few more (20min+ videos and other help material). So I'm a little discouraged even though the whole idea of quantitative trading of personal funds is the most exciting thing for me to do in my limited free time.

I'm sure there's plenty of material to answer all questions that I may have but it just ends up going from one confusion to the other to the other and eventually not getting anything concrete. I guess what I was looking for was a systematic pathway (somewhat like a step by step list of things to do kind of like Quantopian for dummies) which someone can follow to effectively use the power that Quantopian offers. Is there any systematic plan to master Quantopian which I can simply hop on to based on my individual experience?

Thanks.

I agree, the API is also not intuitive for me.
I think is more directed to statistician then software engineers. People used with Matlap and R
That is due to the framework I guess Pandas numpy.

Thanks Lucas. Does it mean that one needs a statistics background to use Q? Out of curiosity, is there some place I can explore the prerequisites for using Q so I can decide if it is for me or not.

statistics background is indeed needed, check pandas and numpy out. Other day it took me a long time to figure out how to do a simple date operation using Pandas timeframe lol I ask myself, am I that stupid while using these framework all the time. Their docs have very little examples and normally are not much of a help. Combined with a web IDE means you ened a couple of books on your table. If you are used with R or matlab it will be easy for you.

No statistics knowledge is needed for basic programs. Dataframes are a pain in the butt to learn, but once you get the hang of it, it's a heck of a lot more powerful than lists. By statistics, I assume you mean things like mean, standard deviation, t test, ANOVA etc...

@Riccardo, check out the sample algorithm to see a skeleton example of how to buy based on the current and previous prices: https://www.quantopian.com/help#sample-basic

If you want previous prices, you'll need to use the history() function. For example, this will give you the high price 2 days ago:

#retrieve the high ice data for last 2 days plus the high in the last minute  
highs = history(3, '1d', 'high')

# high price 2 days ago.  
prev_two_day_high = highs.iloc[0]  

The second line indexes into the pandas dataframe. It's pretty powerful and if you're not familiar with it, I'd recommend to read more here. Also, there is a sample tutorial that was shared in the forums.

Speaking of tutorials, you can also try the 3-part Quantopian tutorial series, to learn the API to code an algo. Hope that helps and let us know if you have other questions along the way.

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.

Here's an InsideDay algo that you could invert to produce your outside day logic:
https://www.quantopian.com/posts/inside-day

Thanks for the help but this is not for me. I think whoever designed this platform took backtesting 40 years back. Traders care about implementing and testing ideas fast, not sweating over coding issues. Take a look at widely used platforms. I will mention Tradestation, NinjaTrader, MetaTrader, Amibroker as examples. Coding is easy but flexibility is high. AFAIK Panda is a nice animal. It is quite confusing to me to deal with data structures used by data scientists and statisticians. It is evident that developing even the simplest of codes in this platform is exceedingly difficult by the responses I get. If I go to Ninja forum and ask the same question, the complete answer will be available in few hours. Here everyone gives pieces of the answers because even for a simple system there is too much work to do. Thanks anyway.

@Ricardo H., I feel for ya.

It's not that python is such a bad language, I'm hating it less and less as time goes by. It's that the developers who build APIs that extend it have a "make this as terse as possible" mentality. You touched on it as well as did Beginner/Pravin in another post when he mentioned that he thought of his code as an extension of mathematics. I hate mathematics. My kids schooling surpassed my abilities by the time they were in 5th grade. "Dad can you help me with this algebra problem?" "Here, let me have a look... Ah, nope, sorry." "Gee, THANKS dad."

But, I know how to program (fairly well). This helps me muddle through the ugliness of numpy and pandas and others. And I think that if you approach this effort as a mental exercise proposition (as Grant K. is wont to propose), it can become, not pleasurable by any means, but somewhat rewarding when you finally learn some of the wizard speak that gets thrown around here. Learn it and apply it and eventually make it your own.

In the end you'll find that this site offers some of the best free data you can get (for equities). And the fundamentals that are intertwined, well, that is unique in the retail world and come close to what bloomberg can offer. What you're experiencing, I think, is the fact that the thousands of jewels of code pieces (code that would truly help you learn) that exist in the annals of this site are ill-served by this primitive and clumsy forum.

Ricardo, this should do what you want. I'm just building off of what Alisa said. These data structures are very similar to lists. You can also convert many pandas objects to lists with object.tolist(), etc.

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.

My Python skills are better than my trading skills. I would be willing to pair with someone with complementary skills. I am also available for teaching or tutoring as much or as little Python as there's need for.

@ Gus Gordon
Thanx Gus .
You are the only who responded as requested.