O'Reilly logo
live online training icon Live Online training

Hands-On Algorithmic Trading With Python

Design and automate your trading strategies

Deepak Kanungo

The pace of automation in the investment management industry has become frenetic in the last decade because of algorithmic trading and machine learning technologies. Industry experts estimate that as much as 70% of the daily trading volume in US equity markets is executed algorithmically i.e. by computer programs following a set of pre-defined rules. In the 20th century, algorithmic trading was used by sell-side brokers to get the best execution of large trades for their clients. In the 21st century, algorithms are used in the entire trading process, from idea generation to execution and portfolio management. While all algorithmic trading is executed by computers, the rules for generating trades may be designed by humans or discovered by machine learning algorithms from training data.

Discipline in the face of grueling markets is a key success factor in trading and investing. Emotional irrationality, behavioral biases, inability to multitask effectively and slow execution speeds put manual trading by retail investors at a massive disadvantage. Retail investors are aware of these disadvantages and there is considerable interest in algorithmic trading, especially using Python. This course is about taking the first step in leveling the playing field for retail equity investors. It provides the process and technological tools for developing algorithmic trading strategies. Note that live trading is out of scope for the course.

What you'll learn-and how you can apply it

By the end of this live, hands-on, online course, you’ll understand:

  • The advantages and disadvantages of algorithmic trading
  • The different types of models used to generate trading and investment strategies
  • The process and tools used for researching, designing and developing them
  • Pitfalls of backtesting algorithmic strategies
  • Risk-adjusted metrics for evaluating their performance
  • The paramount importance of risk management and position sizing

And you’ll be able to:

  • Use the Pandas library to import, analyze and visualize data from market, fundamental, and alternative sources available for free on the web.
  • Design and automate your own specific investment and trading strategies in Python
  • Backtest and evaluate the performance of your strategies using the Zipline library
  • Prepare for competitions by crowd-sourced hedge funds such as Quantopian to fund your algorithmic trading strategies.

This training course is for you because...

  • You’re a retail equity investor, financial analyst, or trader who wants to develop algorithmic trading strategies and mitigate the disadvantages of emotional, manual trading.

Prerequisites

  • Basic experience trading and investing in equities
  • Basic knowledge of Python and Pandas data frames
  • Create a Google Colab document: https://colab.research.google.com/

Recommended preparation:

Recommended follow-up:

About your instructor

  • Deepak Kanungo is the founder and CEO of Hedged Capital LLC, an AI-powered trading and advisory firm. Previously, Deepak was a financial advisor at Morgan Stanley, a Silicon Valley fintech entrepreneur and a Director in the Global Planning Department at MasterCard International. Deepak was educated at Princeton University (Astrophysics) and The London School of Economics (Finance and Information Systems). Hedged Capital’s trading algorithms use probabilistic models and technologies such as TFP. In 2005, Deepak invented a project portfolio management system using Bayesian Inference, the foundation of all probabilistic programming languages.

Schedule

The timeframes are only estimates and may vary according to how the class is progressing

Overview of investment/trading process and various models (60 minutes)

  • Presentation: Brief review of financial/economic models including the Capital Asset Pricing Model, Arbitrage Pricing Model, and Multi-Factor Models. The presentation will focus on the concepts and not mathematical formulas
  • Discussion: We will discuss financial concepts and issues
  • Presentation: Brief review of technical analysis and common trading strategies, including trending and mean-reverting strategies.
  • Q&A: On the materials presented in this section
  • Break (5 minutes)

Sourcing and analyzing market, fundamental and alternative data to design strategies (60 minutes)

  • Exercise: Setup Colab notebook. Create pandas dataframes to import data from freely available public sources such as FRED (economic), IEX (equity), Alpha Vantage (various), Quandl(various), EDGAR (fundamental), Stocktwits (alternative)
  • Discussion: We will discuss the pros and cons of various data sources. Other issues of data extraction, cleaning, and storage
  • Exercise: Use pandas dataframes and plotting functions to analyze and visualize data. This generally leads to insights and generating trade ideas
  • Q&A: On materials presented in this section
  • Break (5 minutes)

Developing and backtesting algorithmic trading strategies in Zipline (60 minutes)

  • Exercise: Import Zipline library into the notebook. Create a simple moving average crossover strategy discussed earlier
  • Discussion: Analysis of the implemented algorithmic strategy
  • Exercise: Backtest the trading strategy over 36 months
  • Discussion: Analysis of the backtest results
  • Q&A: On materials presented in this section
  • Break (5 minutes)

Evaluating risk-adjusted performance and preparing to compete in funding contests (60 minutes)

  • Presentation: Review the pitfalls of backtesting, especially overfitting and hindsight bias. Overview of risk-adjusted performance metrics including Sharpe/information and Sortino ratios. Introduction to the Kelly Criterion for money management
  • Discussion: About the paramount importance of risk management and position sizing in trading
  • Discussion: Next steps including forward testing/paper trading. Issues and risks with going live with algorithmic trading. Competing for funds in contests hosted by firms such as Quantopian
  • Q&A: On the entire course