0%

Discover how to build and backtest algorithmic trading strategies with Zipline

Key Features

  • Get to grips with market data and stock analysis and visualize data to gain quality insights
  • Find out how to systematically approach quantitative research and strategy generation/backtesting in algorithmic trading
  • Learn how to navigate the different features in Python's data analysis libraries

Book Description

Algorithmic trading helps you stay ahead of the markets by devising strategies in quantitative analysis to gain profits and cut losses.

The book starts by introducing you to algorithmic trading and explaining why Python is the best platform for developing trading strategies. You'll then cover quantitative analysis using Python, and learn how to build algorithmic trading strategies with Zipline using various market data sources. Using Zipline as the backtesting library allows access to complimentary US historical daily market data until 2018. As you advance, you will gain an in-depth understanding of Python libraries such as NumPy and pandas for analyzing financial datasets, and explore Matplotlib, statsmodels, and scikit-learn libraries for advanced analytics. You'll also focus on time series forecasting, covering pmdarima and Facebook Prophet.

By the end of this trading book, you will be able to build predictive trading signals, adopt basic and advanced algorithmic trading strategies, and perform portfolio optimization.

What you will learn

  • Discover how quantitative analysis works by covering financial statistics and ARIMA
  • Use core Python libraries to perform quantitative research and strategy development using real datasets
  • Understand how to access financial and economic data in Python
  • Implement effective data visualization with Matplotlib
  • Apply scientific computing and data visualization with popular Python libraries
  • Build and deploy backtesting algorithmic trading strategies

Who this book is for

This book is for data analysts and financial traders who want to explore how to design algorithmic trading strategies using Python's core libraries. If you are looking for a practical guide to backtesting algorithmic trading strategies and building your own strategies, then this book is for you. Beginner-level working knowledge of Python programming and statistics will be helpful.

Table of Contents

  1. Hands-On Financial Trading with Python
  2. Contributors
  3. About the authors
  4. About the reviewer
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Reviews
  6. Section 1: Introduction to Algorithmic Trading
  7. Chapter 1: Introduction to Algorithmic Trading
    1. Walking through the evolution of algorithmic trading
    2. Understanding financial asset classes
    3. Going through the modern electronic trading exchange
    4. Order types
    5. Limit order books
    6. The exchange matching engine
    7. Understanding the components of an algorithmic trading system
    8. The core infrastructure of an algorithmic trading system
    9. The quantitative infrastructure of an algorithmic trading system
    10. Summary
  8. Section 2: In-Depth Look at Python Libraries for the Analysis of Financial Datasets
  9. Chapter 2: Exploratory Data Analysis in Python
    1. Technical requirements
    2. Introduction to EDA
    3. Steps in EDA
    4. Revelation of the identity of A, B, and C and EDA's conclusions
    5. Special Python libraries for EDA
    6. Summary
  10. Chapter 3: High-Speed Scientific Computing Using NumPy
    1. Technical requirements
    2. Introduction to NumPy
    3. Creating NumPy ndarrays
    4. Creating 1D ndarrays
    5. Creating 2D ndarrays
    6. Creating any-dimension ndarrays
    7. Creating an ndarray with np.zeros(...)
    8. Creating an ndarray with np.ones(...)
    9. Creating an ndarray with np.identity(...)
    10. Creating an ndarray with np.arange(...)
    11. Creating an ndarray with np.random.randn(…)
    12. Data types used with NumPy ndarrays
    13. Creating a numpy.float64 array
    14. Creating a numpy.bool array
    15. ndarrays' dtype attribute
    16. Converting underlying data types of ndarray with numpy.ndarrays.astype(...)
    17. Indexing of ndarrays
    18. Direct access to an ndarray's element
    19. ndarray slicing
    20. Boolean indexing
    21. Indexing with arrays
    22. Basic ndarray operations
    23. Scalar multiplication with an ndarray
    24. Linear combinations of ndarrays
    25. Exponentiation of ndarrays
    26. Addition of an ndarray with a scalar
    27. Transposing a matrix
    28. Changing the layout of an ndarray
    29. Finding the minimum value in an ndarray
    30. Calculating the absolute value
    31. Calculating the mean of an ndarray
    32. Finding the index of the maximum value in an ndarray
    33. Calculating the cumulative sum of elements of an ndarray
    34. Finding NaNs in an ndarray
    35. Finding the truth values of x1>x2 of two ndarrays
    36. any and all Boolean operations on ndarrays
    37. Sorting ndarrays
    38. Searching within ndarrays
    39. File operations on ndarrays
    40. File operations with text files
    41. File operations with binary files
    42. Summary
  11. Chapter 4: Data Manipulation and Analysis with pandas
    1. Technical requirements
    2. Introducing pandas Series, pandas DataFrames, and pandas Indexes
    3. pandas.Series
    4. pandas.DataFrame
    5. pandas.Index
    6. Learning essential pandas.DataFrame operations
    7. Indexing, selection, and filtering of DataFrames
    8. Dropping rows and columns from a DataFrame
    9. Sorting values and ranking the values' order within a DataFrame
    10. Arithmetic operations on DataFrames
    11. Merging and combining multiple DataFrames into a single DataFrame
    12. Hierarchical indexing
    13. Grouping operations in DataFrames
    14. Transforming values in DataFrames' axis indices
    15. Handling missing data in DataFrames
    16. The transformation of DataFrames with functions and mappings
    17. Discretization/bucketing of DataFrame values
    18. Permuting and sampling DataFrame values to generate new DataFrames
    19. Exploring file operations with pandas.DataFrames
    20. CSV files
    21. JSON files
    22. Summary
  12. Chapter 5: Data Visualization Using Matplotlib
    1. Technical requirements
    2. Creating figures and subplots
    3. Defining figures' subplots
    4. Plotting in subplots
    5. Enriching plots with colors, markers, and line styles
    6. Enriching axes with ticks, labels, and legends
    7. Enriching data points with annotations
    8. Saving plots to files
    9. Charting a pandas DataFrame with Matplotlib
    10. Creating line plots of a DataFrame column
    11. Creating bar plots of a DataFrame column
    12. Creating histogram and density plots of a DataFrame column
    13. Creating scatter plots of two DataFrame columns
    14. Plotting time series data
    15. Summary
  13. Chapter 6: Statistical Estimation, Inference, and Prediction
    1. Technical requirements
    2. Introduction to statsmodels
    3. Normal distribution test with Q-Q plots
    4. Time series modeling with statsmodels
    5. ETS analysis of a time series
    6. Augmented Dickey-Fuller test for stationarity of a time series
    7. Autocorrelation and partial autocorrelation of a time series
    8. ARIMA time series model
    9. Using a SARIMAX time series model with pmdarima
    10. Time series forecasting with Facebook's Prophet library
    11. Introduction to scikit-learn regression and classification
    12. Generating the dataset
    13. Running RidgeCV regression on the dataset
    14. Running a classification method on the dataset
    15. Summary
  14. Section 3: Algorithmic Trading in Python
  15. Chapter 7: Financial Market Data Access in Python
    1. Technical requirements
    2. Exploring the yahoofinancials Python library
    3. Single-ticker retrieval
    4. Multiple-tickers retrieval
    5. Exploring the pandas_datareader Python library
    6. Access to Yahoo Finance
    7. Access to EconDB
    8. Access to the Federal Reserve Bank of St Louis' FRED
    9. Caching queries
    10. Exploring the Quandl data source
    11. Exploring the IEX Cloud data source
    12. Exploring the MarketStack data source
    13. Summary
  16. Chapter 8: Introduction to Zipline and PyFolio
    1. Technical requirements
    2. Introduction to Zipline and PyFolio
    3. Installing Zipline and PyFolio
    4. Installing Zipline
    5. Installing PyFolio
    6. Importing market data into a Zipline/PyFolio backtesting system
    7. Importing data from the historical Quandl bundle
    8. Importing data from the CSV files bundle
    9. Importing data from custom bundles
    10. Structuring Zipline/PyFolio backtesting modules
    11. Trading happens every day
    12. Trading happens on a custom schedule
    13. Reviewing the key Zipline API reference
    14. Types of orders
    15. Commission models
    16. Slippage models
    17. Running Zipline backtesting from the command line
    18. Introduction to risk management with PyFolio
    19. Market volatility, PnL variance, and PnL standard deviation
    20. Trade-level Sharpe ratio
    21. Maximum drawdown
    22. Summary
  17. Chapter 9: Fundamental Algorithmic Trading Strategies
    1. Technical requirements
    2. What is an algorithmic trading strategy?
    3. Learning momentum-based/trend-following strategies
    4. Rolling window mean strategy
    5. Simple moving averages strategy
    6. Exponentially weighted moving averages strategy
    7. RSI strategy
    8. MACD crossover strategy
    9. RSI and MACD strategies
    10. Triple exponential average strategy
    11. Williams R% strategy
    12. Learning mean-reversion strategies
    13. Bollinger band strategy
    14. Pairs trading strategy
    15. Learning mathematical model-based strategies
    16. Minimization of the portfolio volatility strategy with monthly trading
    17. Maximum Sharpe ratio strategy with monthly trading
    18. Learning time series prediction-based strategies
    19. SARIMAX strategy
    20. Prophet strategy
    21. Summary
  18. Appendix A: How to Setup a Python Environment
    1. Technical requirements
    2. Initial setup
    3. Downloading the complimentary Quandl data bundle
    4. Why subscribe?
  19. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Leave a review - let other readers know what you think
18.117.107.90