Book Image

Python Algorithmic Trading Cookbook

By : Pushpak Dagade
Book Image

Python Algorithmic Trading Cookbook

By: Pushpak Dagade

Overview of this book

If you want to find out how you can build a solid foundation in algorithmic trading using Python, this cookbook is here to help. Starting by setting up the Python environment for trading and connectivity with brokers, you’ll then learn the important aspects of financial markets. As you progress, you’ll learn to fetch financial instruments, query and calculate various types of candles and historical data, and finally, compute and plot technical indicators. Next, you’ll learn how to place various types of orders, such as regular, bracket, and cover orders, and understand their state transitions. Later chapters will cover backtesting, paper trading, and finally real trading for the algorithmic strategies that you've created. You’ll even understand how to automate trading and find the right strategy for making effective decisions that would otherwise be impossible for human traders. By the end of this book, you’ll be able to use Python libraries to conduct key tasks in the algorithmic trading ecosystem. Note: For demonstration, we're using Zerodha, an Indian Stock Market broker. If you're not an Indian resident, you won't be able to use Zerodha and therefore will not be able to test the examples directly. However, you can take inspiration from the book and apply the concepts across your preferred stock market broker of choice.
Table of Contents (16 chapters)

What this book covers

Chapter 1, Handling and Manipulating Date, Time, and Time Series Data, explains everything about the Python DateTime module and pandas DataFrames that are required to handle time series data efficiently.

Chapter 2, Stock Markets – Primer on Trading, covers how to set up Python connectivity with a broker, fetch financial instruments, and get a quick hands-on at placing simple orders. You will also learn how to query margins and calculate brokerage and government taxes.

Chapter 3, Fetching Financial Data, covers financial instruments in-depth.

Chapter 4, Computing Candlesticks and Historical Data, explains how to fetch and understand historical data, and also how to fetch, compute, and plot various candlestick patterns, including Japanese (OHLC), Renko, Line Break, and Heikin-Ashi.

Chapter 5, Computing and Plotting of Technical Indicators, explains how to compute and plot 10 types of technical indicators, including trend indicators, momentum indicators, volatility indicators, and volume indicators.

Chapter 6, Placing Regular Orders on the Exchange, explains how to place 16 types of regular orders across two transaction types, two order codes, and four order varieties. You will learn how to query the order status in real time, while also learning about the possible order states supported by the broker and the order life cycle for regular orders.

Chapter 7, Placing Bracket and Cover Orders on the Exchange, explains how to place eight types of bracket orders and four types of cover orders across two transaction types and multiple order varieties and how to query the order status in real time. You will learn about target, stoploss, and trailing stoploss, along with the possible order states supported by the broker and the order life cycle for both bracket and cover orders.

Chapter 8, Algorithmic Trading Strategies – Code Step by Step, explains how to code your own algorithmic trading strategy from scratch using two strategy coding examples involving regular and bracket orders, respectively.

Chapter 9, Algorithmic Trading – Backtesting, covers how to backtest your own algorithmic trading strategy using two strategy coding examples involving regular and bracket orders, respectively. You will also learn how to fetch execution logs and various types of backtesting reports, including profit and loss reports, statistics reports, and order history logs for your strategy.

Chapter 10, Algorithmic Trading – Paper Trading, explains how to paper trade your own algorithmic trading strategy in live markets using two strategy coding examples involving regular and bracket orders, respectively. You will also learn how to fetch execution logs and various types of paper trading reports, including profit and loss reports, statistics reports, and order history logs, in real time for your strategy.

Chapter 11, Algorithmic Trading – Real Trading, explains how to real trade your own algorithmic trading strategy in live markets and real money using two strategy coding examples involving regular and bracket orders, respectively. You will also learn how to fetch execution logs and various types of real trading reports, including profit and loss reports and statistics reports, in real time for your strategy.