Back to Community
Can I learn to code by just using Quantopian?

I've never done any coding in Python or any other language but would like to write my own algos. Should I learn to code through codeacademy or another similar service or is it possible to learn by using the resources on quantopian and by dissecting existing algos listed here on quantopian?

I would obviously prefer the latter but don't know if that's a realistic method if I want to write profitable algos.

I appreciate any feedback!

10 responses

Welcome. I learn best in messing around with code examples. Here's some code that demonstrates a few useful principles, try cloning this and changing things and see how that goes.

Clone Algorithm
196
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Sample algorithm
#
# The context object can be used in the other functions in your algorithm.
def initialize(context):
    symbols('AAPL', 'TSLA')

# The data object contains your security info for any bar with market activity for it.
def handle_data(context, data):
    # Your algorithm logic here.

    # Current cash available in the account
    cash_now = context.portfolio.cash
    
    for sec in data:             # sec stands for security
        if get_open_orders(sec): # Skip bar if there are open orders for this security
            return

        price  = data[sec].price
        costb  = context.portfolio.positions[sec].cost_basis  # cost for previous buys
        shares = context.portfolio.positions[sec].amount      # number of shares owned
        mavg   = data[sec].mavg(30)                           # mavg = moving average

        if price < .99 * mavg:                   # price is lower than usual
            cash_allocated = cash_now / 6        # Using some part of available cash for buy
            to_buy = int(cash_allocated / price) # Number of shares to buy
            if to_buy > 0:
                log.info('Buy {} {}'.format(to_buy, sec.symbol))
                order(sec, to_buy)               # Buy

        elif shares and price > 1.4 * costb:     # price is up, take profit
            log.info('Sell {} {}'.format(shares, sec.symbol))
            order_target(sec, 0)                 # Sell all of the shares

    # The record() function allows you to chart anything you like.
    record(cash = cash_now)
There was a runtime error.

Hey Jesse,

I didn't know any Python before I started using Quantopian. I have pretty good experience with Matlab, however. I just learned Python just to use in Quantopian and now it is my favorite language. Take a look at the following class. I got a pretty good foundation of Python from this class. The materials are really good and it is free !

https://www.edx.org/course/introduction-computer-science-mitx-6-00-1x-0

video course Google gives to their new python developers: https://developers.google.com/edu/python/

Go here to see how you use apply Python for robotics, finance, data analysis ,etc . I'm also a newbie to coding .

http://pythonprogramming.net/dashboard/

and here are some Quantopian tutorials to learn the API. Good luck!

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 for all the feedback! I'll definitely check out all of these resources.

Jesse,

I learned Python exclusively by using Quantopian (with a bit of reading, googling, etc.).

Enjoy!

Grant

These resources are awesome, thanks. I too am a new programmer and have been using Codecademy (although it starts slowing down in content and cleanliness) and Learn Python the Hard Way (Free online).

I personally learned to code almost exclusively through Quantopian.

I'm writing up a step-by-step breakdown of the process so stay tuned for that!

Seong

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.

Hello Jesse,

I suggest getting access to the Q research platform, as well as trying out the browser-based backtester. You just need to submit a dirt-simple algo to the Q Open contest (could even be a buy and hold of SPY...I'll write it for you, if you want, but if you end up winning, you owe me a beer).

Also, I'd suggest giving the backtest debugger a try. It basically drops you into a command prompt, so you can fiddle around.

Grant