Book Description

Understand the fundamentals of algorithmic trading to apply algorithms to real market data and analyze the results of real-world trading strategies

Key Features

  • Understand the power of algorithmic trading in financial markets with real-world examples
  • Get up and running with the algorithms used to carry out algorithmic trading
  • Learn to build your own algorithmic trading robots which require no human intervention

Book Description

It's now harder than ever to get a significant edge over competitors in terms of speed and efficiency when it comes to algorithmic trading. Relying on sophisticated trading signals, predictive models and strategies can make all the difference. This book will guide you through these aspects, giving you insights into how modern electronic trading markets and participants operate.

You'll start with an introduction to algorithmic trading, along with setting up the environment required to perform the tasks in the book. You'll explore the key components of an algorithmic trading business and aspects you'll need to take into account before starting an automated trading project. Next, you'll focus on designing, building and operating the components required for developing a practical and profitable algorithmic trading business. Later, you'll learn how quantitative trading signals and strategies are developed, and also implement and analyze sophisticated trading strategies such as volatility strategies, economic release strategies, and statistical arbitrage. Finally, you'll create a trading bot from scratch using the algorithms built in the previous sections.

By the end of this book, you'll be well-versed with electronic trading markets and have learned to implement, evaluate and safely operate algorithmic trading strategies in live markets.

What you will learn

  • Understand the components of modern algorithmic trading systems and strategies
  • Apply machine learning in algorithmic trading signals and strategies using Python
  • Build, visualize and analyze trading strategies based on mean reversion, trend, economic releases and more
  • Quantify and build a risk management system for Python trading strategies
  • Build a backtester to run simulated trading strategies for improving the performance of your trading bot
  • Deploy and incorporate trading strategies in the live market to maintain and improve profitability

Who this book is for

This book is for software engineers, financial traders, data analysts, and entrepreneurs. Anyone who wants to get started with algorithmic trading and understand how it works; and learn the components of a trading system, protocols and algorithms required for black box and gray box trading, and techniques for building a completely automated and profitable trading business will also find this book useful.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Learn Algorithmic Trading
  3. About Packt
    1. Why subscribe?
  4. Contributors
    1. About the authors
    2. About the reviewers
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  6. Section 1: Introduction and Environment Setup
  7. Algorithmic Trading Fundamentals
    1. Why are we trading?
    2. Basic concepts regarding the modern trading setup
      1. Market sectors
      2. Asset classes
      3. Basics of what a modern trading exchange looks like
    3. Understanding algorithmic trading concepts
      1. Exchange order book
      2. Exchange matching algorithm
        1. FIFO matching
        2. Pro-rata matching
      3. Limit order book
      4. Exchange market data protocols
      5. Market data feed handlers
      6. Order types
        1. IOC – Immediate Or Cancel
        2. GTD – Good Till Day
        3. Stop orders
      7. Exchange order entry protocols
      8. Order entry gateway
      9. Positions and profit and loss (PnL) management
    4. From intuition to algorithmic trading
      1. Why do we need to automate trading?
      2. Evolution of algorithmic trading – from rule-based to AI
    5. Components of an algorithmic trading system
      1. Market data subscription
      2. Limit order books
      3. Signals
      4. Signal aggregators
      5. Execution logic
      6. Position and PnL management
      7. Risk management
      8. Backtesting
    6. Why Python?
      1. Choice of IDE – Pycharm or Notebook
      2. Our first algorithmic trading (buy when the price is low, and sell when the price is high)
      3. Setting up your workspace
        1. PyCharm 101
        2. Getting the data
        3. Preparing the data – signal
        4. Signal visualization
        5. Backtesting
    7. Summary
  8. Section 2: Trading Signal Generation and Strategies
  9. Deciphering the Markets with Technical Analysis
    1. Designing a trading strategy based on trend- and momentum-based indicators
      1. Support and resistance indicators
    2. Creating trading signals based on fundamental technical analysis
      1. Simple moving average
        1. Implementation of the simple moving average
      2. Exponential moving average
        1. Implementation of the exponential moving average
      3. Absolute price oscillator
        1. Implementation of the absolute price oscillator
      4. Moving average convergence divergence
        1. Implementation of the moving average convergence divergence
      5. Bollinger bands
        1. Implementation of Bollinger bands
      6. Relative strength indicator
        1. Implementation of the relative strength indicator
      7. Standard deviation
        1. Implementing standard derivatives
      8. Momentum
        1. Implementation of momentum
    3. Implementing advanced concepts, such as seasonality, in trading instruments
    4. Summary
  10. Predicting the Markets with Basic Machine Learning
    1. Understanding the terminology and notations
      1. Exploring our financial dataset
    2. Creating predictive models using linear regression methods
      1. Ordinary Least Squares
      2. Regularization and shrinkage – LASSO and Ridge regression
      3. Decision tree regression
    3. Creating predictive models using linear classification methods
      1. K-nearest neighbors
      2. Support vector machine
      3. Logistic regression
    4. Summary
  11. Section 3: Algorithmic Trading Strategies
  12. Classical Trading Strategies Driven by Human Intuition
    1. Creating a trading strategy based on momentum and trend following
      1. Examples of momentum strategies
      2. Python implementation
        1. Dual moving average
        2. Naive trading strategy
        3. Turtle strategy
    2. Creating a trading strategy that works for markets with reversion behavior
      1. Examples of reversion strategies
    3. Creating trading strategies that operate on linearly correlated groups of trading instruments
      1. Summary
  13. Sophisticated Algorithmic Strategies
    1. Creating a trading strategy that adjusts for trading instrument volatility
      1. Adjusting for trading instrument volatility in technical indicators
      2. Adjusting for trading instrument volatility in trading strategies
      3. Volatility adjusted mean reversion trading strategies
        1. Mean reversion strategy using the absolute price oscillator trading signal
        2. Mean reversion strategy that dynamically adjusts for changing volatility
        3. Trend-following strategy using absolute price oscillator trading signal
          1. Trend-following strategy that dynamically adjusts for changing volatility
    2. Creating a trading strategy for economic events
      1. Economic releases
      2. Economic release format
      3. Electronic economic release services
      4. Economic releases in trading
    3. Understanding and implementing basic statistical arbitrage trading strategies
      1. Basics of StatArb
      2. Lead-lag in StatArb
      3. Adjusting portfolio composition and relationships
      4. Infrastructure expenses in StatArb
      5. StatArb trading strategy in Python
        1. StatArb data set
        2. Defining StatArb signal parameters
        3. Defining StatArb trading parameters
        4. Quantifying and computing StatArb trading signals
        5. StatArb execution logic
        6. StatArb signal and strategy performance analysis
    4. Summary
  14. Managing the Risk of Algorithmic Strategies
    1. Differentiating between the types of risk and risk factors
      1. Risk of trading losses
      2. Regulation violation risks
      3. Spoofing
      4. Quote stuffing
      5. Banging the close
      6. Sources of risk
        1. Software implementation risk
        2. DevOps risk
        3. Market risk
      7. Quantifying the risk
        1. The severity of risk violations
    2. Differentiating the measures of risk
      1. Stop-loss
      2. Max drawdown
      3. Position limits
      4. Position holding time
      5. Variance of PnLs
      6. Sharpe ratio
      7. Maximum executions per period
      8. Maximum trade size
      9. Volume limits
    3. Making a risk management algorithm
      1. Realistically adjusting risk
    4. Summary 
  15. Section 4: Building a Trading System
  16. Building a Trading System in Python
    1. Understanding the trading system
      1. Gateways
      2. Order book management
      3. Strategy
      4. Order management system 
      5. Critical components
      6. Non-critical components
        1. Command and control
        2. Services
    2. Building a trading system in Python
      1. LiquidityProvider class
      2. Strategy class
      3. OrderManager class
      4. MarketSimulator class
      5. TestTradingSimulation class
    3. Designing a limit order book
    4. Summary
  17. Connecting to Trading Exchanges
    1. Making a trading system trade with exchanges
    2. Reviewing the Communication API
      1. Network basics
      2. Trading protocols
      3. FIX communication protocols
        1. Price updates
        2. Orders
    3. Receiving price updates
      1. Initiator code example
        1. Price updates
    4. Sending orders and receiving a market response
      1. Acceptor code example
        1. Market Data request handling
        2. Order
      2. Other trading APIs
    5. Summary
  18. Creating a Backtester in Python
    1. Learning how to build a backtester 
      1. In-sample versus out-of-sample data
      2. Paper trading (forward testing)
      3. Naive data storage
      4. HDF5 file
      5. Databases
        1. Relational databases
        2. Non-relational databases
    2. Learning how to choose the correct assumptions
      1. For-loop backtest systems
        1. Advantages
        2. Disadvantages
      2. Event-driven backtest systems
        1. Advantages
        2. Disadvantages
    3. Evaluating what the value of time is
    4. Backtesting the dual-moving average trading strategy
      1. For-loop backtester
      2. Event-based backtester
    5. Summary
  19. Section 5: Challenges in Algorithmic Trading
  20. Adapting to Market Participants and Conditions
    1. Strategy performance in backtester versus live markets
      1. Impact of backtester dislocations
        1. Signal validation
        2. Strategy validation
        3. Risk estimates
        4. Risk management system
        5. Choice of strategies for deployment
        6. Expected performance
      2. Causes of simulation dislocations
        1. Slippage
        2. Fees
        3. Operational issues
        4. Market data issues
        5. Latency variance
        6. Place-in-line estimates
        7. Market impact
      3. Tweaking backtesting and strategies in response to live trading
        1. Historical market data accuracy
        2. Measuring and modeling latencies
        3. Improving backtesting sophistication
        4. Adjusting expected performance for backtester bias
        5. Analytics on live trading strategies
    2. Continued profitability in algorithmic trading
      1. Profit decay in algorithmic trading strategies
        1. Signal decay due to lack of optimization
        2. Signal decay due to absence of leading participants
        3. Signal discovery by other participants
        4. Profit decay due to exit of losing participants
        5. Profit decay due to discovery by other participants
        6. Profit decay due to changes in underlying assumptions/relationships
        7. Seasonal profit decay
      2. Adapting to market conditions and changing participants
        1. Building a trading signals dictionary/database
        2. Optimizing trading signals
        3. Optimizing prediction models
        4. Optimizing trading strategy parameters
        5. Researching new trading signals
        6. Expanding to new trading strategies
        7. Portfolio optimization
          1. Uniform risk allocation
          2. PnL-based risk allocation
          3. PnL-sharpe-based risk allocation
          4. Markowitz allocation
          5. Regime Predictive allocation
        8. Incorporating technological advances
    3. Summary
    4. Final words
  21. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think