Learn Python and QuantTrade with Quantopian

Derek Chen
Derek’s Blog
Published in
3 min readNov 16, 2018

Recently I stomp upon Quantopian website while searching information about quantitative analysis of the stock market and trading algorithms. I was suprised by its openness and easiness to let virtually anyone body who have access to the internet to take a peak even take part in today’s well-known hedge fund’s automatic trading system — Quantitative Trading.

Quantopian provides the data, the platform and tool for anybody whom would like to learn quantitative trading. Its platform allow us to choose multiple source of data from free and premium historical finacial data through its pipeline inerface. There are lots of free data to work with, such as “Overnight LIBOR”, “StockTwits Trader Mood”, “CBOE RVX index”, “VIX S&P 500 Volatility”, and the list goes on and on. You can take a look here.

In order to work with all these data, we have to use python. Quantopian only provides python flatform as their only programing language for the moment. Therefore, it is a nice practice to learn python while working with sample tutorial that Quantopian provided.

Tutorials can be found here. There are 6 tutorials and each tutorial breaks down to several smaller lessons, the number of lessons depends on the tutorial. In the tutorials, python chart tools like pandas is used, and trading techniqu like writing our first trading algorithms, construct a pofolio, and use backtesting to verify algorithms.

Here is a lesson from the tutorial:

# Research environment functionsfrom quantopian.research import prices, symbols# Pandas library: https://pandas.pydata.org/import pandas as pd# Query historical pricing data for AAPLaapl_close = prices(assets=symbols('AAPL'),start='2013-01-01',end='2016-01-01',)# Compute 20 and 50 day moving averages on# AAPL's pricing dataaapl_sma20 = aapl_close.rolling(20).mean()aapl_sma50 = aapl_close.rolling(50).mean()# Combine results into a pandas DataFrame and plotpd.DataFrame({'AAPL': aapl_close,'SMA20': aapl_sma20,'SMA50': aapl_sma50}).plot(title='AAPL Close Price / SMA Crossover');

Output(using pandas):

After completing all the tutorials, then there are 56 lectures available for the for more in-depth lessons. Lectures comes with video presentation and exercises.

Example execise from one of the lectures:

# Useful Functionsdef mode(l):# Count the number of times each element appears in the listcounts = {}for e in l:if e in counts:counts[e] += 1else:counts[e] = 1# Return the elements that appear the most timesmaxcount = 0modes = {}for (key, value) in counts.iteritems():if value > maxcount:maxcount = valuemodes = {key}elif value == maxcount:modes.add(key)if maxcount > 1 or len(l) == 1:return list(modes)return 'No mode'

All of the tutorials and lectures mentioned above are provided for free to everyone. Why is Quantopian providing all these resource free of charge? You may ask. There is no free lunch, especially these days. The caveat is that when users are learning python and trading using Quantopian’s platform, they tend to enter a special reward program they call “ contest” after users learn much and become more knowledgable about quantitative trading. In this contest program, Quantopian run the contestants’ algorithm to compete against other people’s algorithm and winner can license their own algorithm to other people to use, such as hedge funds. While the winning contestants can earn license fee from it, Quantopian also receives a commission from it.

This is basically their business model — crowd sourcing algorithm while providing data and platform for ordinal people to learn. It is a win-win situation for students and researchers, but not so much for professional trader who already have access to large amount of data and platform they were trained to used.

Over all, Quantopian is a very good place to learn more about qutitative trading algorithm while learning python. You might even win the contest after you dig deep into it. Who knows, maybe you are the next wall street wiz.

Originally published at medium.com on November 11, 2018.

--

--