[go: up one dir, main page]

0% found this document useful (0 votes)
192 views63 pages

Quantopian Platform

The document provides an overview of the Quantopian platform for algorithmic trading using Python. It discusses exploring the Quantopian website, using the research notebook format and IDE, basic algorithm methods, building trading algorithms, and Quantopian pipelines. An exercise is given to implement a basic Bollinger bands trading strategy on Johnson & Johnson stock using the platform. Pipelines are also introduced for computing values for all assets and filtering them.

Uploaded by

rajasekhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
192 views63 pages

Quantopian Platform

The document provides an overview of the Quantopian platform for algorithmic trading using Python. It discusses exploring the Quantopian website, using the research notebook format and IDE, basic algorithm methods, building trading algorithms, and Quantopian pipelines. An exercise is given to implement a basic Bollinger bands trading strategy on Johnson & Johnson stock using the platform. Pipelines are also introduced for computing values for all assets and filtering them.

Uploaded by

rajasekhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 63

Quantopian Platform

Python for Finance

● Now that we understand the basics of finance and


portfolios, it is time to learn how to use the
Quantopian Platform for Algorithmic Trading!
Python for Finance

● This section will cover the following:


○ Review of Quantopian
○ Basic Algorithm Methods
○ Building Trading Algorithms
○ Trading Algorithm Exercise
○ Quantopian Pipelines
Python for Finance

● Before we begin with the more technical topics,


let’s go ahead and jump to www.quantopian.com
and explore the site a bit!
Quantopian Research Basics
Python for Finance

● To follow along with this lecture, make sure you’ve


created an account on Quantopian!
● We’ll start off by using the Research Notebook
format, then move on to using the Quantopian IDE.
Quantopian Basic
Algorithm Methods
Python for Finance

● Remember that the corresponding code in this


notebook will only work inside the Quantopian
IDE.
● Let’s begin exploring how to create trading
algorithms!
Quantopian Basic
Algorithm Methods
Part Two
First Trading Algorithm
Python for Finance

● Let’s now apply what we’ve learned about


Quantopian Research and the IDE to create our
first Trading Algorithm!
● We will conduct a strategy known as pairs trading.
Python for Finance

● We will implement a simplified approach of this


strategy.
● Keep in mind this approach is not something you
should trade with!
● Instead we’ll be focusing on understanding
Quantopian’s platform.
Python for Finance

● Make sure to do the additional reading in the


resources if you are further interested in Pairs
Trading.
● The first part will focus on conducting research,
the second part will focus on implementing the
strategy!
First Trading Algorithm
Part Two
Trading Algorithm Exercise
Python for Finance

● Welcome to your trading algorithm exercise!


● This will be an exercise in using the Quantopian
Platform, do not take this as a exercise in learning
a real trading strategy!
Python for Finance

● We’re going to have you execute a very basic


Bollinger Bands trading strategy!
● Let’s quickly review what Bollinger Bands are (we
discussed them previously during the Rolling Mean
lectures)
Python for Finance

● We’re going to have you execute a very basic


Bollinger Bands trading strategy!
● Let’s quickly review what Bollinger Bands are (we
discussed them previously during the Rolling Mean
lectures)
Python for Finance

● Bollinger Bands record bounds above and below the


20 day rolling mean
● Bollinger Bands consist of two bands, an upper and
lower bound.
Python for Finance

● The bands are calculated from the 20 day rolling


mean and 20 day rolling Standard Deviation.
● 20 Day Mean +/- (2 * 20 Day Std. Dev.)
● We will use these bands and compare them to the
current price as a signal.
Python for Finance

● Let’s see a visual representation of the bands...


Python for Finance

20 Day Mean + 2 * 20 Day Std. Dev.

Current Price

20 Day Mean - 2 * 20 Day Std. Dev.


Python for Finance

● We will be implementing an “extreme” version of the


Bollinger Band strategy.
● Our basic idea is if the current price is ever above the
upper band, we will short the stock. If it is below the
lower band, we will go long on the stock.
Python for Finance

● Our version of this strategy is extreme in the sense


that we only enter or exit positions based off the
bands.
● You may want to play around with exiting off some
smaller band off the mean.
Python for Finance

● This strategy is pretty reckless and I would never


recommend it to anyone.
● However it is simpler to implement, which is perfect
for us to use for practice on the Quantopian platform!
Python for Finance

● You will implement this strategy on Johnson &


Johnson.
● Let’s quickly review it using the visual
representation!
Python for Finance

Short Stock
20 Day Mean + 2 * 20 Day Std. Dev.

Current Price

20 Day Mean - 2 * 20 Day Std. Dev.


Python for Finance

20 Day Mean + 2 * 20 Day Std. Dev.

Current Price

20 Day Mean - 2 * 20 Day Std. Dev.


Buy/Long Stock
Python for Finance

● You will only check these bands once per day,


meaning you will need to use schedule_function().
● Check out the notebook for a full overview.
Python for Finance

● If this seems a bit overwhelming, code along with


the solutions lecture first, then go back and see if
you can implement it on your own!
● Let’s get started!
Trading Algorithm Exercise
Solutions
Quantopian Pipelines
Python for Finance

● Now that we understand the basics of Quantopian


Research Notebooks and the IDE let’s move on to
discuss Pipelines!
● Pipelines are useful for algorithms that follow a set
structure...
Python for Finance

● Compute some scalar value for all assets.


● Filter assets based off that scalar value.
● Set desired portfolio weights of filtered assets.
● Place orders on assets to reflect desired portfolio
weights.
Python for Finance

● Quantopian Pipelines offer a nice syntax to


perform these operations repeatedly!
● We will break up each major step into a separate
lecture.
● Take your time with this topic, while the concepts
are simple, the syntax can be difficult at first!
Python for Finance

● Remember to reference the notebook in case you


need to copy and paste any code into the Research
Notebook.
● I recommend you upload the provided notebook to
your Quantopian profile to follow along!
Python for Finance

● Let’s get started!


Quantopian Pipelines
Classifiers and Factors
Python for Finance

● Let’s begin using Pipelines by discussing a few key


parts:
○ Classifiers
○ Factors
Python for Finance

● Classifier is a function that transforms the input of


an asset and a timestamp to a categorical output
(such as taking in AAPL and 2017 and reporting
back that it belongs to the Tech Sector).
Python for Finance

● A factor is a function that takes in an asset and a


timestamp and returns a numerical value, such as
the 10-day moving average.
Python for Finance

● In this lecture we will create a Pipeline that returns


back all equities available at some timestamp.
● Then we will use the USEquityPricing dataset to
match up prices to those sids.
Python for Finance

● Then we can create a Factor that will compute


some numerical value given the pricing
information.
● A lot of these functions will be imported from
built-in Quantopian Pipeline libraries!
Python for Finance

● Let’s see how these concepts fit in with the


Pipeline Operator in Quantopian!
● Let’s jump to a new research notebook!
Quantopian Pipelines
Filters and Screens
Python for Finance

● Let’s continue learning about Pipelines by


discussing Filters and Screens.
● Filters take in an asset and a timestamp and return
a Boolean.
● Screens then allow you to execute those filters in
your pipeline.
Quantopian Pipelines
Masking and Classifiers
Python for Finance

● Masking allows us to tell our pipeline to ignore


assets all together, before the factors or filters even
really take place.
● We can pass in the mask parameter to both factors
and filters.
Python for Finance

● Classifiers take in an asset and a timestamp and


return a categorical value, such as a sector or an
exchange.
● Let’s see a few quick examples of both masking
and classifiers!
Course Overview
Python for Finance

● Welcome to the course!


● In this lecture we will quickly cover some FAQs
and what to expect during the course!
● Please don’t skip this lecture! It will help you
understand the course!
Python for Finance

● Let’s discuss a few things that will help give you


the best course experience possible!
● Lectures can be speed up to your liking up to 2x
and they can also be viewed at higher quality, click
on the settings icon.
Python for Finance

● Who is this course for and what does it cover?


○ Some experience with programming.
○ Interested in using Python for Finance and
Algorithmic Trading!
Python for Finance

● If you are interested in just general Data Science


and Machine Learning with Python, check out my
other course:
○ “ Python for Data Science and Machine
Learning Bootcamp ”
Python for Finance

● This course is ideal for students who have some


Python knowledge and are interested in Finance
Topics.
● A few more things before we get started!
Python for Finance

● This course uses Anaconda and the Jupyter


Notebook system.
● If you have your own preferences and are a more
advanced user of Python, please feel free to choose
any environment you prefer!
Python for Finance

● The course notes have been provided as a .zip file


containing all the .ipynb notebooks used during the
course.
● You can easily use the nbconvert library to convert
them to a variety of formats.
Python for Finance

● The slides shown in the course are also linked to as


a resource in their respective lecture.
● They are hosted as Google Slides you can just visit
online to see any updates.
Python for Finance

● How to get help during the course:


○ Double check that your code matches the
notebooks exactly!
○ The code provided in the notebooks is
guaranteed to work if you are using the
provided environment file!
Python for Finance

● Please make sure to run the provided notebooks


first before posting a question, it will save you a lot
of time!
● Still have a question, no problem!
● Post questions to the Q&A forums inside the
course.
Python for Finance

● Please remember to give as much detail as


possible, including what you’ve tried and what
resources or links you’ve already seen.
● Remember to search the Q&A forums for previous
similar questions!
Python for Finance

● After completing the course you will receive the


ability to get a certificate of completion.
● If you have any issues regarding this certificate,
please contact:
○ support@udemy.com
Python for Finance

● If you are experiencing technical platform issues


(slow video playback, weird site bugs, etc…)
please contact:
○ support@udemy.com

You might also like