Back to Community
I am very keen to learn about how to make an algorithm!

Hello everyone!

I am 16 now and exactly a year ago I got introduced to the stock market. I made a couple of good swing trades then it started going south, I learned from my mistakes and just in the last month I made $295 (2500 SEK).

And since I like programming (taught myself html and css during the summer as an introduction to learn other programming languages, also implemented these so I could make a website.) and finance I came up with the great idea to make a algorithm for the market. As for my programming languages I am currently learning python.

I made some research and I ended up here. Thus I would like your advice to make my own fully operational algorithm.

Thanks in advance!

3 responses

@Kevin - HTML and CSS are page description languages - they describe what a page should have and what it should look like. You need a good grasp of an imperative programming language - one that tells the computer what to do. Quantopian uses Python 2.

First, you need to study Python, and bring yourself to a level that allows you to express what you want. Many professional traders who work with other languages, or spreadsheets, but know little or nothing about Python, come to Quantopian, write embarrassingly incorrect code, and take up a lot of their own and others' time asking embarrassing questions. Don't be one of them.

You don't have to master all of Python to write Quantopian algorithms. You have to have good knowledge of a few simple concepts:

  • variable
  • type
  • predefined simple types and operations on them: int, float, str, bool
    • especially integer division: how much is 1/2?
    • optionally, implicit conversion to bool, which simplifies writing conditions
  • functions: when and how they're executed; how to define one
  • object: how to read and set a member variable of an object, call a member function, but not how to define object types (classes)
  • predefined Python container object types: list, dict (it helps if you know arrays from other languages, perhaps JavaScript)
  • statements: assignment, if, for, function call
  • comments: learn to use them early and often, and keep them up to date

If Python is your first imperative programming language, you'd better take a class, or have lessons with a private tutor. If you already know another (eg. JavaScript), or you're really bright and have good math and reasoning skills, you can read good books or watch good videos, and reproduce code examples.

Then you can start learning the Quantopian programming interface. At a minimum, you will need to know:

  • how to make your algorithms watch certain securities (stocks or ETFs): symbols, symbol, or sid
  • how to find out the current price of a security (currently, a stock or ETF trading on major US exchanges) sec you're watching: data[sec].price
  • how to send an order to buy or sell n shares of security sec (positive n to buy, negative to sell or short): order(sec, n)
  • how to find out how much cash you have available:
  • how to find out how many shares of security sec you have or are short: context.portfolio.positions[sec]
  • how to find out if you have any open orders that haven't been filled yet (and better don't trade if you do): get_open_orders()
  • how to find out what commissions per trade and per share you're being charged: 0.0 and 0.03 USD respectively by default (unless Quantopian relents and makes get_commission available)

Read the relevant portions of the Quantopian help page at to learn more about those. Always try to find the answer there before posting a question on the forum.

Sooner or later, it will greatly help you to know and use the pandas library. If you're running Windows, the best way to get Pandas is to download and install Enthought Canopy, which comes with pandas, numpy, statsmodels, and other libraries available from the Quantopian platform.

Hi Kevin,

Welcome to Quantopian! As the other members have noted, you will want to start off by learning Python. In addition to Mohammad's suggestion, here are some other Python tutorial websites:

After you are reasonably comfortable with Python, take a look at these Quantopian API tutorials.

Happy coding!


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.